python-discovery 1.9.0__tar.gz → 1.9.1__tar.gz

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.
Files changed (69) hide show
  1. {python_discovery-1.9.0 → python_discovery-1.9.1}/PKG-INFO +1 -1
  2. {python_discovery-1.9.0 → python_discovery-1.9.1}/docs/changelog.rst +20 -0
  3. {python_discovery-1.9.0 → python_discovery-1.9.1}/docs/explanation.rst +4 -3
  4. {python_discovery-1.9.0 → python_discovery-1.9.1}/src/python_discovery/_discovery.py +3 -2
  5. {python_discovery-1.9.0 → python_discovery-1.9.1}/src/python_discovery/_py_info.py +3 -2
  6. {python_discovery-1.9.0 → python_discovery-1.9.1}/src/python_discovery/_py_spec.py +6 -3
  7. {python_discovery-1.9.0 → python_discovery-1.9.1}/tests/test_discovery.py +29 -0
  8. {python_discovery-1.9.0 → python_discovery-1.9.1}/tests/test_iter_interpreters.py +23 -0
  9. {python_discovery-1.9.0 → python_discovery-1.9.1}/tests/test_py_info_extra.py +19 -4
  10. {python_discovery-1.9.0 → python_discovery-1.9.1}/tests/test_py_spec_extra.py +46 -0
  11. {python_discovery-1.9.0 → python_discovery-1.9.1}/.github/FUNDING.yaml +0 -0
  12. {python_discovery-1.9.0 → python_discovery-1.9.1}/.github/SECURITY.md +0 -0
  13. {python_discovery-1.9.0 → python_discovery-1.9.1}/.github/THREAT_MODEL.md +0 -0
  14. {python_discovery-1.9.0 → python_discovery-1.9.1}/.github/dependabot.yaml +0 -0
  15. {python_discovery-1.9.0 → python_discovery-1.9.1}/.github/release.yaml +0 -0
  16. {python_discovery-1.9.0 → python_discovery-1.9.1}/.github/workflows/check.yaml +0 -0
  17. {python_discovery-1.9.0 → python_discovery-1.9.1}/.github/workflows/codeql.yaml +0 -0
  18. {python_discovery-1.9.0 → python_discovery-1.9.1}/.github/workflows/news.yaml +0 -0
  19. {python_discovery-1.9.0 → python_discovery-1.9.1}/.github/workflows/prepare-release.yaml +0 -0
  20. {python_discovery-1.9.0 → python_discovery-1.9.1}/.github/workflows/release.yaml +0 -0
  21. {python_discovery-1.9.0 → python_discovery-1.9.1}/.github/workflows/upgrade-release-tools.yaml +0 -0
  22. {python_discovery-1.9.0 → python_discovery-1.9.1}/.gitignore +0 -0
  23. {python_discovery-1.9.0 → python_discovery-1.9.1}/.pre-commit-config.yaml +0 -0
  24. {python_discovery-1.9.0 → python_discovery-1.9.1}/.readthedocs.yaml +0 -0
  25. {python_discovery-1.9.0 → python_discovery-1.9.1}/.readthedocs.yml +0 -0
  26. {python_discovery-1.9.0 → python_discovery-1.9.1}/CODE_OF_CONDUCT.md +0 -0
  27. {python_discovery-1.9.0 → python_discovery-1.9.1}/LICENSE +0 -0
  28. {python_discovery-1.9.0 → python_discovery-1.9.1}/README.md +0 -0
  29. {python_discovery-1.9.0 → python_discovery-1.9.1}/docs/_static/custom.css +0 -0
  30. {python_discovery-1.9.0 → python_discovery-1.9.1}/docs/_static/github.svg +0 -0
  31. {python_discovery-1.9.0 → python_discovery-1.9.1}/docs/_static/logo.svg +0 -0
  32. {python_discovery-1.9.0 → python_discovery-1.9.1}/docs/changelog/template.jinja2 +0 -0
  33. {python_discovery-1.9.0 → python_discovery-1.9.1}/docs/conf.py +0 -0
  34. {python_discovery-1.9.0 → python_discovery-1.9.1}/docs/contributing.rst +0 -0
  35. {python_discovery-1.9.0 → python_discovery-1.9.1}/docs/how-to/standalone-usage.rst +0 -0
  36. {python_discovery-1.9.0 → python_discovery-1.9.1}/docs/index.rst +0 -0
  37. {python_discovery-1.9.0 → python_discovery-1.9.1}/docs/reference/api.rst +0 -0
  38. {python_discovery-1.9.0 → python_discovery-1.9.1}/docs/reference/environment-variables.rst +0 -0
  39. {python_discovery-1.9.0 → python_discovery-1.9.1}/docs/tutorial/getting-started.rst +0 -0
  40. {python_discovery-1.9.0 → python_discovery-1.9.1}/pylock.toml +0 -0
  41. {python_discovery-1.9.0 → python_discovery-1.9.1}/pyproject.toml +0 -0
  42. {python_discovery-1.9.0 → python_discovery-1.9.1}/src/python_discovery/__init__.py +0 -0
  43. {python_discovery-1.9.0 → python_discovery-1.9.1}/src/python_discovery/_cache.py +0 -0
  44. {python_discovery-1.9.0 → python_discovery-1.9.1}/src/python_discovery/_cached_py_info.py +0 -0
  45. {python_discovery-1.9.0 → python_discovery-1.9.1}/src/python_discovery/_compat.py +0 -0
  46. {python_discovery-1.9.0 → python_discovery-1.9.1}/src/python_discovery/_py_info_collect.py +0 -0
  47. {python_discovery-1.9.0 → python_discovery-1.9.1}/src/python_discovery/_specifier.py +0 -0
  48. {python_discovery-1.9.0 → python_discovery-1.9.1}/src/python_discovery/_windows/__init__.py +0 -0
  49. {python_discovery-1.9.0 → python_discovery-1.9.1}/src/python_discovery/_windows/_pep514.py +0 -0
  50. {python_discovery-1.9.0 → python_discovery-1.9.1}/src/python_discovery/_windows/_propose.py +0 -0
  51. {python_discovery-1.9.0 → python_discovery-1.9.1}/src/python_discovery/py.typed +0 -0
  52. {python_discovery-1.9.0 → python_discovery-1.9.1}/tasks/old_target_check.py +0 -0
  53. {python_discovery-1.9.0 → python_discovery-1.9.1}/tasks/old_target_check.sh +0 -0
  54. {python_discovery-1.9.0 → python_discovery-1.9.1}/tests/conftest.py +0 -0
  55. {python_discovery-1.9.0 → python_discovery-1.9.1}/tests/py_info/test_py_info.py +0 -0
  56. {python_discovery-1.9.0 → python_discovery-1.9.1}/tests/py_info/test_py_info_exe_based_of.py +0 -0
  57. {python_discovery-1.9.0 → python_discovery-1.9.1}/tests/test_cache.py +0 -0
  58. {python_discovery-1.9.0 → python_discovery-1.9.1}/tests/test_cache_recovery.py +0 -0
  59. {python_discovery-1.9.0 → python_discovery-1.9.1}/tests/test_cached_py_info.py +0 -0
  60. {python_discovery-1.9.0 → python_discovery-1.9.1}/tests/test_discovery_extra.py +0 -0
  61. {python_discovery-1.9.0 → python_discovery-1.9.1}/tests/test_py_info_collect.py +0 -0
  62. {python_discovery-1.9.0 → python_discovery-1.9.1}/tests/test_py_spec.py +0 -0
  63. {python_discovery-1.9.0 → python_discovery-1.9.1}/tests/test_query_timeout.py +0 -0
  64. {python_discovery-1.9.0 → python_discovery-1.9.1}/tests/test_specifier.py +0 -0
  65. {python_discovery-1.9.0 → python_discovery-1.9.1}/tests/windows/conftest.py +0 -0
  66. {python_discovery-1.9.0 → python_discovery-1.9.1}/tests/windows/test_windows.py +0 -0
  67. {python_discovery-1.9.0 → python_discovery-1.9.1}/tests/windows/test_windows_pep514.py +0 -0
  68. {python_discovery-1.9.0 → python_discovery-1.9.1}/tests/windows/winreg_mock_values.py +0 -0
  69. {python_discovery-1.9.0 → python_discovery-1.9.1}/tox.toml +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: python-discovery
