Skip to content

Commit

Permalink
Cache supported tags for wheels (#3805)
Browse files Browse the repository at this point in the history
  • Loading branch information
abravalheri committed Mar 8, 2023
2 parents f51eccd + f18f7ad commit 2f4a3c0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
1 change: 1 addition & 0 deletions changelog.d/3804.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Cache supported tags for wheels.
8 changes: 5 additions & 3 deletions setuptools/tests/test_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,9 +609,11 @@ def test_wheel_no_dist_dir():

def test_wheel_is_compatible(monkeypatch):
def sys_tags():
for t in parse_tag('cp36-cp36m-manylinux1_x86_64'):
yield t
monkeypatch.setattr('setuptools.wheel.sys_tags', sys_tags)
return {
(t.interpreter, t.abi, t.platform)
for t in parse_tag('cp36-cp36m-manylinux1_x86_64')
}
monkeypatch.setattr('setuptools.wheel._get_supported_tags', sys_tags)
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 @@ -2,6 +2,7 @@

import email
import itertools
import functools
import os
import posixpath
import re
Expand All @@ -28,6 +29,14 @@
"__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):
Expand Down Expand Up @@ -82,10 +91,8 @@ 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?'''
return next((True for t in self.tags() if t in _get_supported_tags()), False)

def egg_name(self):
return _egg_basename(
Expand Down

0 comments on commit 2f4a3c0

Please sign in to comment.