Skip to content

Commit 2c23449

Browse files
Cache supported tags for wheels.
This fixes #3804
1 parent f51eccd commit 2c23449

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

changelog.d/3804.change.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Cache supported tags for wheels.

setuptools/tests/test_wheel.py

+1
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,7 @@ def sys_tags():
612612
for t in parse_tag('cp36-cp36m-manylinux1_x86_64'):
613613
yield t
614614
monkeypatch.setattr('setuptools.wheel.sys_tags', sys_tags)
615+
monkeypatch.setattr('setuptools.wheel._supported_tags', None)
615616
assert Wheel(
616617
'onnxruntime-0.1.2-cp36-cp36m-manylinux1_x86_64.whl').is_compatible()
617618

setuptools/wheel.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
NAMESPACE_PACKAGE_INIT = \
2828
"__import__('pkg_resources').declare_namespace(__name__)\n"
2929

30+
_supported_tags = None
31+
3032

3133
def unpack(src_dir, dst_dir):
3234
'''Move everything under `src_dir` to `dst_dir`, and delete the former.'''
@@ -82,10 +84,15 @@ def tags(self):
8284
)
8385

8486
def is_compatible(self):
85-
'''Is the wheel is compatible with the current platform?'''
86-
supported_tags = set(
87-
(t.interpreter, t.abi, t.platform) for t in sys_tags())
88-
return next((True for t in self.tags() if t in supported_tags), False)
87+
'''Is the wheel compatible with the current platform?'''
88+
global _supported_tags
89+
if _supported_tags is None:
90+
# We calculate the supported tags only once, otherwise calling
91+
# this method on thousands of wheels takes seconds instead of
92+
# milliseconds.
93+
_supported_tags = set(
94+
(t.interpreter, t.abi, t.platform) for t in sys_tags())
95+
return next((True for t in self.tags() if t in _supported_tags), False)
8996

9097
def egg_name(self):
9198
return _egg_basename(

0 commit comments

Comments
 (0)