Mercurial > repos > shellac > sam_consensus_v3
comparison env/lib/python3.9/site-packages/setuptools/installer.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 import glob | |
| 2 import os | |
| 3 import subprocess | |
| 4 import sys | |
| 5 import tempfile | |
| 6 from distutils import log | |
| 7 from distutils.errors import DistutilsError | |
| 8 | |
| 9 import pkg_resources | |
| 10 from setuptools.wheel import Wheel | |
| 11 | |
| 12 | |
| 13 def _fixup_find_links(find_links): | |
| 14 """Ensure find-links option end-up being a list of strings.""" | |
| 15 if isinstance(find_links, str): | |
| 16 return find_links.split() | |
| 17 assert isinstance(find_links, (tuple, list)) | |
| 18 return find_links | |
| 19 | |
| 20 | |
| 21 def fetch_build_egg(dist, req): # noqa: C901 # is too complex (16) # FIXME | |
| 22 """Fetch an egg needed for building. | |
| 23 | |
| 24 Use pip/wheel to fetch/build a wheel.""" | |
| 25 # Warn if wheel is not available | |
| 26 try: | |
| 27 pkg_resources.get_distribution('wheel') | |
| 28 except pkg_resources.DistributionNotFound: | |
| 29 dist.announce('WARNING: The wheel package is not available.', log.WARN) | |
| 30 # Ignore environment markers; if supplied, it is required. | |
| 31 req = strip_marker(req) | |
| 32 # Take easy_install options into account, but do not override relevant | |
| 33 # pip environment variables (like PIP_INDEX_URL or PIP_QUIET); they'll | |
| 34 # take precedence. | |
| 35 opts = dist.get_option_dict('easy_install') | |
| 36 if 'allow_hosts' in opts: | |
| 37 raise DistutilsError('the `allow-hosts` option is not supported ' | |
| 38 'when using pip to install requirements.') | |
| 39 quiet = 'PIP_QUIET' not in os.environ and 'PIP_VERBOSE' not in os.environ | |
| 40 if 'PIP_INDEX_URL' in os.environ: | |
| 41 index_url = None | |
| 42 elif 'index_url' in opts: | |
| 43 index_url = opts['index_url'][1] | |
| 44 else: | |
| 45 index_url = None | |
| 46 find_links = ( | |
| 47 _fixup_find_links(opts['find_links'][1])[:] if 'find_links' in opts | |
| 48 else [] | |
| 49 ) | |
| 50 if dist.dependency_links: | |
| 51 find_links.extend(dist.dependency_links) | |
| 52 eggs_dir = os.path.realpath(dist.get_egg_cache_dir()) | |
| 53 environment = pkg_resources.Environment() | |
| 54 for egg_dist in pkg_resources.find_distributions(eggs_dir): | |
| 55 if egg_dist in req and environment.can_add(egg_dist): | |
| 56 return egg_dist | |
| 57 with tempfile.TemporaryDirectory() as tmpdir: | |
| 58 cmd = [ | |
| 59 sys.executable, '-m', 'pip', | |
| 60 '--disable-pip-version-check', | |
| 61 'wheel', '--no-deps', | |
| 62 '-w', tmpdir, | |
| 63 ] | |
| 64 if quiet: | |
| 65 cmd.append('--quiet') | |
| 66 if index_url is not None: | |
| 67 cmd.extend(('--index-url', index_url)) | |
| 68 for link in find_links or []: | |
| 69 cmd.extend(('--find-links', link)) | |
| 70 # If requirement is a PEP 508 direct URL, directly pass | |
| 71 # the URL to pip, as `req @ url` does not work on the | |
| 72 # command line. | |
| 73 cmd.append(req.url or str(req)) | |
| 74 try: | |
| 75 subprocess.check_call(cmd) | |
| 76 except subprocess.CalledProcessError as e: | |
| 77 raise DistutilsError(str(e)) from e | |
| 78 wheel = Wheel(glob.glob(os.path.join(tmpdir, '*.whl'))[0]) | |
| 79 dist_location = os.path.join(eggs_dir, wheel.egg_name()) | |
| 80 wheel.install_as_egg(dist_location) | |
| 81 dist_metadata = pkg_resources.PathMetadata( | |
| 82 dist_location, os.path.join(dist_location, 'EGG-INFO')) | |
| 83 dist = pkg_resources.Distribution.from_filename( | |
| 84 dist_location, metadata=dist_metadata) | |
| 85 return dist | |
| 86 | |
| 87 | |
| 88 def strip_marker(req): | |
| 89 """ | |
| 90 Return a new requirement without the environment marker to avoid | |
| 91 calling pip with something like `babel; extra == "i18n"`, which | |
| 92 would always be ignored. | |
| 93 """ | |
| 94 # create a copy to avoid mutating the input | |
| 95 req = pkg_resources.Requirement.parse(str(req)) | |
| 96 req.marker = None | |
| 97 return req |
