summaryrefslogtreecommitdiff
path: root/setuptools/wheel.py
diff options
context:
space:
mode:
authorMaurits van Rees <maurits@vanrees.org>2023-03-07 22:36:16 +0100
committerMaurits van Rees <maurits@vanrees.org>2023-03-07 22:43:50 +0100
commit8af6bd4818558e4e4427e730ede8bc7ba17ca000 (patch)
treec7c0a356fea1919b544c22d50accc815be1db857 /setuptools/wheel.py
parent2c234499777a5d3f5a213fbfc42b289c207c411b (diff)
downloadpython-setuptools-git-8af6bd4818558e4e4427e730ede8bc7ba17ca000.tar.gz
Use functools.lru_cache to cache supported tags for wheels.
This is a suggestion by @abravalheri for my PR. https://github.com/pypa/setuptools/pull/3805#issuecomment-1434361907
Diffstat (limited to 'setuptools/wheel.py')
-rw-r--r--setuptools/wheel.py17
1 files changed, 9 insertions, 8 deletions
diff --git a/setuptools/wheel.py b/setuptools/wheel.py
index aab7ed05..ff29e2fb 100644
--- a/setuptools/wheel.py
+++ b/setuptools/wheel.py
@@ -2,6 +2,7 @@
import email
import itertools
+import functools
import os
import posixpath
import re
@@ -27,7 +28,13 @@ WHEEL_NAME = re.compile(
NAMESPACE_PACKAGE_INIT = \
"__import__('pkg_resources').declare_namespace(__name__)\n"
-_supported_tags = None
+
+@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 set((t.interpreter, t.abi, t.platform) for t in sys_tags())
def unpack(src_dir, dst_dir):
@@ -85,13 +92,7 @@ class Wheel:
def is_compatible(self):
'''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())
+ _supported_tags = _get_supported_tags()
return next((True for t in self.tags() if t in _supported_tags), False)
def egg_name(self):