Mercurial > repos > rliterman > csp2
comparison CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/lib/python3.8/site-packages/setuptools/installer.py @ 68:5028fdace37b
planemo upload commit 2e9511a184a1ca667c7be0c6321a36dc4e3d116d
author | jpayne |
---|---|
date | Tue, 18 Mar 2025 16:23:26 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
67:0e9998148a16 | 68:5028fdace37b |
---|---|
1 import glob | |
2 import os | |
3 import subprocess | |
4 import sys | |
5 import tempfile | |
6 from functools import partial | |
7 | |
8 from . import _reqs | |
9 from ._reqs import _StrOrIter | |
10 from .warnings import SetuptoolsDeprecationWarning | |
11 from .wheel import Wheel | |
12 | |
13 from distutils import log | |
14 from distutils.errors import DistutilsError | |
15 | |
16 | |
17 def _fixup_find_links(find_links): | |
18 """Ensure find-links option end-up being a list of strings.""" | |
19 if isinstance(find_links, str): | |
20 return find_links.split() | |
21 assert isinstance(find_links, (tuple, list)) | |
22 return find_links | |
23 | |
24 | |
25 def fetch_build_egg(dist, req): | |
26 """Fetch an egg needed for building. | |
27 | |
28 Use pip/wheel to fetch/build a wheel.""" | |
29 _DeprecatedInstaller.emit() | |
30 _warn_wheel_not_available(dist) | |
31 return _fetch_build_egg_no_warn(dist, req) | |
32 | |
33 | |
34 def _fetch_build_eggs(dist, requires: _StrOrIter): | |
35 import pkg_resources # Delay import to avoid unnecessary side-effects | |
36 | |
37 _DeprecatedInstaller.emit(stacklevel=3) | |
38 _warn_wheel_not_available(dist) | |
39 | |
40 resolved_dists = pkg_resources.working_set.resolve( | |
41 _reqs.parse(requires, pkg_resources.Requirement), # required for compatibility | |
42 installer=partial(_fetch_build_egg_no_warn, dist), # avoid warning twice | |
43 replace_conflicting=True, | |
44 ) | |
45 for dist in resolved_dists: | |
46 pkg_resources.working_set.add(dist, replace=True) | |
47 return resolved_dists | |
48 | |
49 | |
50 def _fetch_build_egg_no_warn(dist, req): # noqa: C901 # is too complex (16) # FIXME | |
51 import pkg_resources # Delay import to avoid unnecessary side-effects | |
52 | |
53 # Ignore environment markers; if supplied, it is required. | |
54 req = strip_marker(req) | |
55 # Take easy_install options into account, but do not override relevant | |
56 # pip environment variables (like PIP_INDEX_URL or PIP_QUIET); they'll | |
57 # take precedence. | |
58 opts = dist.get_option_dict('easy_install') | |
59 if 'allow_hosts' in opts: | |
60 raise DistutilsError( | |
61 'the `allow-hosts` option is not supported ' | |
62 'when using pip to install requirements.' | |
63 ) | |
64 quiet = 'PIP_QUIET' not in os.environ and 'PIP_VERBOSE' not in os.environ | |
65 if 'PIP_INDEX_URL' in os.environ: | |
66 index_url = None | |
67 elif 'index_url' in opts: | |
68 index_url = opts['index_url'][1] | |
69 else: | |
70 index_url = None | |
71 find_links = ( | |
72 _fixup_find_links(opts['find_links'][1])[:] if 'find_links' in opts else [] | |
73 ) | |
74 if dist.dependency_links: | |
75 find_links.extend(dist.dependency_links) | |
76 eggs_dir = os.path.realpath(dist.get_egg_cache_dir()) | |
77 environment = pkg_resources.Environment() | |
78 for egg_dist in pkg_resources.find_distributions(eggs_dir): | |
79 if egg_dist in req and environment.can_add(egg_dist): | |
80 return egg_dist | |
81 with tempfile.TemporaryDirectory() as tmpdir: | |
82 cmd = [ | |
83 sys.executable, | |
84 '-m', | |
85 'pip', | |
86 '--disable-pip-version-check', | |
87 'wheel', | |
88 '--no-deps', | |
89 '-w', | |
90 tmpdir, | |
91 ] | |
92 if quiet: | |
93 cmd.append('--quiet') | |
94 if index_url is not None: | |
95 cmd.extend(('--index-url', index_url)) | |
96 for link in find_links or []: | |
97 cmd.extend(('--find-links', link)) | |
98 # If requirement is a PEP 508 direct URL, directly pass | |
99 # the URL to pip, as `req @ url` does not work on the | |
100 # command line. | |
101 cmd.append(req.url or str(req)) | |
102 try: | |
103 subprocess.check_call(cmd) | |
104 except subprocess.CalledProcessError as e: | |
105 raise DistutilsError(str(e)) from e | |
106 wheel = Wheel(glob.glob(os.path.join(tmpdir, '*.whl'))[0]) | |
107 dist_location = os.path.join(eggs_dir, wheel.egg_name()) | |
108 wheel.install_as_egg(dist_location) | |
109 dist_metadata = pkg_resources.PathMetadata( | |
110 dist_location, os.path.join(dist_location, 'EGG-INFO') | |
111 ) | |
112 return pkg_resources.Distribution.from_filename( | |
113 dist_location, metadata=dist_metadata | |
114 ) | |
115 | |
116 | |
117 def strip_marker(req): | |
118 """ | |
119 Return a new requirement without the environment marker to avoid | |
120 calling pip with something like `babel; extra == "i18n"`, which | |
121 would always be ignored. | |
122 """ | |
123 import pkg_resources # Delay import to avoid unnecessary side-effects | |
124 | |
125 # create a copy to avoid mutating the input | |
126 req = pkg_resources.Requirement.parse(str(req)) | |
127 req.marker = None | |
128 return req | |
129 | |
130 | |
131 def _warn_wheel_not_available(dist): | |
132 import pkg_resources # Delay import to avoid unnecessary side-effects | |
133 | |
134 try: | |
135 pkg_resources.get_distribution('wheel') | |
136 except pkg_resources.DistributionNotFound: | |
137 dist.announce('WARNING: The wheel package is not available.', log.WARN) | |
138 | |
139 | |
140 class _DeprecatedInstaller(SetuptoolsDeprecationWarning): | |
141 _SUMMARY = "setuptools.installer and fetch_build_eggs are deprecated." | |
142 _DETAILS = """ | |
143 Requirements should be satisfied by a PEP 517 installer. | |
144 If you are using pip, you can try `pip install --use-pep517`. | |
145 """ | |
146 # _DUE_DATE not decided yet |