python-discovery 1.6.7__py3-none-any.whl → 1.8.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 +14 -5
- python_discovery/_py_info.py +1 -0
- python_discovery/_py_info_collect.py +24 -0
- python_discovery/_py_spec.py +52 -39
- {python_discovery-1.6.7.dist-info → python_discovery-1.8.0.dist-info}/METADATA +1 -1
- {python_discovery-1.6.7.dist-info → python_discovery-1.8.0.dist-info}/RECORD +8 -8
- {python_discovery-1.6.7.dist-info → python_discovery-1.8.0.dist-info}/WHEEL +0 -0
- {python_discovery-1.6.7.dist-info → python_discovery-1.8.0.dist-info}/licenses/LICENSE +0 -0
python_discovery/_discovery.py
CHANGED
|
@@ -532,11 +532,10 @@ def _read_python_version_file(start: str | Path, *, search_parents: bool = True)
|
|
|
532
532
|
"""Read a ``.python-version`` file, optionally searching parent directories."""
|
|
533
533
|
current = start
|
|
534
534
|
while True:
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
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
|
|
540
539
|
if not search_parents:
|
|
541
540
|
return None
|
|
542
541
|
parent = Path(current).parent
|
|
@@ -545,6 +544,16 @@ def _read_python_version_file(start: str | Path, *, search_parents: bool = True)
|
|
|
545
544
|
current = parent
|
|
546
545
|
|
|
547
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
|
+
|
|
548
557
|
class PathPythonInfo(PythonInfo):
|
|
549
558
|
"""python info from path."""
|
|
550
559
|
|
python_discovery/_py_info.py
CHANGED
|
@@ -64,6 +64,30 @@ class PythonInfoCollector:
|
|
|
64
64
|
self.os = os.name
|
|
65
65
|
self.free_threaded = sysconfig.get_config_var("Py_GIL_DISABLED") == 1
|
|
66
66
|
self.debug_build = bool(sysconfig.get_config_var("Py_DEBUG"))
|
|
67
|
+
# Vermin checks the whole script against Python 2.7 despite the version gate above.
|
|
68
|
+
interpreter = getattr(sys, "implementation") # ruff:ignore[get-attr-with-constant]
|
|
69
|
+
interpreter_version = interpreter.version
|
|
70
|
+
marker_version = "{}.{}.{}{}".format(
|
|
71
|
+
interpreter_version.major,
|
|
72
|
+
interpreter_version.minor,
|
|
73
|
+
interpreter_version.micro,
|
|
74
|
+
"{}{}".format(interpreter_version.releaselevel[0], interpreter_version.serial)
|
|
75
|
+
if interpreter_version.releaselevel != "final"
|
|
76
|
+
else "",
|
|
77
|
+
)
|
|
78
|
+
self.marker_environment = {
|
|
79
|
+
"implementation_name": interpreter.name,
|
|
80
|
+
"implementation_version": marker_version,
|
|
81
|
+
"os_name": os.name,
|
|
82
|
+
"platform_machine": platform.machine(),
|
|
83
|
+
"platform_release": platform.release(),
|
|
84
|
+
"platform_system": platform.system(),
|
|
85
|
+
"platform_version": platform.version(),
|
|
86
|
+
"python_full_version": platform.python_version(),
|
|
87
|
+
"platform_python_implementation": platform.python_implementation(),
|
|
88
|
+
"python_version": ".".join(platform.python_version_tuple()[:2]),
|
|
89
|
+
"sys_platform": sys.platform,
|
|
90
|
+
}
|
|
67
91
|
|
|
68
92
|
def _init_prefixes(self):
|
|
69
93
|
def abs_path(value):
|
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=
|
|
7
|
-
python_discovery/_py_info_collect.py,sha256=
|
|
8
|
-
python_discovery/_py_spec.py,sha256=
|
|
5
|
+
python_discovery/_discovery.py,sha256=Ulq3gbOrCvVULengzFF20yrDwGYCj3xs86CGqF2LThc,23212
|
|
6
|
+
python_discovery/_py_info.py,sha256=iCmE5rv-B9yGpSmaSeZx2RF1x5FCf3ezarsHnMpT6JA,27004
|
|
7
|
+
python_discovery/_py_info_collect.py,sha256=k9P4JzNkvW9iw37teeu7L6Y27ytWTnvWiK47B3gm5xg,17390
|
|
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.8.0.dist-info/METADATA,sha256=USw0gc2rwC_fdUMXfh3bWhnDQ7imwPM8uDeyYo8e16M,3937
|
|
15
|
+
python_discovery-1.8.0.dist-info/WHEEL,sha256=W3fkpkm7-wf9vBI5Z-7s0eWkeM-spu78I8Neb98DeEg,87
|
|
16
|
+
python_discovery-1.8.0.dist-info/licenses/LICENSE,sha256=kOJeH68qSq6o2V7o5_VziwUqGswMnFgGgQH5Mahr1Yg,1023
|
|
17
|
+
python_discovery-1.8.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|