Mercurial > repos > guerler > hhblits
comparison lib/python3.8/site-packages/setuptools/installer.py @ 0:9e54283cc701 draft
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
author | guerler |
---|---|
date | Mon, 27 Jul 2020 03:47:31 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:9e54283cc701 |
---|---|
1 import glob | |
2 import os | |
3 import subprocess | |
4 import sys | |
5 from distutils import log | |
6 from distutils.errors import DistutilsError | |
7 | |
8 import pkg_resources | |
9 from setuptools.command.easy_install import easy_install | |
10 from setuptools.extern import six | |
11 from setuptools.wheel import Wheel | |
12 | |
13 from .py31compat import TemporaryDirectory | |
14 | |
15 | |
16 def _fixup_find_links(find_links): | |
17 """Ensure find-links option end-up being a list of strings.""" | |
18 if isinstance(find_links, six.string_types): | |
19 return find_links.split() | |
20 assert isinstance(find_links, (tuple, list)) | |
21 return find_links | |
22 | |
23 | |
24 def _legacy_fetch_build_egg(dist, req): | |
25 """Fetch an egg needed for building. | |
26 | |
27 Legacy path using EasyInstall. | |
28 """ | |
29 tmp_dist = dist.__class__({'script_args': ['easy_install']}) | |
30 opts = tmp_dist.get_option_dict('easy_install') | |
31 opts.clear() | |
32 opts.update( | |
33 (k, v) | |
34 for k, v in dist.get_option_dict('easy_install').items() | |
35 if k in ( | |
36 # don't use any other settings | |
37 'find_links', 'site_dirs', 'index_url', | |
38 'optimize', 'site_dirs', 'allow_hosts', | |
39 )) | |
40 if dist.dependency_links: | |
41 links = dist.dependency_links[:] | |
42 if 'find_links' in opts: | |
43 links = _fixup_find_links(opts['find_links'][1]) + links | |
44 opts['find_links'] = ('setup', links) | |
45 install_dir = dist.get_egg_cache_dir() | |
46 cmd = easy_install( | |
47 tmp_dist, args=["x"], install_dir=install_dir, | |
48 exclude_scripts=True, | |
49 always_copy=False, build_directory=None, editable=False, | |
50 upgrade=False, multi_version=True, no_report=True, user=False | |
51 ) | |
52 cmd.ensure_finalized() | |
53 return cmd.easy_install(req) | |
54 | |
55 | |
56 def fetch_build_egg(dist, req): | |
57 """Fetch an egg needed for building. | |
58 | |
59 Use pip/wheel to fetch/build a wheel.""" | |
60 # Check pip is available. | |
61 try: | |
62 pkg_resources.get_distribution('pip') | |
63 except pkg_resources.DistributionNotFound: | |
64 dist.announce( | |
65 'WARNING: The pip package is not available, falling back ' | |
66 'to EasyInstall for handling setup_requires/test_requires; ' | |
67 'this is deprecated and will be removed in a future version.', | |
68 log.WARN | |
69 ) | |
70 return _legacy_fetch_build_egg(dist, req) | |
71 # Warn if wheel is not. | |
72 try: | |
73 pkg_resources.get_distribution('wheel') | |
74 except pkg_resources.DistributionNotFound: | |
75 dist.announce('WARNING: The wheel package is not available.', log.WARN) | |
76 # Ignore environment markers; if supplied, it is required. | |
77 req = strip_marker(req) | |
78 # Take easy_install options into account, but do not override relevant | |
79 # pip environment variables (like PIP_INDEX_URL or PIP_QUIET); they'll | |
80 # take precedence. | |
81 opts = dist.get_option_dict('easy_install') | |
82 if 'allow_hosts' in opts: | |
83 raise DistutilsError('the `allow-hosts` option is not supported ' | |
84 'when using pip to install requirements.') | |
85 if 'PIP_QUIET' in os.environ or 'PIP_VERBOSE' in os.environ: | |
86 quiet = False | |
87 else: | |
88 quiet = True | |
89 if 'PIP_INDEX_URL' in os.environ: | |
90 index_url = None | |
91 elif 'index_url' in opts: | |
92 index_url = opts['index_url'][1] | |
93 else: | |
94 index_url = None | |
95 if 'find_links' in opts: | |
96 find_links = _fixup_find_links(opts['find_links'][1])[:] | |
97 else: | |
98 find_links = [] | |
99 if dist.dependency_links: | |
100 find_links.extend(dist.dependency_links) | |
101 eggs_dir = os.path.realpath(dist.get_egg_cache_dir()) | |
102 environment = pkg_resources.Environment() | |
103 for egg_dist in pkg_resources.find_distributions(eggs_dir): | |
104 if egg_dist in req and environment.can_add(egg_dist): | |
105 return egg_dist | |
106 with TemporaryDirectory() as tmpdir: | |
107 cmd = [ | |
108 sys.executable, '-m', 'pip', | |
109 '--disable-pip-version-check', | |
110 'wheel', '--no-deps', | |
111 '-w', tmpdir, | |
112 ] | |
113 if quiet: | |
114 cmd.append('--quiet') | |
115 if index_url is not None: | |
116 cmd.extend(('--index-url', index_url)) | |
117 if find_links is not None: | |
118 for link in find_links: | |
119 cmd.extend(('--find-links', link)) | |
120 # If requirement is a PEP 508 direct URL, directly pass | |
121 # the URL to pip, as `req @ url` does not work on the | |
122 # command line. | |
123 if req.url: | |
124 cmd.append(req.url) | |
125 else: | |
126 cmd.append(str(req)) | |
127 try: | |
128 subprocess.check_call(cmd) | |
129 except subprocess.CalledProcessError as e: | |
130 raise DistutilsError(str(e)) | |
131 wheel = Wheel(glob.glob(os.path.join(tmpdir, '*.whl'))[0]) | |
132 dist_location = os.path.join(eggs_dir, wheel.egg_name()) | |
133 wheel.install_as_egg(dist_location) | |
134 dist_metadata = pkg_resources.PathMetadata( | |
135 dist_location, os.path.join(dist_location, 'EGG-INFO')) | |
136 dist = pkg_resources.Distribution.from_filename( | |
137 dist_location, metadata=dist_metadata) | |
138 return dist | |
139 | |
140 | |
141 def strip_marker(req): | |
142 """ | |
143 Return a new requirement without the environment marker to avoid | |
144 calling pip with something like `babel; extra == "i18n"`, which | |
145 would always be ignored. | |
146 """ | |
147 # create a copy to avoid mutating the input | |
148 req = pkg_resources.Requirement.parse(str(req)) | |
149 req.marker = None | |
150 return req |