3
- Version: 1.9.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
@@ -6,6 +6,26 @@
6
6
 
7
7
  .. towncrier release notes start
8
8
 
9
+ .. _release-1-9-1:
10
+
11
+ *********************
12
+ v1.9.1 (2026-11-02)
13
+ *********************
14
+
15
+ .. _release-1-9-1-fixed:
16
+
17
+ Fixed
18
+ -----
19
+
20
+ - List free-threaded and debug builds on ``PATH``, such as ``python3.13t``, ``python3.13d`` and ``python3.13-dbg``, when
21
+ ``iter_interpreters()`` runs with no spec, as it already did for uv's ``+freethreaded`` and ``+debug`` installs
22
+ (:pr:`181`) by :user:`darrenhuai` and :user:`gaborbernat`.
23
+ - Reuse preferred interpreter paths supplied as an iterator when trying multiple interpreter specifications (:pr:`180`)
24
+ by :user:`subotac` and :user:`gaborbernat`.
25
+ - Stop ``PythonInfo.system_include`` reporting the interpreter's prefix as the include directory when the C headers are
26
+ not installed, which happened on Python 3.11 and later and on Debian's 3.10; the missing sysconfig include path is
27
+ returned instead (:pr:`182`) by :user:`darrenhuai` and :user:`gaborbernat`.
28
+
9
29
  .. _release-1-9-0:
