From e6fc6946b825efe15b77bbb0b11880e5cae88168 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bern=C3=A1t=20G=C3=A1bor?= Date: Mon, 2 Nov 2026 16:55:10 -0800 Subject: [PATCH 1/2] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor(cache):=20imp?= =?UTF-8?q?ort=20tempfile=20helper?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/python_discovery/_cache.py | 4 ++-- tests/test_cache.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/python_discovery/_cache.py b/src/python_discovery/_cache.py index b0eeb8c..30b8b2e 100644 --- a/src/python_discovery/_cache.py +++ b/src/python_discovery/_cache.py @@ -6,10 +6,10 @@ import logging import os import stat -import tempfile from contextlib import contextmanager, suppress from hashlib import sha256 from pathlib import Path +from tempfile import NamedTemporaryFile from typing import TYPE_CHECKING, Final, Protocol, runtime_checkable if TYPE_CHECKING: @@ -115,7 +115,7 @@ def write(self, content: dict) -> None: self._folder.mkdir(parents=True, exist_ok=True) temporary: Path | None = None try: - with tempfile.NamedTemporaryFile( + with NamedTemporaryFile( mode="w", encoding="utf-8", dir=self._folder, prefix=f".{self._key}.", delete=False ) as file: temporary = Path(file.name) diff --git a/tests/test_cache.py b/tests/test_cache.py index 933d44f..6aea070 100644 --- a/tests/test_cache.py +++ b/tests/test_cache.py @@ -291,7 +291,7 @@ def test_disk_content_store_write_is_private_with_lax_umask(tmp_path: Path) -> N @pytest.mark.parametrize( "target", [ - pytest.param("python_discovery._cache.tempfile.NamedTemporaryFile", id="create"), + pytest.param("python_discovery._cache.NamedTemporaryFile", id="create"), pytest.param("pathlib.Path.replace", id="replace"), ], ) From 8246362a4903c79fb2656acf7e9ca4a2501c6a77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bern=C3=A1t=20G=C3=A1bor?= Date: Mon, 2 Nov 2026 16:54:53 -0800 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=92=84=20style(shims):=20import=20bas?= =?UTF-8?q?ename?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/python_discovery/_discovery.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/python_discovery/_discovery.py b/src/python_discovery/_discovery.py index 23338cc..21568f6 100644 --- a/src/python_discovery/_discovery.py +++ b/src/python_discovery/_discovery.py @@ -6,6 +6,7 @@ from contextlib import suppress from dataclasses import dataclass from itertools import tee +from os.path import basename from pathlib import Path from typing import TYPE_CHECKING, Final @@ -514,7 +515,7 @@ def _resolve_shim(exe_path: str, env: Mapping[str, str]) -> str | None: def _resolve_shim_to_binary(exe_name: str, versions_dir: str, env: Mapping[str, str]) -> str | None: for version in _active_versions(env): - if version in {"", ".", ".."} or os.path.basename(version) != version: + if version in {"", ".", ".."} or basename(version) != version: _LOGGER.debug("ignoring invalid version name %r", version) continue resolved = os.path.join(versions_dir, version, "bin", exe_name)