python-discovery 1.9.4__tar.gz → 1.9.5__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 (72) hide show
  1. {python_discovery-1.9.4 → python_discovery-1.9.5}/.github/workflows/check.yaml +1 -1
  2. python_discovery-1.9.5/CONTRIBUTING.md +5 -0
  3. {python_discovery-1.9.4 → python_discovery-1.9.5}/PKG-INFO +1 -1
  4. {python_discovery-1.9.4 → python_discovery-1.9.5}/docs/changelog.rst +17 -0
  5. {python_discovery-1.9.4 → python_discovery-1.9.5}/src/python_discovery/_discovery.py +3 -2
  6. {python_discovery-1.9.4 → python_discovery-1.9.5}/src/python_discovery/_py_spec.py +17 -14
  7. {python_discovery-1.9.4 → python_discovery-1.9.5}/tests/test_iter_interpreters.py +24 -0
  8. {python_discovery-1.9.4 → python_discovery-1.9.5}/tests/test_py_spec_extra.py +19 -15
  9. {python_discovery-1.9.4 → python_discovery-1.9.5}/.github/FUNDING.yaml +0 -0
  10. {python_discovery-1.9.4 → python_discovery-1.9.5}/.github/SECURITY.md +0 -0
  11. {python_discovery-1.9.4 → python_discovery-1.9.5}/.github/THREAT_MODEL.md +0 -0
  12. {python_discovery-1.9.4 → python_discovery-1.9.5}/.github/dependabot.yaml +0 -0
  13. {python_discovery-1.9.4 → python_discovery-1.9.5}/.github/release.yaml +0 -0
  14. {python_discovery-1.9.4 → python_discovery-1.9.5}/.github/workflows/codeql.yaml +0 -0
  15. {python_discovery-1.9.4 → python_discovery-1.9.5}/.github/workflows/news.yaml +0 -0
  16. {python_discovery-1.9.4 → python_discovery-1.9.5}/.github/workflows/prepare-release.yaml +0 -0
  17. {python_discovery-1.9.4 → python_discovery-1.9.5}/.github/workflows/release.yaml +0 -0
  18. {python_discovery-1.9.4 → python_discovery-1.9.5}/.github/workflows/scorecard.yaml +0 -0
  19. {python_discovery-1.9.4 → python_discovery-1.9.5}/.github/workflows/upgrade-release-tools.yaml +0 -0
  20. {python_discovery-1.9.4 → python_discovery-1.9.5}/.gitignore +0 -0
  21. {python_discovery-1.9.4 → python_discovery-1.9.5}/.pre-commit-config.yaml +0 -0
  22. {python_discovery-1.9.4 → python_discovery-1.9.5}/.readthedocs.yaml +0 -0
  23. {python_discovery-1.9.4 → python_discovery-1.9.5}/.readthedocs.yml +0 -0
  24. {python_discovery-1.9.4 → python_discovery-1.9.5}/CODE_OF_CONDUCT.md +0 -0
  25. {python_discovery-1.9.4 → python_discovery-1.9.5}/LICENSE +0 -0
  26. {python_discovery-1.9.4 → python_discovery-1.9.5}/README.md +0 -0
  27. {python_discovery-1.9.4 → python_discovery-1.9.5}/docs/_static/custom.css +0 -0
  28. {python_discovery-1.9.4 → python_discovery-1.9.5}/docs/_static/github.svg +0 -0
  29. {python_discovery-1.9.4 → python_discovery-1.9.5}/docs/_static/logo.svg +0 -0
  30. {python_discovery-1.9.4 → python_discovery-1.9.5}/docs/changelog/template.jinja2 +0 -0
  31. {python_discovery-1.9.4 → python_discovery-1.9.5}/docs/conf.py +0 -0
  32. {python_discovery-1.9.4 → python_discovery-1.9.5}/docs/contributing.rst +0 -0
  33. {python_discovery-1.9.4 → python_discovery-1.9.5}/docs/explanation.rst +0 -0
  34. {python_discovery-1.9.4 → python_discovery-1.9.5}/docs/how-to/standalone-usage.rst +0 -0
  35. {python_discovery-1.9.4 → python_discovery-1.9.5}/docs/index.rst +0 -0
  36. {python_discovery-1.9.4 → python_discovery-1.9.5}/docs/reference/api.rst +0 -0
  37. {python_discovery-1.9.4 → python_discovery-1.9.5}/docs/reference/environment-variables.rst +0 -0
  38. {python_discovery-1.9.4 → python_discovery-1.9.5}/docs/tutorial/getting-started.rst +0 -0
  39. {python_discovery-1.9.4 → python_discovery-1.9.5}/pylock.toml +0 -0
  40. {python_discovery-1.9.4 → python_discovery-1.9.5}/pyproject.toml +0 -0
  41. {python_discovery-1.9.4 → python_discovery-1.9.5}/src/python_discovery/__init__.py +0 -0
  42. {python_discovery-1.9.4 → python_discovery-1.9.5}/src/python_discovery/_cache.py +0 -0
  43. {python_discovery-1.9.4 → python_discovery-1.9.5}/src/python_discovery/_cached_py_info.py +0 -0
  44. {python_discovery-1.9.4 → python_discovery-1.9.5}/src/python_discovery/_compat.py +0 -0
  45. {python_discovery-1.9.4 → python_discovery-1.9.5}/src/python_discovery/_py_info.py +0 -0
  46. {python_discovery-1.9.4 → python_discovery-1.9.5}/src/python_discovery/_py_info_collect.py +0 -0
  47. {python_discovery-1.9.4 → python_discovery-1.9.5}/src/python_discovery/_specifier.py +0 -0
  48. {python_discovery-1.9.4 → python_discovery-1.9.5}/src/python_discovery/_windows/__init__.py +0 -0
  49. {python_discovery-1.9.4 → python_discovery-1.9.5}/src/python_discovery/_windows/_cancel_io.py +0 -0
  50. {python_discovery-1.9.4 → python_discovery-1.9.5}/src/python_discovery/_windows/_pep514.py +0 -0
  51. {python_discovery-1.9.4 → python_discovery-1.9.5}/src/python_discovery/_windows/_propose.py +0 -0
  52. {python_discovery-1.9.4 → python_discovery-1.9.5}/src/python_discovery/py.typed +0 -0
  53. {python_discovery-1.9.4 → python_discovery-1.9.5}/tasks/old_target_check.py +0 -0
  54. {python_discovery-1.9.4 → python_discovery-1.9.5}/tasks/old_target_check.sh +0 -0
  55. {python_discovery-1.9.4 → python_discovery-1.9.5}/tests/conftest.py +0 -0
  56. {python_discovery-1.9.4 → python_discovery-1.9.5}/tests/py_info/test_py_info.py +0 -0
  57. {python_discovery-1.9.4 → python_discovery-1.9.5}/tests/py_info/test_py_info_exe_based_of.py +0 -0
  58. {python_discovery-1.9.4 → python_discovery-1.9.5}/tests/test_cache.py +0 -0
  59. {python_discovery-1.9.4 → python_discovery-1.9.5}/tests/test_cache_recovery.py +0 -0
  60. {python_discovery-1.9.4 → python_discovery-1.9.5}/tests/test_cached_py_info.py +0 -0
  61. {python_discovery-1.9.4 → python_discovery-1.9.5}/tests/test_discovery.py +0 -0
  62. {python_discovery-1.9.4 → python_discovery-1.9.5}/tests/test_discovery_extra.py +0 -0
  63. {python_discovery-1.9.4 → python_discovery-1.9.5}/tests/test_py_info_collect.py +0 -0
  64. {python_discovery-1.9.4 → python_discovery-1.9.5}/tests/test_py_info_extra.py +0 -0
  65. {python_discovery-1.9.4 → python_discovery-1.9.5}/tests/test_py_spec.py +0 -0
  66. {python_discovery-1.9.4 → python_discovery-1.9.5}/tests/test_query_timeout.py +0 -0
  67. {python_discovery-1.9.4 → python_discovery-1.9.5}/tests/test_specifier.py +0 -0
  68. {python_discovery-1.9.4 → python_discovery-1.9.5}/tests/windows/conftest.py +0 -0
  69. {python_discovery-1.9.4 → python_discovery-1.9.5}/tests/windows/test_windows.py +0 -0
  70. {python_discovery-1.9.4 → python_discovery-1.9.5}/tests/windows/test_windows_pep514.py +0 -0
  71. {python_discovery-1.9.4 → python_discovery-1.9.5}/tests/windows/winreg_mock_values.py +0 -0
  72. {python_discovery-1.9.4 → python_discovery-1.9.5}/tox.toml +0 -0
