1# -*- coding=utf-8 -*-
2
3"""Shims to make the pip interface more consistent accross versions.
4
5There are currently two members:
6
7* VCS_SUPPORT is an instance of VcsSupport.
8* build_wheel abstracts the process to build a wheel out of a bunch parameters.
9* unpack_url wraps the actual function in pip to accept modern parameters.
10"""
11
12from __future__ import absolute_import, unicode_literals
13
14import pip_shims
15
16
17def _build_wheel_pre10(ireq, output_dir, finder, wheel_cache, kwargs):
18    kwargs.update({"wheel_cache": wheel_cache, "session": finder.session})
19    reqset = pip_shims.RequirementSet(**kwargs)
20    builder = pip_shims.WheelBuilder(reqset, finder)
21    return builder._build_one(ireq, output_dir)
22
23
24def _build_wheel_modern(ireq, output_dir, finder, wheel_cache, kwargs):
25    """Build a wheel.
26
27    * ireq: The InstallRequirement object to build
28    * output_dir: The directory to build the wheel in.
29    * finder: pip's internal Finder object to find the source out of ireq.
30    * kwargs: Various keyword arguments from `_prepare_wheel_building_kwargs`.
31    """
32    kwargs.update({"progress_bar": "off", "build_isolation": False})
33    with pip_shims.RequirementTracker() as req_tracker:
34        if req_tracker:
35            kwargs["req_tracker"] = req_tracker
36        preparer = pip_shims.RequirementPreparer(**kwargs)
37        builder = pip_shims.WheelBuilder(finder, preparer, wheel_cache)
38        return builder._build_one(ireq, output_dir)
39
40
41def _unpack_url_pre10(*args, **kwargs):
42    """Shim for unpack_url in various pip versions.
43
44    pip before 10.0 does not accept `progress_bar` here. Simply drop it.
45    """
46    kwargs.pop("progress_bar", None)
47    return pip_shims.unpack_url(*args, **kwargs)
48
49
50PIP_VERSION = pip_shims.utils._parse(pip_shims.pip_version)
51VERSION_10 = pip_shims.utils._parse("10")
52
53
54VCS_SUPPORT = pip_shims.VcsSupport()
55
56build_wheel = _build_wheel_modern
57unpack_url = pip_shims.unpack_url
58
59if PIP_VERSION < VERSION_10:
60    build_wheel = _build_wheel_pre10
61    unpack_url = _unpack_url_pre10
62