Skip to content

Commit

Permalink
Cache supported tags for wheels.
Browse files Browse the repository at this point in the history
This fixes #3804
  • Loading branch information
mauritsvanrees committed Jan 31, 2023
1 parent 2ab03c7 commit c82d58b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions changelog.d/3804.change.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Cache supported tags for wheels.
1 change: 1 addition & 0 deletions setuptools/tests/test_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,7 @@ def sys_tags():
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()

Expand Down
15 changes: 11 additions & 4 deletions setuptools/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
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.'''
Expand Down Expand Up @@ -83,10 +85,15 @@ def tags(self):
)

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 pkg_resources.Distribution(
Expand Down

0 comments on commit c82d58b

Please sign in to comment.