10
30
 
11
31
  *********************
@@ -180,9 +180,10 @@ PATH unless the spec names another implementation explicitly (``pypy3.12``, ``gr
180
180
  compatibility with tools that have always read "no implementation in the spec" as "give me CPython."
181
181
  :func:`~python_discovery.iter_interpreters` with no spec broadens the search to every name in
182
182
  :data:`~python_discovery.KNOWN_IMPLEMENTATIONS` -- otherwise an "all interpreters" call would silently miss every
183
- PyPy and GraalPy on the system. When you pass a spec to :func:`~python_discovery.iter_interpreters`, it falls back
184
- to the same narrow regex as :func:`~python_discovery.get_interpreter`, so behavior is consistent across the two
185
- APIs whenever a spec is given.
183
+ PyPy and GraalPy on the system. It also matches the free-threaded and debug names (``python3.13t``, ``python3.13d``,
184
+ ``python3.13-dbg``), so PATH lists those builds just as uv's ``+freethreaded`` and ``+debug`` installs are listed.
185
+ When you pass a spec to :func:`~python_discovery.iter_interpreters`, it falls back to the same narrow regex as
186
+ :func:`~python_discovery.get_interpreter`, so behavior is consistent across the two APIs whenever a spec is given.
186
187
 
187
188
  **Deduplication.** :func:`~python_discovery.get_interpreter` deduplicates per call so it does not interrogate the
188
189
  same binary twice while searching, and stops as soon as a match is found. :func:`~python_discovery.iter_interpreters`
@@ -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
 
@@ -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
@@ -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(
@@ -133,6 +133,35 @@ def test_discovery_invalid_specifier_raises(session_cache: DiskCache) -> None:
133
133
  get_interpreter([">=3.12 <4", sys.executable], cache=session_cache)
134
134
 
135
135
 
136
+ @pytest.mark.parametrize(
137
+ "use_iterator",
138
+ [pytest.param(False, id="list"), pytest.param(True, id="iterator")],
139
+ )
140
+ def test_discovery_fallback_reuses_preferred_paths(
141
+ tmp_path: Path, session_cache: DiskCache, *, use_iterator: bool
142
+ ) -> None:
143
+ preferred = tmp_path / "preferred"
144
+ subprocess.check_call([sys.executable, "-m", "venv", "--without-pip", "--copies", str(preferred)])
145
+ executable = preferred / ("Scripts/python.exe" if IS_WIN else "bin/python")
146
+ paths = [str(executable)]
147
+ result = get_interpreter(
148
+ ["missing-interpreter", str(sys.version_info.major)],
149
+ try_first_with=iter(paths) if use_iterator else paths,
150
+ cache=session_cache,
151
+ env={**os.environ, "PATH": str(tmp_path), "UV_PYTHON_INSTALL_DIR": str(tmp_path / "missing")},
152
+ predicate=lambda info: Path(info.executable) == executable,
153
+ )
154
+ assert result is not None
155
+ assert Path(result.executable) == executable
156
+
157
+
158
+ def test_discovery_stops_reading_preferred_paths_after_match(session_cache: DiskCache) -> None:
159
+ preferred_paths = iter([sys.executable, "unneeded"])
160
+ result = get_interpreter(str(sys.version_info.major), try_first_with=preferred_paths, cache=session_cache)
161
+ assert result is not None
162
+ assert next(preferred_paths) == "unneeded"
163
+
164
+
136
165
  @pytest.fixture
137
166
  def mock_find_interpreter(mocker: MockerFixture) -> None:
138
167
  mocker.patch(
@@ -121,6 +121,29 @@ def test_iter_interpreters_no_key_includes_running_interpreter(session_cache: Di
121
121
  assert any(os.path.realpath(info.executable) == real_self for info in results)
122
122
 
123
123
 
124
+ @pytest.mark.usefixtures("uv_dir")
125
+ @pytest.mark.parametrize(
126
+ "name",
127
+ [
128
+ pytest.param("python3.99t", id="free-threaded"),
129
+ pytest.param("python3.99d", id="debug-abi"),
130
+ pytest.param("python3.99-dbg", id="debug-debian"),
131
+ ],
132
+ )
133
+ def test_iter_interpreters_no_key_probes_variant_builds_on_path(
134
+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch, mocker: MockerFixture, name: str
135
+ ) -> None:
136
+ exe = tmp_path / "bin" / f"{name}{'.exe' if IS_WIN else ''}"
137
+ exe.parent.mkdir()
138
+ exe.touch()
139
+ monkeypatch.setenv("PATH", str(exe.parent))
140
+ from_exe = mocker.patch("python_discovery._discovery.PathPythonInfo.from_exe", return_value=None)
141
+
142
+ list(iter_interpreters())
143
+
144
+ assert str(exe) in [call.args[0] for call in from_exe.call_args_list]
145
+
146
+
124
147
  @pytest.mark.usefixtures("uv_dir")
125
148
  def test_iter_interpreters_dedups_symlinks(
126
149
  tmp_path: Path,
@@ -276,11 +276,26 @@ def test_system_include() -> None:
276
276
  assert isinstance(result, str)
277
277
 
278
278
 
279
- def test_system_include_fallback(mocker: MockerFixture) -> None:
279
+ @pytest.mark.parametrize(
280
+ ("distutils_install", "existing", "expected"),
281
+ [
282
+ pytest.param({}, [], "include", id="no-headers-path"),
283
+ pytest.param({"headers": "headers/UNKNOWN"}, ["headers"], "headers", id="headers"),
284
+ pytest.param({"headers": "headers/UNKNOWN"}, [], "include", id="headers-missing"),
285
+ pytest.param({"headers": "headers/UNKNOWN"}, ["include", "headers"], "include", id="include-present"),
286
+ ],
287
+ )
288
+ def test_system_include_fallback(
289
+ tmp_path: Path, distutils_install: dict[str, str], existing: list[str], expected: str
290
+ ) -> None:
280
291
  info = copy.deepcopy(CURRENT)
281
- mocker.patch("os.path.exists", side_effect=lambda p: "include" not in p or "dist" in p.lower())
282
- result = info.system_include
283
- assert isinstance(result, str)
292
+ info.prefix, info.base_prefix, info.real_prefix = str(tmp_path), None, None
293
+ info.sysconfig_vars = {"base": str(tmp_path)}
294
+ info.sysconfig_paths = {"include": "{base}/include"}
295
+ info.distutils_install = distutils_install
296
+ for name in existing:
297
+ (tmp_path / name).mkdir()
298
+ assert info.system_include == str(tmp_path / expected)
284
299
 
285
300
 
286
301
  def test_sysconfig_path_missing_key() -> None:
@@ -95,6 +95,52 @@ def test_generate_re_with_debug(name: str) -> None:
95
95
  assert pat.fullmatch(name) is not None
96
96
 
97
97
 
98
+ @pytest.mark.parametrize(
99
+ "name",
100
+ [
101
+ pytest.param("python3.99t", id="free-threaded"),
102
+ pytest.param("python3.99d", id="debug-abi"),
103
+ pytest.param("python3.99-dbg", id="debug-short"),
104
+ pytest.param("python3.99-debug", id="debug-long"),
105
+ pytest.param("python3.99td", id="free-threaded-debug-abi"),
106
+ pytest.param("python3.99t-dbg", id="free-threaded-debug-short"),
107
+ ],
108
+ )
109
+ @pytest.mark.parametrize("windows", [pytest.param(False, id="posix"), pytest.param(True, id="windows")])
110
+ def test_generate_re_all_implementations_matches_variant_names(name: str, windows: bool) -> None:
111
+ spec = PythonSpec("", None, None, None, None, None, None)
112
+ pat = spec.generate_re(windows=windows, all_implementations=True)
113
+ assert pat.fullmatch(f"{name}.exe" if windows else name) is not None
114
+
115
+
116
+ @pytest.mark.parametrize(
117
+ "name",
118
+ [
119
+ pytest.param("python3.99t", id="free-threaded"),
120
+ pytest.param("python3.99d", id="debug-abi"),
121
+ pytest.param("python3.99-dbg", id="debug-debian"),
122
+ ],
123
+ )
124
+ @pytest.mark.parametrize("key", [pytest.param("python", id="name"), pytest.param("3.99", id="version")])
125
+ def test_generate_re_single_lookup_skips_variant_names(key: str, name: str) -> None:
126
+ pat = PythonSpec.from_string_spec(key).generate_re(windows=False)
127
+ assert pat.fullmatch(name) is None
128
+
129
+
130
+ @pytest.mark.parametrize(
131
+ "name",
132
+ [
133
+ pytest.param("python3.99t", id="free-threaded"),
134
+ pytest.param("python3.99d", id="debug-abi"),
135
+ pytest.param("python3.99-dbg", id="debug-debian"),
136
+ ],
137
+ )
138
+ def test_generate_re_all_implementations_keeps_ruled_out_variants_out(name: str) -> None:
139
+ spec = PythonSpec("", None, 3, 99, None, None, None, free_threaded=False, debug=False)
140
+ pat = spec.generate_re(windows=False, all_implementations=True)
141
+ assert pat.fullmatch(name) is None
142
+
143
+
98
144
  def test_single_digit_version() -> None:
99
145
  spec = PythonSpec.from_string_spec("python3")
100
146
  assert spec.major == 3