Mercurial > repos > guerler > springsuite
comparison planemo/lib/python3.7/site-packages/virtualenv/seed/wheels/acquire.py @ 1:56ad4e20f292 draft
"planemo upload commit 6eee67778febed82ddd413c3ca40b3183a3898f1"
author | guerler |
---|---|
date | Fri, 31 Jul 2020 00:32:28 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
0:d30785e31577 | 1:56ad4e20f292 |
---|---|
1 """Bootstrap""" | |
2 from __future__ import absolute_import, unicode_literals | |
3 | |
4 import logging | |
5 import os | |
6 import sys | |
7 from operator import eq, lt | |
8 | |
9 import six | |
10 | |
11 from virtualenv.util.path import Path | |
12 from virtualenv.util.six import ensure_str | |
13 from virtualenv.util.subprocess import Popen, subprocess | |
14 | |
15 from .bundle import from_bundle | |
16 from .util import Version, Wheel, discover_wheels | |
17 | |
18 | |
19 def get_wheel(distribution, version, for_py_version, search_dirs, download, app_data, do_periodic_update): | |
20 """ | |
21 Get a wheel with the given distribution-version-for_py_version trio, by using the extra search dir + download | |
22 """ | |
23 # not all wheels are compatible with all python versions, so we need to py version qualify it | |
24 # 1. acquire from bundle | |
25 wheel = from_bundle(distribution, version, for_py_version, search_dirs, app_data, do_periodic_update) | |
26 | |
27 # 2. download from the internet | |
28 if version not in Version.non_version and download: | |
29 wheel = download_wheel( | |
30 distribution=distribution, | |
31 version_spec=Version.as_version_spec(version), | |
32 for_py_version=for_py_version, | |
33 search_dirs=search_dirs, | |
34 app_data=app_data, | |
35 to_folder=app_data.house, | |
36 ) | |
37 return wheel | |
38 | |
39 | |
40 def download_wheel(distribution, version_spec, for_py_version, search_dirs, app_data, to_folder): | |
41 to_download = "{}{}".format(distribution, version_spec or "") | |
42 logging.debug("download wheel %s %s to %s", to_download, for_py_version, to_folder) | |
43 cmd = [ | |
44 sys.executable, | |
45 "-m", | |
46 "pip", | |
47 "download", | |
48 "--progress-bar", | |
49 "off", | |
50 "--disable-pip-version-check", | |
51 "--only-binary=:all:", | |
52 "--no-deps", | |
53 "--python-version", | |
54 for_py_version, | |
55 "-d", | |
56 str(to_folder), | |
57 to_download, | |
58 ] | |
59 # pip has no interface in python - must be a new sub-process | |
60 env = pip_wheel_env_run(search_dirs, app_data) | |
61 process = Popen(cmd, env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) | |
62 out, err = process.communicate() | |
63 if process.returncode != 0: | |
64 kwargs = {"output": out} | |
65 if six.PY2: | |
66 kwargs["output"] += err | |
67 else: | |
68 kwargs["stderr"] = err | |
69 raise subprocess.CalledProcessError(process.returncode, cmd, **kwargs) | |
70 result = _find_downloaded_wheel(distribution, version_spec, for_py_version, to_folder, out) | |
71 logging.debug("downloaded wheel %s", result.name) | |
72 return result | |
73 | |
74 | |
75 def _find_downloaded_wheel(distribution, version_spec, for_py_version, to_folder, out): | |
76 for line in out.splitlines(): | |
77 line = line.lstrip() | |
78 for marker in ("Saved ", "File was already downloaded "): | |
79 if line.startswith(marker): | |
80 return Wheel(Path(line[len(marker) :]).absolute()) | |
81 # if for some reason the output does not match fallback to latest version with that spec | |
82 return find_compatible_in_house(distribution, version_spec, for_py_version, to_folder) | |
83 | |
84 | |
85 def find_compatible_in_house(distribution, version_spec, for_py_version, in_folder): | |
86 wheels = discover_wheels(in_folder, distribution, None, for_py_version) | |
87 start, end = 0, len(wheels) | |
88 if version_spec is not None: | |
89 if version_spec.startswith("<"): | |
90 from_pos, op = 1, lt | |
91 elif version_spec.startswith("=="): | |
92 from_pos, op = 2, eq | |
93 else: | |
94 raise ValueError(version_spec) | |
95 version = Wheel.as_version_tuple(version_spec[from_pos:]) | |
96 start = next((at for at, w in enumerate(wheels) if op(w.version_tuple, version)), len(wheels)) | |
97 | |
98 return None if start == end else wheels[start] | |
99 | |
100 | |
101 def pip_wheel_env_run(search_dirs, app_data): | |
102 for_py_version = "{}.{}".format(*sys.version_info[0:2]) | |
103 env = os.environ.copy() | |
104 env.update( | |
105 { | |
106 ensure_str(k): str(v) # python 2 requires these to be string only (non-unicode) | |
107 for k, v in {"PIP_USE_WHEEL": "1", "PIP_USER": "0", "PIP_NO_INPUT": "1"}.items() | |
108 }, | |
109 ) | |
110 wheel = get_wheel( | |
111 distribution="pip", | |
112 version=None, | |
113 for_py_version=for_py_version, | |
114 search_dirs=search_dirs, | |
115 download=False, | |
116 app_data=app_data, | |
117 do_periodic_update=False, | |
118 ) | |
119 if wheel is None: | |
120 raise RuntimeError("could not find the embedded pip") | |
121 env[str("PYTHONPATH")] = str(wheel.path) | |
122 return env |