summaryrefslogtreecommitdiffstats
path: root/third_party/python/setuptools/setuptools/wheel.py
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/python/setuptools/setuptools/wheel.py')
-rw-r--r--third_party/python/setuptools/setuptools/wheel.py64
1 files changed, 41 insertions, 23 deletions
diff --git a/third_party/python/setuptools/setuptools/wheel.py b/third_party/python/setuptools/setuptools/wheel.py
index 0be811af2c..850e43cd01 100644
--- a/third_party/python/setuptools/setuptools/wheel.py
+++ b/third_party/python/setuptools/setuptools/wheel.py
@@ -1,20 +1,22 @@
"""Wheels support."""
-from distutils.util import get_platform
-from distutils import log
import email
import itertools
+import functools
import os
import posixpath
import re
import zipfile
+import contextlib
+
+from distutils.util import get_platform
-import pkg_resources
import setuptools
-from pkg_resources import parse_version
+from setuptools.extern.packaging.version import Version as parse_version
from setuptools.extern.packaging.tags import sys_tags
from setuptools.extern.packaging.utils import canonicalize_name
-from setuptools.command.egg_info import write_requirements
+from setuptools.command.egg_info import write_requirements, _egg_basename
+from setuptools.archive_util import _unpack_zipfile_obj
WHEEL_NAME = re.compile(
@@ -27,6 +29,14 @@ NAMESPACE_PACKAGE_INIT = \
"__import__('pkg_resources').declare_namespace(__name__)\n"
+@functools.lru_cache(maxsize=None)
+def _get_supported_tags():
+ # We calculate the supported tags only once, otherwise calling
+ # this method on thousands of wheels takes seconds instead of
+ # milliseconds.
+ return {(t.interpreter, t.abi, t.platform) for t in sys_tags()}
+
+
def unpack(src_dir, dst_dir):
'''Move everything under `src_dir` to `dst_dir`, and delete the former.'''
for dirpath, dirnames, filenames in os.walk(src_dir):
@@ -49,6 +59,19 @@ def unpack(src_dir, dst_dir):
os.rmdir(dirpath)
+@contextlib.contextmanager
+def disable_info_traces():
+ """
+ Temporarily disable info traces.
+ """
+ from distutils import log
+ saved = log.set_threshold(log.WARN)
+ try:
+ yield
+ finally:
+ log.set_threshold(saved)
+
+
class Wheel:
def __init__(self, filename):
@@ -68,16 +91,15 @@ class Wheel:
)
def is_compatible(self):
- '''Is the wheel is compatible with the current platform?'''
- supported_tags = set(
- (t.interpreter, t.abi, t.platform) for t in sys_tags())
- return next((True for t in self.tags() if t in supported_tags), False)
+ '''Is the wheel compatible with the current platform?'''
+ return next((True for t in self.tags() if t in _get_supported_tags()), False)
def egg_name(self):
- return pkg_resources.Distribution(
- project_name=self.project_name, version=self.version,
+ return _egg_basename(
+ self.project_name,
+ self.version,
platform=(None if self.platform == 'any' else get_platform()),
- ).egg_name() + '.egg'
+ ) + ".egg"
def get_dist_info(self, zf):
# find the correct name of the .dist-info dir in the wheel file
@@ -106,6 +128,8 @@ class Wheel:
@staticmethod
def _convert_metadata(zf, destination_eggdir, dist_info, egg_info):
+ import pkg_resources
+
def get_metadata(name):
with zf.open(posixpath.join(dist_info, name)) as fp:
value = fp.read().decode('utf-8')
@@ -121,8 +145,7 @@ class Wheel:
raise ValueError(
'unsupported wheel format version: %s' % wheel_version)
# Extract to target directory.
- os.mkdir(destination_eggdir)
- zf.extractall(destination_eggdir)
+ _unpack_zipfile_obj(zf, destination_eggdir)
# Convert metadata.
dist_info = os.path.join(destination_eggdir, dist_info)
dist = pkg_resources.Distribution.from_location(
@@ -136,13 +159,13 @@ class Wheel:
def raw_req(req):
req.marker = None
return str(req)
- install_requires = list(sorted(map(raw_req, dist.requires())))
+ install_requires = list(map(raw_req, dist.requires()))
extras_require = {
- extra: sorted(
+ extra: [
req
for req in map(raw_req, dist.requires((extra,)))
if req not in install_requires
- )
+ ]
for extra in dist.extras
}
os.rename(dist_info, egg_info)
@@ -156,17 +179,12 @@ class Wheel:
extras_require=extras_require,
),
)
- # Temporarily disable info traces.
- log_threshold = log._global_log.threshold
- log.set_threshold(log.WARN)
- try:
+ with disable_info_traces():
write_requirements(
setup_dist.get_command_obj('egg_info'),
None,
os.path.join(egg_info, 'requires.txt'),
)
- finally:
- log.set_threshold(log_threshold)
@staticmethod
def _move_data_entries(destination_eggdir, dist_data):