Skip to content

Commit bb7c156

Browse files
Cache _get_current_python_version with @functools.cache; clear in conftest
Agent-Logs-Url: https://github.com/usethis-python/usethis-python/sessions/fd92765f-45c3-47a9-88fc-14abf9492211 Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com>
1 parent 966b573 commit bb7c156

2 files changed

Lines changed: 5 additions & 0 deletions

File tree

src/usethis/_integrations/environ/python.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
from __future__ import annotations
44

5+
import functools
6+
57
from typing_extensions import assert_never
68

79
from usethis._backend.dispatch import get_backend
@@ -68,6 +70,7 @@ def get_supported_minor_python_versions() -> list[PythonVersion]:
6870
return versions
6971

7072

73+
@functools.cache
7174
def _get_current_python_version() -> PythonVersion:
7275
"""Get the inferred Python version for the current project.
7376

tests/conftest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from usethis._config import usethis_config
1111
from usethis._console import _cached_warn_print, get_icon_mode
1212
from usethis._file.pyproject_toml.io_ import PyprojectTOMLManager
13+
from usethis._integrations.environ.python import _get_current_python_version
1314
from usethis._subprocess import call_subprocess
1415
from usethis._test import change_cwd, is_offline
1516
from usethis._tool.impl.spec.import_linter import _importlinter_warn_no_packages_found
@@ -27,6 +28,7 @@ def clear_functools_caches():
2728
_cached_warn_print.cache_clear()
2829
get_icon_mode.cache_clear()
2930
_importlinter_warn_no_packages_found.cache_clear()
31+
_get_current_python_version.cache_clear()
3032

3133

3234
@pytest.fixture(scope="session")

0 commit comments

Comments
 (0)