summaryrefslogtreecommitdiff
path: root/pip-wrapper.py
blob: 30a56fd5aa2cb7f136bdfd5c3d1baa0c8f5d6801 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
"""
Wrap the pip command to:

- Avoid the default 'python -m pip' invocation, which causes the current
  working directory to be added to the path, which causes problems.
- Ensure pip meets a requisite version.
"""


import sys
import subprocess


def ensure_pip_version(pip_bin, ver):
    """
    Ensure the pip version meets the specified version.

    Use python -m pip to upgrade/downgrade, because for this operation,
    on Windows, pip.exe must not be locked.
    """
    cmd = [sys.executable, '-m', 'pip', 'install', 'pip ' + ver]
    subprocess.check_call(cmd)


def main():
    pip_bin = sys.argv[1]
    # workaround for #1644
    ensure_pip_version(pip_bin, '<19')
    cmd = sys.argv[1:]
    subprocess.check_call(cmd)


__name__ == '__main__' and main()