python-discovery 1.7.0__tar.gz → 1.8.0__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.7.0 → python_discovery-1.8.0}/PKG-INFO +1 -1
  2. {python_discovery-1.7.0 → python_discovery-1.8.0}/docs/changelog.rst +14 -0
  3. {python_discovery-1.7.0 → python_discovery-1.8.0}/docs/how-to/standalone-usage.rst +5 -0
  4. {python_discovery-1.7.0 → python_discovery-1.8.0}/pyproject.toml +1 -0
  5. {python_discovery-1.7.0 → python_discovery-1.8.0}/src/python_discovery/_py_info.py +1 -0
  6. {python_discovery-1.7.0 → python_discovery-1.8.0}/src/python_discovery/_py_info_collect.py +24 -0
  7. {python_discovery-1.7.0 → python_discovery-1.8.0}/tests/py_info/test_py_info.py +44 -1
  8. {python_discovery-1.7.0 → python_discovery-1.8.0}/.github/FUNDING.yaml +0 -0
  9. {python_discovery-1.7.0 → python_discovery-1.8.0}/.github/SECURITY.md +0 -0
  10. {python_discovery-1.7.0 → python_discovery-1.8.0}/.github/THREAT_MODEL.md +0 -0
  11. {python_discovery-1.7.0 → python_discovery-1.8.0}/.github/dependabot.yaml +0 -0
  12. {python_discovery-1.7.0 → python_discovery-1.8.0}/.github/release.yaml +0 -0
  13. {python_discovery-1.7.0 → python_discovery-1.8.0}/.github/workflows/check.yaml +0 -0
  14. {python_discovery-1.7.0 → python_discovery-1.8.0}/.github/workflows/codeql.yaml +0 -0
  15. {python_discovery-1.7.0 → python_discovery-1.8.0}/.github/workflows/news.yaml +0 -0
  16. {python_discovery-1.7.0 → python_discovery-1.8.0}/.github/workflows/prepare-release.yaml +0 -0
  17. {python_discovery-1.7.0 → python_discovery-1.8.0}/.github/workflows/release.yaml +0 -0
  18. {python_discovery-1.7.0 → python_discovery-1.8.0}/.github/workflows/upgrade-release-tools.yaml +0 -0
  19. {python_discovery-1.7.0 → python_discovery-1.8.0}/.gitignore +0 -0
  20. {python_discovery-1.7.0 → python_discovery-1.8.0}/.pre-commit-config.yaml +0 -0
  21. {python_discovery-1.7.0 → python_discovery-1.8.0}/.readthedocs.yaml +0 -0
  22. {python_discovery-1.7.0 → python_discovery-1.8.0}/.readthedocs.yml +0 -0
  23. {python_discovery-1.7.0 → python_discovery-1.8.0}/CODE_OF_CONDUCT.md +0 -0
  24. {python_discovery-1.7.0 → python_discovery-1.8.0}/LICENSE +0 -0
  25. {python_discovery-1.7.0 → python_discovery-1.8.0}/README.md +0 -0
  26. {python_discovery-1.7.0 → python_discovery-1.8.0}/docs/_static/custom.css +0 -0
  27. {python_discovery-1.7.0 → python_discovery-1.8.0}/docs/_static/github.svg +0 -0
  28. {python_discovery-1.7.0 → python_discovery-1.8.0}/docs/_static/logo.svg +0 -0
  29. {python_discovery-1.7.0 → python_discovery-1.8.0}/docs/changelog/template.jinja2 +0 -0
  30. {python_discovery-1.7.0 → python_discovery-1.8.0}/docs/conf.py +0 -0
  31. {python_discovery-1.7.0 → python_discovery-1.8.0}/docs/contributing.rst +0 -0
  32. {python_discovery-1.7.0 → python_discovery-1.8.0}/docs/explanation.rst +0 -0
  33. {python_discovery-1.7.0 → python_discovery-1.8.0}/docs/index.rst +0 -0
  34. {python_discovery-1.7.0 → python_discovery-1.8.0}/docs/reference/api.rst +0 -0
  35. {python_discovery-1.7.0 → python_discovery-1.8.0}/docs/reference/environment-variables.rst +0 -0
  36. {python_discovery-1.7.0 → python_discovery-1.8.0}/docs/tutorial/getting-started.rst +0 -0
  37. {python_discovery-1.7.0 → python_discovery-1.8.0}/pylock.toml +0 -0
  38. {python_discovery-1.7.0 → python_discovery-1.8.0}/src/python_discovery/__init__.py +0 -0
  39. {python_discovery-1.7.0 → python_discovery-1.8.0}/src/python_discovery/_cache.py +0 -0
  40. {python_discovery-1.7.0 → python_discovery-1.8.0}/src/python_discovery/_cached_py_info.py +0 -0
  41. {python_discovery-1.7.0 → python_discovery-1.8.0}/src/python_discovery/_compat.py +0 -0
  42. {python_discovery-1.7.0 → python_discovery-1.8.0}/src/python_discovery/_discovery.py +0 -0
  43. {python_discovery-1.7.0 → python_discovery-1.8.0}/src/python_discovery/_py_spec.py +0 -0
  44. {python_discovery-1.7.0 → python_discovery-1.8.0}/src/python_discovery/_specifier.py +0 -0
  45. {python_discovery-1.7.0 → python_discovery-1.8.0}/src/python_discovery/_windows/__init__.py +0 -0
  46. {python_discovery-1.7.0 → python_discovery-1.8.0}/src/python_discovery/_windows/_pep514.py +0 -0
  47. {python_discovery-1.7.0 → python_discovery-1.8.0}/src/python_discovery/_windows/_propose.py +0 -0
  48. {python_discovery-1.7.0 → python_discovery-1.8.0}/src/python_discovery/py.typed +0 -0
  49. {python_discovery-1.7.0 → python_discovery-1.8.0}/tasks/old_target_check.py +0 -0
  50. {python_discovery-1.7.0 → python_discovery-1.8.0}/tasks/old_target_check.sh +0 -0
  51. {python_discovery-1.7.0 → python_discovery-1.8.0}/tests/conftest.py +0 -0
  52. {python_discovery-1.7.0 → python_discovery-1.8.0}/tests/py_info/test_py_info_exe_based_of.py +0 -0
  53. {python_discovery-1.7.0 → python_discovery-1.8.0}/tests/test_cache.py +0 -0
  54. {python_discovery-1.7.0 → python_discovery-1.8.0}/tests/test_cache_recovery.py +0 -0
  55. {python_discovery-1.7.0 → python_discovery-1.8.0}/tests/test_cached_py_info.py +0 -0
  56. {python_discovery-1.7.0 → python_discovery-1.8.0}/tests/test_discovery.py +0 -0
  57. {python_discovery-1.7.0 → python_discovery-1.8.0}/tests/test_discovery_extra.py +0 -0
  58. {python_discovery-1.7.0 → python_discovery-1.8.0}/tests/test_iter_interpreters.py +0 -0
  59. {python_discovery-1.7.0 → python_discovery-1.8.0}/tests/test_py_info_collect.py +0 -0
  60. {python_discovery-1.7.0 → python_discovery-1.8.0}/tests/test_py_info_extra.py +0 -0
  61. {python_discovery-1.7.0 → python_discovery-1.8.0}/tests/test_py_spec.py +0 -0
  62. {python_discovery-1.7.0 → python_discovery-1.8.0}/tests/test_py_spec_extra.py +0 -0
  63. {python_discovery-1.7.0 → python_discovery-1.8.0}/tests/test_query_timeout.py +0 -0
  64. {python_discovery-1.7.0 → python_discovery-1.8.0}/tests/test_specifier.py +0 -0
  65. {python_discovery-1.7.0 → python_discovery-1.8.0}/tests/windows/conftest.py +0 -0
  66. {python_discovery-1.7.0 → python_discovery-1.8.0}/tests/windows/test_windows.py +0 -0
  67. {python_discovery-1.7.0 → python_discovery-1.8.0}/tests/windows/test_windows_pep514.py +0 -0
  68. {python_discovery-1.7.0 → python_discovery-1.8.0}/tests/windows/winreg_mock_values.py +0 -0
  69. {python_discovery-1.7.0 → python_discovery-1.8.0}/tox.toml +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: python-discovery
