Skip to content

Commit dba6d29

Browse files
committed
🔧 build(lint): bump simplint to 0.10.3
Keep Windows discovery in its existing package and make virtualenv's query functions available through the public library API. The new entry points load the query cache only when called. Passing parsed versions into comparison helpers removes unreachable coverage guards. Use public stdlib APIs for Tk library lookup and Windows junction tests.
1 parent 9c7685c commit dba6d29

34 files changed

Lines changed: 1890 additions & 1846 deletions

‎.pre-commit-config.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ repos:
3535
priority: 5
3636
args: ["--fix", "--unsafe-fixes", "--exit-non-zero-on-fix"]
3737
- repo: https://github.com/gaborbernat/simplint-pre-commit
38-
rev: "f15525433ac9797aa1580f46fdadfe60dd77923c" # frozen: v0.8.0
38+
rev: "073bd9250c7a4d15b71eef71f2c95e4af5c76283" # frozen: v0.10.3
3939
hooks:
4040
- id: simplint
4141
priority: 6
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
``PythonInfo.from_exe`` accepts PEP 514 ``ExecutableArguments`` on Windows. Registry discovery uses that public method.

‎pyproject.toml‎

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,12 @@ lint.ignore = [
133133
"missing-trailing-comma", # Conflict with formatter
134134
"multi-line-summary-first-line", # `multi-line-summary-first-line` and `multi-line-summary-second-line` are incompatible
135135
"single-line-implicit-string-concatenation", # Conflict with formatter
136-
"undocumented-magic-method", # undocumented-public-api (simplint SMP903) covers the public API instead
137-
"undocumented-public-class", # undocumented-public-api (simplint SMP903) covers the public API instead
138-
"undocumented-public-function", # undocumented-public-api (simplint SMP903) covers the public API instead
139-
"undocumented-public-init", # undocumented-public-api (simplint SMP903) covers the public API instead
140-
"undocumented-public-method", # undocumented-public-api (simplint SMP903) covers the public API instead
141-
"undocumented-public-nested-class", # undocumented-public-api (simplint SMP903) covers the public API instead
136+
"undocumented-magic-method", # undocumented-public-api (simplint) covers the public API instead
137+
"undocumented-public-class", # undocumented-public-api (simplint) covers the public API instead
138+
"undocumented-public-function", # undocumented-public-api (simplint) covers the public API instead
139+
"undocumented-public-init", # undocumented-public-api (simplint) covers the public API instead
140+
"undocumented-public-method", # undocumented-public-api (simplint) covers the public API instead
141+
"undocumented-public-nested-class", # undocumented-public-api (simplint) covers the public API instead
142142
]
143143
lint.per-file-ignores."docs/**/*.py" = [
144144
"implicit-namespace-package", # no __init__.py in docs directory
@@ -153,12 +153,9 @@ lint.per-file-ignores."src/python_discovery/_py_info_collect.py" = [
153153
"ANN", # file must parse on Python 2.7 for the version gate: no annotations
154154
"missing-required-import", # `from __future__ import annotations` is a SyntaxError below 3.7
155155
"module-import-not-at-top-of-file", # the version gate must run before importing sysconfig, absent on 3.0/3.1
156-
"PTH", # must use os.path — file runs as subprocess script with only stdlib
156+
"PTH", # probe exchanges string paths with older interpreters
157157
"UP", # pyupgrade pushes syntax newer than the 2.7 parse floor, e.g. f-strings
158158
]
159-
lint.per-file-ignores."src/python_discovery/_windows/_pep514.py" = [
160-
"PTH", # os.path.exists is monkeypatched in tests; pathlib.Path.exists bypasses the mock
161-
]
162159
lint.per-file-ignores."tasks/**/*.py" = [
163160
"D", # release helper scripts, not API
164161
"implicit-namespace-package", # no __init__.py in tasks directory
@@ -175,12 +172,12 @@ lint.per-file-ignores."tests/**/*.py" = [
175172
"magic-value-comparison", # Magic value used in comparison
176173
"private-member-access", # private member access needed to test internals
177174
"pytest-fixture-autouse", # shared setup fixtures are meant to apply to every test
178-
"subprocess-without-shell-equals-true", # `subprocess` call: check for execution of untrusted input
179-
"suspicious-subprocess-import", # subprocess import
175+
"subprocess-without-shell-equals-true", # tests launch known interpreters and test-created scripts
176+
"suspicious-subprocess-import", # subprocess calls exercise interpreter discovery
180177
"too-many-arguments", # too many arguments (pytest fixtures)
181178
"too-many-positional-arguments", # too many positional arguments (pytest fixtures)
182179
]
183-
lint.per-file-ignores."tests/windows/winreg_mock_values.py" = [
180+
lint.per-file-ignores."tests/python_discovery/_windows/winreg_mock_values.py" = [
184181
"undefined-name", # undefined name (winreg available only on Windows)
185182
]
186183
lint.isort = { known-first-party = [
@@ -199,7 +196,7 @@ count = true
199196
max_supported_python = "3.15"
200197

201198
[tool.ty]
202-
src.exclude = [ "tests/windows/winreg_mock_values.py" ]
199+
src.exclude = [ "tests/python_discovery/_windows/winreg_mock_values.py" ]
203200

204201
[[tool.ty.overrides]]
205202
include = [
@@ -243,8 +240,12 @@ paths.source = [
243240
]
244241
report.fail_under = 100
245242
report.omit = [
246-
"src/python_discovery/_windows/*",
247-
"tests/windows/*",
243+
"src/python_discovery/_windows/_cancel_io.py",
244+
"src/python_discovery/_windows/_pep514.py",
245+
"src/python_discovery/_windows/_propose.py",
246+
"tests/python_discovery/_windows/conftest.py",
247+
"tests/python_discovery/_windows/test_pep514.py",
248+
"tests/python_discovery/_windows/winreg_mock_values.py",
248249
]
249250
report.partial_branches = [
250251
"assert any\\(",

‎src/python_discovery/__init__.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from ._discovery import get_interpreter, iter_interpreters
88
from ._py_info import KNOWN_ARCHITECTURES, MarkerEnvironment, PythonInfo, normalize_isa
99
from ._py_spec import KNOWN_IMPLEMENTATIONS, PythonSpec
10+
from ._query import clear, from_exe
1011
from ._specifier import SimpleSpecifier, SimpleSpecifierSet, SimpleVersion
1112

1213
__all__ = [
@@ -22,6 +23,8 @@
2223
"SimpleSpecifierSet",
2324
"SimpleVersion",
2425
"__version__",
26+
"clear",
27+
"from_exe",
2528
"get_interpreter",
2629
"iter_interpreters",
2730
"normalize_isa",

‎src/python_discovery/_cache.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,10 +231,10 @@ def locked(self) -> Generator[None]:
231231

232232
class NoOpContentStore(ContentStore):
233233
# Content store that does nothing -- implements ContentStore protocol.
234-
def exists(self) -> bool: # ruff:ignore[no-self-use]
234+
def exists(self) -> bool: # ruff:ignore[no-self-use] cache protocol
235235
return False
236236

237-
def read(self) -> dict | None: # ruff:ignore[no-self-use] keeps the cache interface uniform across implementations
237+
def read(self) -> dict | None: # ruff:ignore[no-self-use] cache protocol
238238
return None
239239

240240
def write(self, content: dict) -> None:
@@ -244,13 +244,13 @@ def remove(self) -> None:
244244
pass
245245

246246
@contextmanager
247-
def locked(self) -> Generator[None]: # ruff:ignore[no-self-use] keeps the cache interface uniform across implementations
247+
def locked(self) -> Generator[None]: # ruff:ignore[no-self-use] cache protocol
248248
yield
249249

250250

251251
class NoOpCache(PyInfoCache):
252252
# Cache that does nothing -- implements PyInfoCache protocol.
253-
def py_info(self, path: Path) -> NoOpContentStore: # ruff:ignore[unused-method-argument, no-self-use]
253+
def py_info(self, path: Path) -> NoOpContentStore: # ruff:ignore[unused-method-argument, no-self-use] protocol
254254
return NoOpContentStore()
255255

256256
def py_info_clear(self) -> None:

‎src/python_discovery/_cached_py_info.py‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
from pathlib import Path
1919
from select import select
2020
from shlex import quote
21-
from subprocess import DEVNULL, PIPE, Popen, TimeoutExpired, list2cmdline # ruff:ignore[suspicious-subprocess-import] list2cmdline only formats the command for logging
21+
22+
# ruff:ignore[suspicious-subprocess-import] interpreter interrogation
23+
from subprocess import DEVNULL, PIPE, Popen, TimeoutExpired, list2cmdline
2224
from threading import Event, Thread
2325
from time import monotonic
2426
from typing import TYPE_CHECKING, Final, NamedTuple
@@ -28,7 +30,7 @@
2830
from ._py_info_collect import MIN_INTERROGATE_VERSION, UNSUPPORTED_EXIT_CODE, UNSUPPORTED_MARKER
2931

3032
if sys.platform == "win32": # pragma: win32 cover
31-
from ._windows._cancel_io import stop_query_reader
33+
from ._windows import stop_query_reader
3234

3335
if TYPE_CHECKING:
3436
from collections.abc import Generator, Mapping
@@ -207,7 +209,7 @@ def _run_subprocess(
207209
env["PYTHONUTF8"] = "1"
208210
_LOGGER.debug("get interpreter info via cmd: %s", cmd if isinstance(cmd, str) else LogCmd(cmd))
209211
try:
210-
process = Popen( # ruff:ignore[subprocess-without-shell-equals-true] argv list without a shell, so no shell injection
212+
process = Popen( # ruff:ignore[subprocess-without-shell-equals-true] interrogate discovered interpreter
211213
cmd,
212214
universal_newlines=True,
213215
stdin=DEVNULL,

‎src/python_discovery/_discovery.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def _propose_current_and_windows(
150150
yield current_python, True
151151

152152
if IS_WIN: # pragma: win32 cover
153-
from ._windows._propose import propose_interpreters as win_propose # ruff:ignore[import-outside-top-level] the module is Windows-only and imported only there
153+
from ._windows import propose_interpreters as win_propose # ruff:ignore[import-outside-top-level] Windows-only
154154

155155
for interpreter in win_propose(spec, cache, env):
156156
if _is_new_exe(str(interpreter.executable), tested_exes):
@@ -433,7 +433,7 @@ def _uv_specifier_matches(key: _UvKey, specifier: SimpleSpecifier) -> bool:
433433
precision = numeric_version.count(".") + 1
434434
release = ".".join(str(part) for part in key.version.release[:precision])
435435
if key.version.pre_type is not None and (
436-
precision == 3 or specifier.version.pre_type is not None # ruff:ignore[magic-value-comparison] 3 is the precision of a full version tuple
436+
precision == 3 or specifier.version.pre_type is not None # ruff:ignore[magic-value-comparison] full version
437437
):
438438
release = f"{release}{key.version.pre_type}{key.version.pre_num}"
439439
return specifier.contains(release)
@@ -529,7 +529,7 @@ def iter_interpreters(
529529
yield from _iter_for_spec(spec_str, first_with, cache, env_map, predicate, seen)
530530

531531

532-
def _iter_for_spec( # ruff:ignore[too-many-arguments, too-many-positional-arguments] each argument is a separate spec input
532+
def _iter_for_spec( # ruff:ignore[too-many-arguments, too-many-positional-arguments] distinct spec inputs
533533
spec_str: str | None,
534534
try_first_with: tuple[str, ...],
535535
cache: PyInfoCache | None,

‎src/python_discovery/_py_info.py‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def _get_path_extensions() -> list[str]:
4444
EXTENSIONS: Final[list[str]] = _get_path_extensions()
4545

4646

47-
class PythonInfo: # ruff:ignore[too-many-public-methods] PythonInfo is the public query surface; splitting it breaks callers
47+
class PythonInfo: # ruff:ignore[too-many-public-methods] public query API
4848
"""
4949
Contains information for a Python interpreter.
5050
@@ -200,7 +200,7 @@ def from_exe( # ruff:ignore[too-many-arguments] each argument is a separate pro
200200
)
201201

202202
@classmethod
203-
def _from_exe_with_args( # ruff:ignore[too-many-arguments] each argument is a separate probe input
203+
def _from_exe_with_args( # ruff:ignore[too-many-arguments] distinct probe inputs
204204
cls,
205205
exe: str,
206206
cache: PyInfoCache | None = None,
@@ -211,8 +211,7 @@ def _from_exe_with_args( # ruff:ignore[too-many-arguments] each argument is a s
211211
resolve_to_host: bool = True,
212212
env: Mapping[str, str] | None = None,
213213
) -> PythonInfo | None:
214-
# Interrogate an executable with optional platform-specific leading arguments.
215-
from ._cached_py_info import from_exe # ruff:ignore[import-outside-top-level]
214+
from ._cached_py_info import from_exe # ruff:ignore[import-outside-top-level] deferred import avoids a cycle
216215

217216
env = os.environ if env is None else env
218217
proposed = from_exe(
@@ -472,12 +471,13 @@ def clear_cache(cls, cache: PyInfoCache) -> None:
472471
473472
:param cache: the cache store to clear.
474473
"""
475-
from ._cached_py_info import clear # ruff:ignore[import-outside-top-level] deferred import avoids a cycle with _cached_py_info
474+
from ._cached_py_info import clear # ruff:ignore[import-outside-top-level] import cycle
476475

477476
clear(cache)
478477
cls._cache_exe_discovery.clear()
479478

480-
def satisfies(self, spec: PythonSpec, *, impl_must_match: bool) -> bool: # ruff:ignore[too-many-return-statements] one return per distinct satisfaction outcome
479+
# ruff:ignore[too-many-return-statements] distinct outcomes
480+
def satisfies(self, spec: PythonSpec, *, impl_must_match: bool) -> bool:
481481
"""
482482
Check if a given specification can be satisfied by this python interpreter instance.
483483
@@ -535,7 +535,8 @@ def _satisfies_version_specifier(self, spec: PythonSpec) -> bool:
535535
release = ".".join(str(c) for c in [version_info.major, version_info.minor, version_info.micro][:precision])
536536
if (
537537
version_info.releaselevel != "final"
538-
and (precision == 3 or specifier.version.pre_type is not None) # ruff:ignore[magic-value-comparison] 3 is the precision of a full version tuple
538+
# ruff:ignore[magic-value-comparison] full version has three parts
539+
and (precision == 3 or specifier.version.pre_type is not None)
539540
and (suffix := {"alpha": "a", "beta": "b", "candidate": "rc"}.get(version_info.releaselevel))
540541
):
541542
release = f"{release}{suffix}{version_info.serial}"
@@ -629,7 +630,7 @@ def _possible_base(self) -> Generator[str, None, None]:
629630
for base in possible_base:
630631
lower = base.lower()
631632
yield lower
632-
from ._compat import fs_is_case_sensitive # ruff:ignore[import-outside-top-level] imported only when this path is walked
633+
from ._compat import fs_is_case_sensitive # ruff:ignore[import-outside-top-level] cold path
633634

634635
if fs_is_case_sensitive(): # pragma: no branch, the branch depends on the host filesystem
635636
if base != lower:

‎src/python_discovery/_py_info_collect.py‎

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -246,18 +246,18 @@ def _distutils_install(): # pragma: <3.11 cover # 3.11+ uses the "venv" scheme
246246
warnings.simplefilter("ignore")
247247
try:
248248
# ruff:ignore[import-outside-top-level] distutils is optional and removed in newer Pythons
249-
from distutils import dist # ty: ignore[unresolved-import] distutils is removed from the stdlib in Python 3.12
249+
from distutils import dist # ty: ignore[unresolved-import] removed in 3.12
250250

251251
# ruff:ignore[import-outside-top-level] distutils is optional and removed in newer Pythons
252-
from distutils.command.install import SCHEME_KEYS # ty: ignore[unresolved-import] distutils is removed from the stdlib in Python 3.12
252+
from distutils.command.install import SCHEME_KEYS # ty: ignore[unresolved-import] removed in 3.12
253253
except ImportError: # pragma: no cover # if removed or not installed ignore
254254
return {}
255255

256256
distribution = dist.Distribution({
257257
"script_args": "--no-user-cfg",
258258
}) # conf files not parsed so they do not hijack paths
259259
if hasattr(sys, "_framework"): # pragma: no cover # macOS framework builds only
260-
sys._framework = None # ty: ignore[invalid-assignment] # ruff:ignore[private-member-access] # disable macOS static paths for framework
260+
sys._framework = None # ty: ignore[invalid-assignment] # ruff:ignore[private-member-access] macOS paths
261261

262262
with warnings.catch_warnings(): # disable warning for PEP-632
263263
warnings.simplefilter("ignore")
@@ -311,30 +311,27 @@ def _get_tcl_tk_libs(): # pragma: no cover # tkinter availability varies; teste
311311
else:
312312
# Tk.__init__ reads profile scripts from HOME or the working directory; probing needs only library metadata.
313313
class _TclWithoutProfile(tk.Tk):
314-
def readprofile(self, *_args, **_kwargs): # ruff:ignore[no-self-use] # Tk override must be an instance method.
314+
def readprofile(self, *_args, **_kwargs): # ruff:ignore[no-self-use] Tk override
315315
return None
316316

317317
try:
318318
tcl = _TclWithoutProfile(useTk=False)
319319
tcl_lib = tcl.eval("info library")
320-
tk_lib = PythonInfoCollector._resolve_tk_lib(tcl, tcl_lib)
320+
tk_lib = PythonInfoCollector._resolve_tk_lib(tcl, tcl_lib, tk.TkVersion)
321321
except tk.TclError:
322322
pass
323323

324324
return tcl_lib, tk_lib
325325

326326
@staticmethod
327-
def _resolve_tk_lib(tcl, tcl_lib): # pragma: no cover, Tcl probing needs a Tk install the test runners lack
327+
def _resolve_tk_lib(tcl, tcl_lib, tk_version): # pragma: no cover # Tk is absent on test runners
328328
# Resolve the TK library path by direct query or path construction.
329329
tk_lib = PythonInfoCollector._query_tk_library(tcl)
330330
if tk_lib is not None:
331331
return tk_lib
332-
import _tkinter # ruff:ignore[import-outside-top-level,import-private-name] # novermin # linked Tk version
333-
334-
# Loading Tk can block on DISPLAY; the linked version is enough to locate its library.
335-
tk_version = _tkinter.TK_VERSION
336332
tcl_parent = os.path.dirname(tcl_lib)
337-
for version in (tk_version, tk_version.split(".")[0]):
333+
version_text = str(tk_version)
334+
for version in (version_text, version_text.split(".", maxsplit=1)[0]):
338335
tk_lib_path = os.path.join(tcl_parent, "tk{}".format(version))
339336
if os.path.isdir(tk_lib_path) and os.path.exists(os.path.join(tk_lib_path, "tk.tcl")):
340337
return tk_lib_path

‎src/python_discovery/_py_spec.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ class PythonSpec:
152152
constraints, or ``None``.
153153
"""
154154

155-
def __init__( # ruff:ignore[too-many-arguments, too-many-positional-arguments] making the arguments keyword-only breaks positional callers
155+
def __init__( # ruff:ignore[too-many-arguments, too-many-positional-arguments] positional callers
156156
self,
157157
str_spec: str,
158158
implementation: str | None,
@@ -243,7 +243,7 @@ def generate_re(self, *, windows: bool, all_implementations: bool = False) -> re
243243
flags=re.IGNORECASE,
244244
)
245245

246-
def satisfies(self, spec: PythonSpec) -> bool: # ruff:ignore[too-many-return-statements] one return per distinct satisfaction outcome
246+
def satisfies(self, spec: PythonSpec) -> bool: # ruff:ignore[too-many-return-statements] distinct outcomes
247247
"""
248248
Check if this spec is compatible with the given *spec* (e.g. PEP-514 on Windows).
249249

0 commit comments

Comments
 (0)