summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaurits van Rees <maurits@vanrees.org>2023-01-31 17:03:48 +0100
committerMaurits van Rees <maurits@vanrees.org>2023-03-07 22:43:50 +0100
commit2c234499777a5d3f5a213fbfc42b289c207c411b (patch)
tree75746af0d57474ca11a673b85393b9ff77f8fb65
parentf51eccd769cab0297c64e4d007bef42544326431 (diff)
downloadpython-setuptools-git-2c234499777a5d3f5a213fbfc42b289c207c411b.tar.gz
Cache supported tags for wheels.
This fixes https://github.com/pypa/setuptools/issues/3804
-rw-r--r--changelog.d/3804.change.rst1
-rw-r--r--setuptools/tests/test_wheel.py1
-rw-r--r--setuptools/wheel.py15
3 files changed, 13 insertions, 4 deletions
diff --git a/changelog.d/3804.change.rst b/changelog.d/3804.change.rst
new file mode 100644
index 00000000..86a6597c
--- /dev/null
+++ b/changelog.d/3804.change.rst
@@ -0,0 +1 @@
+Cache supported tags for wheels.
diff --git a/setuptools/tests/test_wheel.py b/setuptools/tests/test_wheel.py
index b2bbdfae..8b2faff6 100644
--- a/setuptools/tests/test_wheel.py
+++ b/setuptools/tests/test_wheel.py
@@ -612,6 +612,7 @@ def test_wheel_is_compatible(monkeypatch):
for t in parse_tag('cp36-cp36m-manylinux1_x86_64'):
yield t
monkeypatch.setattr('setuptools.wheel.sys_tags', sys_tags)
+ monkeypatch.setattr('setuptools.wheel._supported_tags', None)
assert Wheel(
'onnxruntime-0.1.2-cp36-cp36m-manylinux1_x86_64.whl').is_compatible()
diff --git a/setuptools/wheel.py b/setuptools/wheel.py
index e388083b..aab7ed05 100644
--- a/setuptools/wheel.py
+++ b/setuptools/wheel.py
@@ -27,6 +27,8 @@ WHEEL_NAME = re.compile(
NAMESPACE_PACKAGE_INIT = \
"__import__('pkg_resources').declare_namespace(__name__)\n"
+_supported_tags = None
+
def unpack(src_dir, dst_dir):
'''Move everything under `src_dir` to `dst_dir`, and delete the former.'''
@@ -82,10 +84,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?'''
+ global _supported_tags
+ if _supported_tags is None:
+ # We calculate the supported tags only once, otherwise calling
+ # this method on thousands of wheels takes seconds instead of
+ # milliseconds.
+ _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)
def egg_name(self):
return _egg_basename(