3
- Version: 1.7.0
3
+ Version: 1.8.0
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,20 @@
6
6
 
7
7
  .. towncrier release notes start
8
8
 
9
+ .. _release-1-8-0:
10
+
11
+ *********************
12
+ v1.8.0 (2026-10-30)
13
+ *********************
14
+
15
+ .. _release-1-8-0-added:
16
+
17
+ Added
18
+ -----
19
+
20
+ - Expose the selected interpreter's dependency marker values as ``PythonInfo.marker_environment`` (:pr:`178`) by
21
+ :user:`gaborbernat`.
22
+
9
23
  .. _release-1-7-0:
10
24
 
11
25
  *********************
@@ -153,6 +153,7 @@ Once you have a :class:`~python_discovery.PythonInfo`, you can inspect everythin
153
153
  +platform: str
154
154
  +sysconfig_vars: dict
155
155
  +sysconfig_paths: dict
156
+ +marker_environment: dict[str, str]
156
157
  +machine: str
157
158
  +free_threaded: bool
158
159
  +debug_build: bool
@@ -178,6 +179,10 @@ Once you have a :class:`~python_discovery.PythonInfo`, you can inspect everythin
178
179
  info.debug_build # True if this is a Py_DEBUG build.
179
180
  info.sysconfig_vars # All sysconfig.get_config_vars() values.
