python-discovery 1.8.0__py3-none-any.whl → 1.9.1__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.
@@ -6,7 +6,7 @@ from importlib.metadata import version
6
6
 
7
7
  from ._cache import ContentStore, DiskCache, PyInfoCache
8
8
  from ._discovery import get_interpreter, iter_interpreters
9
- from ._py_info import KNOWN_ARCHITECTURES, PythonInfo, normalize_isa
9
+ from ._py_info import KNOWN_ARCHITECTURES, MarkerEnvironment, PythonInfo, normalize_isa
10
10
  from ._py_spec import KNOWN_IMPLEMENTATIONS, PythonSpec
11
11
  from ._specifier import SimpleSpecifier, SimpleSpecifierSet, SimpleVersion
12
12
 
@@ -17,6 +17,7 @@ __all__ = [
17
17
  "KNOWN_IMPLEMENTATIONS",
18
18
  "ContentStore",
19
19
  "DiskCache",
20
+ "MarkerEnvironment",
20
21
  "PyInfoCache",
21
22
  "PythonInfo",
22
23
  "PythonSpec",
@@ -5,6 +5,7 @@ import os
5
5
  import sys
6
6
  from contextlib import suppress
7
7
  from dataclasses import dataclass
8
+ from itertools import tee
8
9
  from pathlib import Path
9
10
  from typing import TYPE_CHECKING, Final
10
11
 
@@ -47,8 +48,8 @@ def get_interpreter(
47
48
  :return: the first matching interpreter, or ``None`` if no match is found.
48
49
  """
49
50
  specs = [key] if isinstance(key, str) else key
50
- for spec_str in specs:
51
- if result := _find_interpreter(spec_str, try_first_with or (), cache, env, predicate):
51
+ for spec_str, preferred_paths in zip(specs, tee(try_first_with or (), len(specs))):
52
+ if result := _find_interpreter(spec_str, preferred_paths, cache, env, predicate):
52
53
  return result
53
54
  return None
54
55
 
@@ -11,7 +11,7 @@ import sys
11
11
  from collections import OrderedDict
12
12
  from itertools import product
13
13
  from string import digits
14
- from typing import TYPE_CHECKING, ClassVar, Final, NamedTuple
14
+ from typing import TYPE_CHECKING, ClassVar, Final, NamedTuple, TypedDict
15
15
 
16
16
  from ._py_info_collect import PythonInfoCollector
17
17
 
@@ -57,7 +57,7 @@ class PythonInfo: # ruff:ignore[too-many-public-methods]
57
57
  os: str
58
58
  free_threaded: bool
59
59
  debug_build: bool
60
- marker_environment: dict[str, str]
60
+ marker_environment: MarkerEnvironment
61
61
  prefix: str | None
62
62
  base_prefix: str | None
63
63
  real_prefix: str | None
@@ -153,8 +153,9 @@ class PythonInfo: # ruff:ignore[too-many-public-methods]
153
153
  for k, v in self.sysconfig_vars.items()
154
154
  },
155
155
  )
156
- if not os.path.exists(path): # pragma: no cover # broken packaging fallback
157
- fallback = os.path.join(self.prefix, os.path.dirname(self.install_path("headers")))
156
+ # An empty headers path would make the fallback resolve to the existing prefix.
157
+ if not os.path.exists(path) and (headers := os.path.dirname(self.install_path("headers"))):
158
+ fallback = os.path.join(self.prefix, headers)
158
159
  if os.path.exists(fallback):
159
160
  path = fallback
160
161
  return path
@@ -629,6 +630,20 @@ class PythonInfo: # ruff:ignore[too-many-public-methods]
629
630
  yield upper
630
631
 
631
632
 
633
+ class MarkerEnvironment(TypedDict):
634
+ implementation_name: str
635
+ implementation_version: str
636
+ os_name: str
637
+ platform_machine: str
638
+ platform_release: str
639
+ platform_system: str
640
+ platform_version: str
641
+ python_full_version: str
642
+ platform_python_implementation: str
643
+ python_version: str
644
+ sys_platform: str
645
+
646
+
632
647
  KNOWN_ARCHITECTURES: frozenset[str] = frozenset({
633
648
  "arm64",
634
649
  "loongarch64",
@@ -672,6 +687,7 @@ def normalize_isa(isa: str) -> str:
672
687
 
673
688
  __all__ = [
674
689
  "KNOWN_ARCHITECTURES",
690
+ "MarkerEnvironment",
675
691
  "PythonInfo",
676
692
  "VersionInfo",
677
693
  "normalize_isa",
@@ -197,7 +197,9 @@ class PythonSpec:
197
197
 
198
198
  :param windows: if ``True``, require a ``.exe`` suffix.
199
199
  :param all_implementations: when ``True`` and the spec does not constrain the implementation, match every
200
- filename in :data:`KNOWN_IMPLEMENTATIONS` instead of only ``python``. Used by enumeration APIs.
200
+ filename in :data:`KNOWN_IMPLEMENTATIONS` instead of only ``python``. A free-threaded or debug build the
201
+ spec leaves open also matches its marked name, such as ``python3.13t`` or ``python3.13-dbg``. Used by
202
+ enumeration APIs.
201
203
  """
202
204
  version = r"{}(\.{}(\.{})?)?".format(
203
205
  *(r"\d+" if v is None else v for v in (self.major, self.minor, self.micro)),
@@ -208,8 +210,9 @@ class PythonSpec:
208
210
  impl = "|".join(re.escape(i) for i in KNOWN_IMPLEMENTATIONS)
209
211
  else:
210
212
  impl = "python"
211
- mod = "t?" if self.free_threaded else ""
212
- dbg = "(?:d|-dbg|-debug)?" if self.debug else ""
213
+ # An unconstrained single lookup must not depend on directory order to choose a variant.
214
+ mod = "t?" if self.free_threaded or (all_implementations and self.free_threaded is None) else ""
215
+ dbg = "(?:d|-dbg|-debug)?" if self.debug or (all_implementations and self.debug is None) else ""
213
216
  suffix = r"\.exe" if windows else ""
214
217
  version_conditional = "?" if windows or self.major is None else ""
215
218
  return re.compile(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: python-discovery
3
- Version: 1.8.0
3
+ Version: 1.9.1
4
4
  Import-Name: python_discovery
5
5
  Summary: Python interpreter discovery
6
6
  Project-URL: Changelog, https://github.com/tox-dev/python-discovery/blob/main/docs/changelog.rst
@@ -1,17 +1,17 @@
1
- python_discovery/__init__.py,sha256=Hi4j3pMvC8Fo8KoNL-wOHsPSCUHwY4c0qvv5sjnFzME,808
1
+ python_discovery/__init__.py,sha256=BV4pKMWDAK_3pU8o2hYvtL30WKs_wTzIBRuFV7nUaug,852
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=Ulq3gbOrCvVULengzFF20yrDwGYCj3xs86CGqF2LThc,23212
6
- python_discovery/_py_info.py,sha256=iCmE5rv-B9yGpSmaSeZx2RF1x5FCf3ezarsHnMpT6JA,27004
5
+ python_discovery/_discovery.py,sha256=4a-fRJsy6a1x__0LiiavTmQula5kN2-MnBj3fR-FKJk,23294
6
+ python_discovery/_py_info.py,sha256=uP3fWpLy_N4HSIzTFQxEyxSkUBusZy-qX3Pp3VJGVg4,27442
7
7
  python_discovery/_py_info_collect.py,sha256=k9P4JzNkvW9iw37teeu7L6Y27ytWTnvWiK47B3gm5xg,17390
8
- python_discovery/_py_spec.py,sha256=14WRyDOLEQt7COevcUU5Rb6sgy99l9XI5XEQRUtCHf8,11800
8
+ python_discovery/_py_spec.py,sha256=s76yM2zbrKdvwhaDlPyUo6ERKkn2MldRNydPZucNvOM,12154
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.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,,
14
+ python_discovery-1.9.1.dist-info/METADATA,sha256=6xq9g-xC6bvsDbWc0CrFmdrq4uv519kMstNNZ_bdAO4,3937
15
+ python_discovery-1.9.1.dist-info/WHEEL,sha256=W3fkpkm7-wf9vBI5Z-7s0eWkeM-spu78I8Neb98DeEg,87
16
+ python_discovery-1.9.1.dist-info/licenses/LICENSE,sha256=kOJeH68qSq6o2V7o5_VziwUqGswMnFgGgQH5Mahr1Yg,1023
17
+ python_discovery-1.9.1.dist-info/RECORD,,