python-discovery 1.6.6__py3-none-any.whl → 1.7.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- python_discovery/_discovery.py +17 -7
- python_discovery/_py_info.py +5 -1
- python_discovery/_py_spec.py +52 -39
- {python_discovery-1.6.6.dist-info → python_discovery-1.7.0.dist-info}/METADATA +1 -1
- {python_discovery-1.6.6.dist-info → python_discovery-1.7.0.dist-info}/RECORD +7 -7
- {python_discovery-1.6.6.dist-info → python_discovery-1.7.0.dist-info}/WHEEL +0 -0
- {python_discovery-1.6.6.dist-info → python_discovery-1.7.0.dist-info}/licenses/LICENSE +0 -0
python_discovery/_discovery.py
CHANGED
|
@@ -389,8 +389,9 @@ def _uv_sort_key(install: _UvInstall) -> tuple[int, ...]:
|
|
|
389
389
|
version = key.version
|
|
390
390
|
return (
|
|
391
391
|
impl_order.index(key.implementation) if key.implementation in impl_order else len(impl_order),
|
|
392
|
-
# uv's minor version links point at a concrete install that moves on upgrade, so report the target instead
|
|
393
|
-
|
|
392
|
+
# uv's minor version links point at a concrete install that moves on upgrade, so report the target instead;
|
|
393
|
+
# spot them by the name they resolve to, as on Windows they are junctions, which is_symlink() does not report
|
|
394
|
+
int(install.path.resolve().name != install.path.name),
|
|
394
395
|
-version.major,
|
|
395
396
|
-version.minor,
|
|
396
397
|
-version.micro,
|
|
@@ -531,11 +532,10 @@ def _read_python_version_file(start: str | Path, *, search_parents: bool = True)
|
|
|
531
532
|
"""Read a ``.python-version`` file, optionally searching parent directories."""
|
|
532
533
|
current = start
|
|
533
534
|
while True:
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
return versions
|
|
535
|
+
# unlike pathlib before 3.14, os.path answers False when a directory on the way can't be searched
|
|
536
|
+
candidate = os.path.join(current, ".python-version") if os.path.isdir(current) else current
|
|
537
|
+
if os.path.isfile(candidate) and (versions := _versions_in_file(candidate)):
|
|
538
|
+
return versions
|
|
539
539
|
if not search_parents:
|
|
540
540
|
return None
|
|
541
541
|
parent = Path(current).parent
|
|
@@ -544,6 +544,16 @@ def _read_python_version_file(start: str | Path, *, search_parents: bool = True)
|
|
|
544
544
|
current = parent
|
|
545
545
|
|
|
546
546
|
|
|
547
|
+
def _versions_in_file(path: str | Path) -> list[str]:
|
|
548
|
+
try:
|
|
549
|
+
# pyenv reads raw bytes, so a byte that is not UTF-8 (a Latin-1 comment, say) must not hide the versions
|
|
550
|
+
with Path(path).open(encoding="utf-8", errors="replace") as fh:
|
|
551
|
+
return [v for line in fh if (v := line.strip()) and not v.startswith("#")]
|
|
552
|
+
except OSError: # skip a file we cannot read, the same as one that names no version
|
|
553
|
+
_LOGGER.debug("failed to read %s", path, exc_info=True)
|
|
554
|
+
return []
|
|
555
|
+
|
|
556
|
+
|
|
547
557
|
class PathPythonInfo(PythonInfo):
|
|
548
558
|
"""python info from path."""
|
|
549
559
|
|
python_discovery/_py_info.py
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
+
import copy
|
|
5
6
|
import json
|
|
6
7
|
import logging
|
|
7
8
|
import os
|
|
@@ -475,7 +476,10 @@ class PythonInfo: # ruff:ignore[too-many-public-methods]
|
|
|
475
476
|
resolved = cls.from_exe(target.system_executable, cache)
|
|
476
477
|
if resolved is not None:
|
|
477
478
|
target = resolved
|
|
478
|
-
target.executable
|
|
479
|
+
if target.executable != start_executable:
|
|
480
|
+
# the cache hands every lookup of this base the same object, so point a copy at the start executable
|
|
481
|
+
target = copy.copy(target)
|
|
482
|
+
target.executable = start_executable
|
|
479
483
|
return target
|
|
480
484
|
|
|
481
485
|
_cache_exe_discovery: ClassVar[dict[tuple[str, bool], PythonInfo]] = {}
|
python_discovery/_py_spec.py
CHANGED
|
@@ -10,26 +10,29 @@ from typing import Final
|
|
|
10
10
|
from ._py_info import normalize_isa
|
|
11
11
|
from ._specifier import SimpleSpecifier, SimpleSpecifierSet, SimpleVersion
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
r"""
|
|
15
|
-
^
|
|
16
|
-
(?P<impl>[a-zA-Z]+)? # implementation (e.g. cpython, pypy)
|
|
17
|
-
(?P<version>[0-9.]+)? # version (e.g. 3.12, 3.12.1)
|
|
13
|
+
_MODIFIERS: Final[str] = r"""
|
|
18
14
|
(?P<threaded>t)? # free-threaded flag
|
|
19
15
|
(?P<debug>d|(?:-dbg|-debug)(?=-|$))? # debug build flag (d, -dbg or -debug)
|
|
20
16
|
(?:-(?P<arch>32|64))? # architecture bitness
|
|
21
17
|
(?:-(?P<machine>[a-zA-Z0-9_.]+))? # ISA (e.g. arm64, x86_64, i86pc.64bit)
|
|
22
18
|
$
|
|
23
|
-
|
|
19
|
+
"""
|
|
20
|
+
PATTERN = re.compile(
|
|
21
|
+
r"""
|
|
22
|
+
^
|
|
23
|
+
(?P<impl>[a-zA-Z]+)? # implementation (e.g. cpython, pypy)
|
|
24
|
+
(?P<version>[0-9.]+)? # version (e.g. 3.12, 3.12.1)
|
|
25
|
+
"""
|
|
26
|
+
+ _MODIFIERS,
|
|
24
27
|
re.VERBOSE,
|
|
25
28
|
)
|
|
26
29
|
SPECIFIER_PATTERN = re.compile(
|
|
27
30
|
r"""
|
|
28
31
|
^
|
|
29
32
|
(?:(?P<impl>[A-Za-z]+)\s*)? # optional implementation prefix
|
|
30
|
-
(?P<spec>(?:===|==|~=|!=|<=|>=|<|>)
|
|
31
|
-
|
|
32
|
-
|
|
33
|
+
(?P<spec>(?:===|==|~=|!=|<=|>=|<|>).*?) # PEP 440 version specifier, lazy so the modifiers can follow it
|
|
34
|
+
"""
|
|
35
|
+
+ _MODIFIERS,
|
|
33
36
|
re.VERBOSE,
|
|
34
37
|
)
|
|
35
38
|
|
|
@@ -69,51 +72,60 @@ def _parse_version_parts(version: str) -> tuple[int | None, int | None, int | No
|
|
|
69
72
|
def _parse_spec_pattern(string_spec: str) -> PythonSpec | None:
|
|
70
73
|
if not (match := re.match(PATTERN, string_spec)):
|
|
71
74
|
return None
|
|
72
|
-
|
|
73
|
-
version
|
|
74
|
-
major, minor, micro, threaded = None, None, None, None
|
|
75
|
-
debug = True if groups["debug"] else None # unconstrained unless an explicit d/-dbg/-debug marker is present
|
|
76
|
-
if version is not None:
|
|
75
|
+
release, threaded = (None, None, None), None
|
|
76
|
+
if (version := match["version"]) is not None:
|
|
77
77
|
try:
|
|
78
|
-
|
|
78
|
+
release = _parse_version_parts(version)
|
|
79
79
|
except ValueError:
|
|
80
80
|
return None
|
|
81
|
-
threaded = bool(
|
|
82
|
-
|
|
81
|
+
threaded = bool(match["threaded"])
|
|
82
|
+
return _spec_from_match(string_spec, match, release, threaded=threaded, version_specifier=None)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def _spec_from_match(
|
|
86
|
+
string_spec: str,
|
|
87
|
+
match: re.Match[str],
|
|
88
|
+
release: tuple[int | None, int | None, int | None],
|
|
89
|
+
*,
|
|
90
|
+
threaded: bool | None,
|
|
91
|
+
version_specifier: SpecifierSet | None,
|
|
92
|
+
) -> PythonSpec:
|
|
93
|
+
impl = match["impl"]
|
|
83
94
|
if impl in {"py", "python"}:
|
|
84
95
|
impl = None
|
|
85
96
|
if impl == "graalvm":
|
|
86
97
|
impl = "graalpy"
|
|
87
|
-
arch = _int_or_none(groups["arch"])
|
|
88
|
-
machine = groups.get("machine")
|
|
89
|
-
if machine is not None:
|
|
90
|
-
machine = normalize_isa(machine)
|
|
91
98
|
return PythonSpec(
|
|
92
|
-
string_spec,
|
|
99
|
+
string_spec,
|
|
100
|
+
impl,
|
|
101
|
+
*release,
|
|
102
|
+
_int_or_none(match["arch"]),
|
|
103
|
+
None,
|
|
104
|
+
free_threaded=threaded,
|
|
105
|
+
machine=None if (machine := match["machine"]) is None else normalize_isa(machine),
|
|
106
|
+
debug=True if match["debug"] else None, # unconstrained unless an explicit d/-dbg/-debug marker is present
|
|
107
|
+
version_specifier=version_specifier,
|
|
93
108
|
)
|
|
94
109
|
|
|
95
110
|
|
|
96
111
|
def _parse_specifier(string_spec: str) -> PythonSpec | None:
|
|
97
|
-
if not (
|
|
98
|
-
return None
|
|
99
|
-
if SpecifierSet is None: # pragma: no cover
|
|
112
|
+
if not (match := SPECIFIER_PATTERN.match(string_spec.strip())):
|
|
100
113
|
return None
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
version_specifier = SpecifierSet.from_string(spec_text)
|
|
105
|
-
except InvalidSpecifier: # pragma: no cover
|
|
106
|
-
return None
|
|
107
|
-
# the set never raises: it keeps an unparsable version as None and drops items without an operator, so fall back
|
|
108
|
-
# to a literal path, like any other unrecognized spec, unless every item parsed into a usable version
|
|
114
|
+
spec_text = match["spec"].strip()
|
|
115
|
+
version_specifier = SpecifierSet.from_string(spec_text)
|
|
116
|
+
# the set never raises: it keeps an unparsable version as None and drops items without an operator
|
|
109
117
|
items = [item for item in spec_text.split(",") if item.strip()]
|
|
110
118
|
if len(items) != len(version_specifier.specifiers) or any(spec.version is None for spec in version_specifier):
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
119
|
+
msg = f"invalid version specifier {string_spec!r}"
|
|
120
|
+
raise ValueError(msg)
|
|
121
|
+
return _spec_from_match(
|
|
122
|
+
string_spec,
|
|
123
|
+
match,
|
|
124
|
+
(None, None, None),
|
|
125
|
+
# the version bounds say nothing about the build, so without a trailing t any build qualifies
|
|
126
|
+
threaded=True if match["threaded"] else None,
|
|
127
|
+
version_specifier=version_specifier,
|
|
128
|
+
)
|
|
117
129
|
|
|
118
130
|
|
|
119
131
|
class PythonSpec:
|
|
@@ -169,6 +181,7 @@ class PythonSpec:
|
|
|
169
181
|
|
|
170
182
|
:param string_spec: an interpreter spec — an absolute path, a version string, an implementation prefix,
|
|
171
183
|
or a `version specifier <https://packaging.python.org/en/latest/specifications/version-specifiers/>`_.
|
|
184
|
+
:raises ValueError: if the spec starts with a version specifier operator but does not parse as one.
|
|
172
185
|
"""
|
|
173
186
|
if pathlib.Path(string_spec).is_absolute():
|
|
174
187
|
return cls(string_spec, None, None, None, None, None, string_spec)
|
|
@@ -2,16 +2,16 @@ python_discovery/__init__.py,sha256=Hi4j3pMvC8Fo8KoNL-wOHsPSCUHwY4c0qvv5sjnFzME,
|
|
|
2
2
|
python_discovery/_cache.py,sha256=svmG2GzUQzd2xTjAbm2eX1CKxxGAglfv4kxaPuxwPIA,5147
|
|
3
3
|
python_discovery/_cached_py_info.py,sha256=15P5_TODxkZCkNfD2Uk5dtPxGf0Nea_aWm2N7uY9zbY,12059
|
|
4
4
|
python_discovery/_compat.py,sha256=iqxGuhK9rPaiui80G1H1KrweoMJ16gyLYEmUrSXrp5c,709
|
|
5
|
-
python_discovery/_discovery.py,sha256=
|
|
6
|
-
python_discovery/_py_info.py,sha256=
|
|
5
|
+
python_discovery/_discovery.py,sha256=Ulq3gbOrCvVULengzFF20yrDwGYCj3xs86CGqF2LThc,23212
|
|
6
|
+
python_discovery/_py_info.py,sha256=fAhFj5swYdGvhJpAXR6b6O1yT2MSbRXTDMrdu15e6q8,26965
|
|
7
7
|
python_discovery/_py_info_collect.py,sha256=3PNlySbxNSHDjBw8KJ_olVpOXww1qhGdY28YoLfF0Z8,16160
|
|
8
|
-
python_discovery/_py_spec.py,sha256=
|
|
8
|
+
python_discovery/_py_spec.py,sha256=14WRyDOLEQt7COevcUU5Rb6sgy99l9XI5XEQRUtCHf8,11800
|
|
9
9
|
python_discovery/_specifier.py,sha256=9sMnJs7FTfIIduTCKKTA7Lk7onARqwkG_zzFIqgj0xs,10364
|
|
10
10
|
python_discovery/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
11
11
|
python_discovery/_windows/__init__.py,sha256=qthcyGh36b3WkeSbZ4ECRRYLbCOCaQu5X_DRZ98tXfk,315
|
|
12
12
|
python_discovery/_windows/_pep514.py,sha256=Vhxe-3hETFIXQrekLqOHmzG5eq5moeR8b0dCS80zbBg,8026
|
|
13
13
|
python_discovery/_windows/_propose.py,sha256=EE-N-BiNgrFU9mQ34SkoF5gRaNjtspghssQxT9uRQi0,1756
|
|
14
|
-
python_discovery-1.
|
|
15
|
-
python_discovery-1.
|
|
16
|
-
python_discovery-1.
|
|
17
|
-
python_discovery-1.
|
|
14
|
+
python_discovery-1.7.0.dist-info/METADATA,sha256=FOu5Fx2hWx_B48bPGJK6vX-1lRqt3ahuJfbn86jW1tw,3937
|
|
15
|
+
python_discovery-1.7.0.dist-info/WHEEL,sha256=W3fkpkm7-wf9vBI5Z-7s0eWkeM-spu78I8Neb98DeEg,87
|
|
16
|
+
python_discovery-1.7.0.dist-info/licenses/LICENSE,sha256=kOJeH68qSq6o2V7o5_VziwUqGswMnFgGgQH5Mahr1Yg,1023
|
|
17
|
+
python_discovery-1.7.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|