180
181
  info.sysconfig_paths # All sysconfig.get_paths() values.
182
+ info.marker_environment
183
+
184
+ Use ``marker_environment`` to evaluate :pep:`508` dependency markers for the discovered interpreter. The mapping
185
+ contains all standard marker keys, including its implementation version and operating system.
181
186
 
182
187
  Prefer :attr:`~python_discovery.PythonInfo.system_exe` over the raw
183
188
  :attr:`~python_discovery.PythonInfo.system_executable` field it reads. The field is typed ``str | None`` because it
@@ -57,6 +57,7 @@ urls.Tracker = "https://github.com/tox-dev/python-discovery/issues"
57
57
  test = [
58
58
  "covdefaults>=2.3",
59
59
  "coverage>=7.6.1",
60
+ "packaging>=23.2",
60
61
  "pytest>=8.3.5",
61
62
  "pytest-mock>=3.14.1",
62
63
  "setuptools>=75.3.4",
@@ -57,6 +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
61
  prefix: str | None
61
62
  base_prefix: str | None
62
63
  real_prefix: str | None
@@ -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):
@@ -9,9 +9,10 @@ import sys
9
9
  import sysconfig
10
10
  from pathlib import Path
11
11
  from textwrap import dedent
12
- from typing import TYPE_CHECKING, NamedTuple
12
+ from typing import TYPE_CHECKING, Final, NamedTuple
13
13
 
14
14
  import pytest
15
+ from packaging.markers import default_environment
15
16
  from setuptools.dist import Distribution
16
17
 
17
18
  from python_discovery import DiskCache, PythonInfo, PythonSpec
@@ -19,6 +20,7 @@ from python_discovery import _cached_py_info as cached_py_info
19
20
  from python_discovery._py_info import VersionInfo
20
21
 
21
22
  if TYPE_CHECKING:
23
+ from packaging.markers import Environment
22
24
  from pytest_mock import MockerFixture
23
25
 
24
26
  IS_PYPY = PythonInfo.current_system().implementation == "PyPy"
@@ -492,6 +494,47 @@ def test_py_info_json_round_trip() -> None:
492
494
  assert restored.machine == CURRENT.machine
493
495
 
494
496
 
497
+ def test_marker_environment_matches_target_interpreter() -> None:
498
+ info: Final[PythonInfo | None] = PythonInfo.from_exe(sys.executable, ignore_cache=True, resolve_to_host=False)
499
+ assert info is not None
500
+ assert info.marker_environment == default_environment()
501
+
502
+
503
+ def test_marker_environment_uses_target_platform(tmp_path: Path) -> None:
504
+ (tmp_path / "sitecustomize.py").write_text(
505
+ 'import platform\nplatform.machine = lambda: "target-machine"\nplatform.release = lambda: "target-release"\n',
506
+ encoding="utf-8",
507
+ )
508
+ expected: Final[Environment] = default_environment()
509
+ assert expected["platform_machine"] != "target-machine"
510
+ assert expected["platform_release"] != "target-release"
511
+ info: Final[PythonInfo | None] = PythonInfo.from_exe(
512
+ sys.executable,
513
+ ignore_cache=True,
514
+ resolve_to_host=False,
515
+ env={**os.environ, "PYTHONPATH": str(tmp_path)},
516
+ )
517
+ assert info is not None
518
+ assert info.marker_environment == {
519
+ **expected,
520
+ "platform_machine": "target-machine",
521
+ "platform_release": "target-release",
522
+ }
523
+
524
+
525
+ def test_marker_environment_survives_json_round_trip() -> None:
526
+ assert PythonInfo.from_json(CURRENT.to_json()).marker_environment == CURRENT.marker_environment
527
+
528
+
529
+ def test_marker_environment_formats_prerelease(mocker: MockerFixture) -> None:
530
+ version: Final[VersionInfo] = VersionInfo(*sys.implementation.version)
531
+ mocker.patch.object(sys.implementation, "version", version._replace(releaselevel="candidate", serial=1))
532
+
533
+ assert PythonInfo().marker_environment["implementation_version"] == (
534
+ f"{version.major}.{version.minor}.{version.micro}c1"
535
+ )
536
+
537
+
495
538
  @pytest.mark.parametrize(
496
539
  ("target_platform", "discovered_platforms", "expected_idx"),
497
540
  [