diff options
author | Maurits van Rees <maurits@vanrees.org> | 2023-01-31 17:03:48 +0100 |
---|---|---|
committer | Maurits van Rees <maurits@vanrees.org> | 2023-03-07 22:43:50 +0100 |
commit | 2c234499777a5d3f5a213fbfc42b289c207c411b (patch) | |
tree | 75746af0d57474ca11a673b85393b9ff77f8fb65 /setuptools/wheel.py | |
parent | f51eccd769cab0297c64e4d007bef42544326431 (diff) | |
download | python-setuptools-git-2c234499777a5d3f5a213fbfc42b289c207c411b.tar.gz |
Cache supported tags for wheels.
This fixes https://github.com/pypa/setuptools/issues/3804
Diffstat (limited to 'setuptools/wheel.py')
-rw-r--r-- | setuptools/wheel.py | 15 |
1 files changed, 11 insertions, 4 deletions
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( |