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