@@ -7,7 +7,7 @@ on:
7
7
  pull_request:
8
8
  types: [opened, synchronize, reopened]
9
9
  schedule:
10
- - cron: "0 8 * * *"
10
+ - cron: "47 8 * * *"
11
11
  concurrency:
12
12
  group: check-${{ github.ref }}
13
13
  cancel-in-progress: true
@@ -0,0 +1,5 @@
1
+ # Contributing
2
+
3
+ ## Tests
4
+
5
+ Add a test for every new feature and bug fix. A change without a test needs a reason in the pull request description.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: python-discovery
3
- Version: 1.9.4
3
+ Version: 1.9.5
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,23 @@
6
6
 
7
7
  .. towncrier release notes start
8
8
 
9
+ .. _release-1-9-5:
10
+
11
+ *********************
12
+ v1.9.5 (2026-11-06)
13
+ *********************
14
+
15
+ .. _release-1-9-5-fixed:
16
+
17
+ Fixed
18
+ -----
19
+
20
+ - :func:`~python_discovery.iter_interpreters` with no key no longer probes ``PATH`` directories or subdirectories named
21
+ like Python executables as interpreters (:pr:`247`) by :user:`qodelicious` and :user:`gaborbernat`.
22
+ - ``PythonSpec.satisfies`` now checks a version specifier at the precision it was written with, so ``3.11`` no longer
23
+ satisfies ``>=3.13``. The Windows registry pre-filter skips mismatched releases and interrogates candidates whose
24
+ prerelease status is unknown (:pr:`246`) by :user:`qodelicious` and :user:`gaborbernat`.
25
+
9
26
  .. _release-1-9-4:
10
27
 
11
28
  *********************
@@ -496,12 +496,13 @@ def path_exe_finder(
496
496
  direct = f"{direct}.exe"
497
497
 
498
498
  def path_exes(path: Path) -> Generator[tuple[Path, bool], None, None]:
499
+ # an empty spec (enumerating everything) would make the direct path the PATH directory itself
499
500
  direct_path = path / direct
500
- if direct_path.exists():
501
+ if direct_path.is_file():
501
502
  yield direct_path, impl_must_match
502
503
 
503
504
  for exe in path.iterdir():
504
- if match := pat.fullmatch(exe.name):
505
+ if (match := pat.fullmatch(exe.name)) and exe.is_file():
505
506
  yield exe.absolute(), impl_must_match or match["impl"].lower() == "python"
506
507
 
507
508
  return path_exes
@@ -2,7 +2,6 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
- import contextlib
6
5
  import pathlib
7
6
  import re
8
7
  from typing import Final
@@ -235,27 +234,31 @@ class PythonSpec:
235
234
  if not components:
236
235
  return True
237
236
 
238
- version_str = ".".join(str(part) for part in components)
239
237
  if spec.version_specifier is None:
240
238
  return True
241
- with contextlib.suppress(InvalidVersion):
242
- Version.from_string(version_str)
243
- for item in spec.version_specifier:
244
- required_precision = self._get_required_precision(item)
245
- if required_precision is None or len(components) < required_precision:
246
- continue
247
- if not item.contains(version_str):
248
- return False
239
+ for item in spec.version_specifier:
240
+ required_precision = self._get_required_precision(item)
241
+ if required_precision is None or len(components) < required_precision:
242
+ continue
243
+ # Registry versions omit prerelease status, so a matching release still needs interrogation.
244
+ if (
245
+ (version := item.version) is not None
246
+ and version.pre_type is not None
247
+ and tuple(components[:required_precision]) == version.release[:required_precision]
248
+ ):
249
+ continue
250
+ # compare at the precision the specifier was written with, as PythonInfo.satisfies does
251
+ if not item.contains(".".join(str(part) for part in components[:required_precision])):
252
+ return False
249
253
  return True
250
254
 
251
255
  @staticmethod
252
256
  def _get_required_precision(item: SimpleSpecifier) -> int | None:
253
- """Get the required precision for a specifier item."""
254
257
  if item.version is None:
255
258
  return None
256
- with contextlib.suppress(AttributeError, ValueError):
257
- return len(item.version.release)
258
- return None
259
+ if item.wildcard_precision is not None:
260
+ return item.wildcard_precision
261
+ return re.split(r"a|b|rc", item.version_str, maxsplit=1)[0].count(".") + 1
259
262
 
260
263
  def satisfies(self, spec: PythonSpec) -> bool: # ruff:ignore[too-many-return-statements]
261
264
  """
@@ -144,6 +144,30 @@ def test_iter_interpreters_no_key_probes_variant_builds_on_path(
144
144
  assert str(exe) in [call.args[0] for call in from_exe.call_args_list]
145
145
 
146
146
 
147
+ @pytest.mark.usefixtures("uv_dir")
148
+ @pytest.mark.parametrize(
149
+ "directory_name",
150
+ [
151
+ pytest.param(".", id="path-directory"),
152
+ pytest.param(f"python3.99{'.exe' if IS_WIN else ''}", id="named-directory"),
153
+ ],
154
+ )
155
+ def test_iter_interpreters_skips_path_directories(
156
+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch, mocker: MockerFixture, directory_name: str
157
+ ) -> None:
158
+ bin_dir = tmp_path / "bin"
159
+ bin_dir.mkdir()
160
+ (bin_dir / directory_name).mkdir(exist_ok=True)
161
+ executable = bin_dir / f"python3.98{'.exe' if IS_WIN else ''}"
162
+ executable.touch()
163
+ monkeypatch.setenv("PATH", str(bin_dir))
164
+ from_exe = mocker.patch("python_discovery._discovery.PathPythonInfo.from_exe", return_value=None)
165
+
166
+ list(iter_interpreters())
167
+
168
+ assert [call.args[0] for call in from_exe.call_args_list] == [str(executable)]
169
+
170
+
147
171
  @pytest.mark.usefixtures("uv_dir")
148
172
  def test_iter_interpreters_dedups_symlinks(
149
173
  tmp_path: Path,
@@ -1,7 +1,5 @@
1
1
  from __future__ import annotations
2
2
 
3
- from unittest.mock import MagicMock
4
-
5
3
  import pytest
6
4
 
7
5
  from python_discovery import PythonSpec
@@ -165,16 +163,22 @@ def test_specifier_set_parsed_for_valid_format() -> None:
165
163
  assert spec.implementation == "cpython"
166
164
 
167
165
 
168
- def test_get_required_precision_attribute_error() -> None:
169
- from python_discovery._specifier import SimpleSpecifier
170
-
171
- mock_version = MagicMock(spec=[])
172
- specifier = SimpleSpecifier(
173
- spec_str=">=3.12",
174
- operator=">=",
175
- version_str="3.12",
176
- is_wildcard=False,
177
- wildcard_precision=None,
178
- version=mock_version,
179
- )
180
- assert PythonSpec._get_required_precision(specifier) is None
166
+ @pytest.mark.parametrize(
167
+ ("candidate", "text", "expected"),
168
+ [
169
+ pytest.param("3.11", ">=3.13", False, id="minor-too-old"),
170
+ pytest.param("3.14", "<3.13", False, id="minor-too-new"),
171
+ pytest.param("3.11", "==3.12.*", False, id="minor-wildcard-miss"),
172
+ pytest.param("3.12", "==3.12.*", True, id="minor-wildcard-hit"),
173
+ pytest.param("3.13", ">=3.12,<3.14", True, id="minor-in-range"),
174
+ pytest.param("3", ">=4", False, id="major-too-old"),
175
+ pytest.param("3.12", ">=3.12.5", True, id="micro-unknown"),
176
+ pytest.param("3.12.1", "==3.12", True, id="micro-at-minor-precision"),
177
+ pytest.param("3.14", "==3.14rc1", True, id="prerelease-unknown"),
178
+ pytest.param("3.14", "<=3.14rc1", True, id="prerelease-upper-bound-unknown"),
179
+ pytest.param("3.14.0", "==3.14.0rc1", True, id="prerelease-unknown-at-micro-precision"),
180
+ pytest.param("3.13", ">=3.14rc1", False, id="earlier-release-still-filtered"),
181
+ ],
182
+ )
183
+ def test_version_specifier_compared_at_written_precision(candidate: str, text: str, expected: bool) -> None:
184
+ assert PythonSpec.from_string_spec(candidate).satisfies(PythonSpec.from_string_spec(text)) is expected