Skip to content

Commit a825b7b

Browse files
committed
refactor: cache system architecture retrieval for efficiency
Signed-off-by: Frost Ming <me@frostming.com>
1 parent 77b19b1 commit a825b7b

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/findpython/providers/winreg.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import platform
4+
from functools import lru_cache
45
from pathlib import Path
56
from typing import TYPE_CHECKING
67

@@ -19,7 +20,11 @@
1920
else:
2021
from typing_extensions import Self
2122

22-
SYS_ARCHITECTURE = platform.architecture()[0]
23+
24+
@lru_cache
25+
def sys_architecture() -> str:
26+
"""Return the system architecture."""
27+
return platform.architecture()[0]
2328

2429

2530
class WinregProvider(BaseProvider):
@@ -35,6 +40,7 @@ def find_pythons(self) -> Iterable[PythonVersion]:
3540
from findpython.pep514tools import findall as pep514_findall
3641

3742
env_versions = pep514_findall()
43+
sys_arch = sys_architecture()
3844
for version in env_versions:
3945
install_path = getattr(version.info, "install_path", None)
4046
if install_path is None:
@@ -54,7 +60,7 @@ def find_pythons(self) -> Iterable[PythonVersion]:
5460
py_ver = self.version_maker(
5561
path,
5662
parse_version,
57-
getattr(version.info, "sys_architecture", SYS_ARCHITECTURE),
63+
getattr(version.info, "sys_architecture", sys_arch),
5864
path,
5965
)
6066
yield py_ver

0 commit comments

Comments
 (0)