Skip to content

Commit 2f4a3c0

Browse files
committed
Cache supported tags for wheels (#3805)
2 parents f51eccd + f18f7ad commit 2f4a3c0

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

changelog.d/3804.misc.rst

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

setuptools/tests/test_wheel.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -609,9 +609,11 @@ def test_wheel_no_dist_dir():
609609

610610
def test_wheel_is_compatible(monkeypatch):
611611
def sys_tags():
612-
for t in parse_tag('cp36-cp36m-manylinux1_x86_64'):
613-
yield t
614-
monkeypatch.setattr('setuptools.wheel.sys_tags', sys_tags)
612+
return {
613+
(t.interpreter, t.abi, t.platform)
614+
for t in parse_tag('cp36-cp36m-manylinux1_x86_64')
615+
}
616+
monkeypatch.setattr('setuptools.wheel._get_supported_tags', sys_tags)
615617
assert Wheel(
616618
'onnxruntime-0.1.2-cp36-cp36m-manylinux1_x86_64.whl').is_compatible()
617619

setuptools/wheel.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import email
44
import itertools
5+
import functools
56
import os
67
import posixpath
78
import re
@@ -28,6 +29,14 @@
2829
"__import__('pkg_resources').declare_namespace(__name__)\n"
2930

3031

32+
@functools.lru_cache(maxsize=None)
33+
def _get_supported_tags():
34+
# We calculate the supported tags only once, otherwise calling
35+
# this method on thousands of wheels takes seconds instead of
36+
# milliseconds.
37+
return {(t.interpreter, t.abi, t.platform) for t in sys_tags()}
38+
39+
3140
def unpack(src_dir, dst_dir):
3241
'''Move everything under `src_dir` to `dst_dir`, and delete the former.'''
3342
for dirpath, dirnames, filenames in os.walk(src_dir):
@@ -82,10 +91,8 @@ def tags(self):
8291
)
8392

8493
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)
94+
'''Is the wheel compatible with the current platform?'''
95+
return next((True for t in self.tags() if t in _get_supported_tags()), False)
8996

9097
def egg_name(self):
9198
return _egg_basename(

0 commit comments

Comments
 (0)