python-discovery 1.6.7__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.
- python_discovery-1.8.0/.github/SECURITY.md +56 -0
- python_discovery-1.8.0/.github/THREAT_MODEL.md +106 -0
- {python_discovery-1.6.7 → python_discovery-1.8.0}/PKG-INFO +1 -1
- python_discovery-1.8.0/docs/_static/github.svg +1 -0
- {python_discovery-1.6.7 → python_discovery-1.8.0}/docs/changelog.rst +47 -0
- {python_discovery-1.6.7 → python_discovery-1.8.0}/docs/conf.py +16 -3
- {python_discovery-1.6.7 → python_discovery-1.8.0}/docs/explanation.rst +12 -3
- {python_discovery-1.6.7 → python_discovery-1.8.0}/docs/how-to/standalone-usage.rst +5 -0
- {python_discovery-1.6.7 → python_discovery-1.8.0}/pyproject.toml +1 -0
- {python_discovery-1.6.7 → python_discovery-1.8.0}/src/python_discovery/_discovery.py +14 -5
- {python_discovery-1.6.7 → python_discovery-1.8.0}/src/python_discovery/_py_info.py +1 -0
- {python_discovery-1.6.7 → python_discovery-1.8.0}/src/python_discovery/_py_info_collect.py +24 -0
- {python_discovery-1.6.7 → python_discovery-1.8.0}/src/python_discovery/_py_spec.py +52 -39
- {python_discovery-1.6.7 → python_discovery-1.8.0}/tests/py_info/test_py_info.py +44 -1
- {python_discovery-1.6.7 → python_discovery-1.8.0}/tests/test_discovery.py +66 -1
- {python_discovery-1.6.7 → python_discovery-1.8.0}/tests/test_py_info_extra.py +12 -0
- {python_discovery-1.6.7 → python_discovery-1.8.0}/tests/test_py_spec.py +44 -9
- {python_discovery-1.6.7 → python_discovery-1.8.0}/tests/test_py_spec_extra.py +0 -5
- python_discovery-1.6.7/.github/SECURITY.md +0 -9
- {python_discovery-1.6.7 → python_discovery-1.8.0}/.github/FUNDING.yaml +0 -0
- {python_discovery-1.6.7 → python_discovery-1.8.0}/.github/dependabot.yaml +0 -0
- {python_discovery-1.6.7 → python_discovery-1.8.0}/.github/release.yaml +0 -0
- {python_discovery-1.6.7 → python_discovery-1.8.0}/.github/workflows/check.yaml +0 -0
- {python_discovery-1.6.7 → python_discovery-1.8.0}/.github/workflows/codeql.yaml +0 -0
- {python_discovery-1.6.7 → python_discovery-1.8.0}/.github/workflows/news.yaml +0 -0
- {python_discovery-1.6.7 → python_discovery-1.8.0}/.github/workflows/prepare-release.yaml +0 -0
- {python_discovery-1.6.7 → python_discovery-1.8.0}/.github/workflows/release.yaml +0 -0
- {python_discovery-1.6.7 → python_discovery-1.8.0}/.github/workflows/upgrade-release-tools.yaml +0 -0
- {python_discovery-1.6.7 → python_discovery-1.8.0}/.gitignore +0 -0
- {python_discovery-1.6.7 → python_discovery-1.8.0}/.pre-commit-config.yaml +0 -0
- {python_discovery-1.6.7 → python_discovery-1.8.0}/.readthedocs.yaml +0 -0
- {python_discovery-1.6.7 → python_discovery-1.8.0}/.readthedocs.yml +0 -0
- {python_discovery-1.6.7 → python_discovery-1.8.0}/CODE_OF_CONDUCT.md +0 -0
- {python_discovery-1.6.7 → python_discovery-1.8.0}/LICENSE +0 -0
- {python_discovery-1.6.7 → python_discovery-1.8.0}/README.md +0 -0
- {python_discovery-1.6.7 → python_discovery-1.8.0}/docs/_static/custom.css +0 -0
- {python_discovery-1.6.7 → python_discovery-1.8.0}/docs/_static/logo.svg +0 -0
- {python_discovery-1.6.7 → python_discovery-1.8.0}/docs/changelog/template.jinja2 +0 -0
- {python_discovery-1.6.7 → python_discovery-1.8.0}/docs/contributing.rst +0 -0
- {python_discovery-1.6.7 → python_discovery-1.8.0}/docs/index.rst +0 -0
- {python_discovery-1.6.7 → python_discovery-1.8.0}/docs/reference/api.rst +0 -0
- {python_discovery-1.6.7 → python_discovery-1.8.0}/docs/reference/environment-variables.rst +0 -0
- {python_discovery-1.6.7 → python_discovery-1.8.0}/docs/tutorial/getting-started.rst +0 -0
- {python_discovery-1.6.7 → python_discovery-1.8.0}/pylock.toml +0 -0
- {python_discovery-1.6.7 → python_discovery-1.8.0}/src/python_discovery/__init__.py +0 -0
- {python_discovery-1.6.7 → python_discovery-1.8.0}/src/python_discovery/_cache.py +0 -0
- {python_discovery-1.6.7 → python_discovery-1.8.0}/src/python_discovery/_cached_py_info.py +0 -0
- {python_discovery-1.6.7 → python_discovery-1.8.0}/src/python_discovery/_compat.py +0 -0
- {python_discovery-1.6.7 → python_discovery-1.8.0}/src/python_discovery/_specifier.py +0 -0
- {python_discovery-1.6.7 → python_discovery-1.8.0}/src/python_discovery/_windows/__init__.py +0 -0
- {python_discovery-1.6.7 → python_discovery-1.8.0}/src/python_discovery/_windows/_pep514.py +0 -0
- {python_discovery-1.6.7 → python_discovery-1.8.0}/src/python_discovery/_windows/_propose.py +0 -0
- {python_discovery-1.6.7 → python_discovery-1.8.0}/src/python_discovery/py.typed +0 -0
- {python_discovery-1.6.7 → python_discovery-1.8.0}/tasks/old_target_check.py +0 -0
- {python_discovery-1.6.7 → python_discovery-1.8.0}/tasks/old_target_check.sh +0 -0
- {python_discovery-1.6.7 → python_discovery-1.8.0}/tests/conftest.py +0 -0
- {python_discovery-1.6.7 → python_discovery-1.8.0}/tests/py_info/test_py_info_exe_based_of.py +0 -0
- {python_discovery-1.6.7 → python_discovery-1.8.0}/tests/test_cache.py +0 -0
- {python_discovery-1.6.7 → python_discovery-1.8.0}/tests/test_cache_recovery.py +0 -0
- {python_discovery-1.6.7 → python_discovery-1.8.0}/tests/test_cached_py_info.py +0 -0
- {python_discovery-1.6.7 → python_discovery-1.8.0}/tests/test_discovery_extra.py +0 -0
- {python_discovery-1.6.7 → python_discovery-1.8.0}/tests/test_iter_interpreters.py +0 -0
- {python_discovery-1.6.7 → python_discovery-1.8.0}/tests/test_py_info_collect.py +0 -0
- {python_discovery-1.6.7 → python_discovery-1.8.0}/tests/test_query_timeout.py +0 -0
- {python_discovery-1.6.7 → python_discovery-1.8.0}/tests/test_specifier.py +0 -0
- {python_discovery-1.6.7 → python_discovery-1.8.0}/tests/windows/conftest.py +0 -0
- {python_discovery-1.6.7 → python_discovery-1.8.0}/tests/windows/test_windows.py +0 -0
- {python_discovery-1.6.7 → python_discovery-1.8.0}/tests/windows/test_windows_pep514.py +0 -0
- {python_discovery-1.6.7 → python_discovery-1.8.0}/tests/windows/winreg_mock_values.py +0 -0
- {python_discovery-1.6.7 → python_discovery-1.8.0}/tox.toml +0 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# Security policy
|
|
2
|
+
|
|
3
|
+
python-discovery is a Python library that finds Python interpreters on a machine and reports their metadata. This policy
|
|
4
|
+
says how to report a security problem and how we decide whether a report is one.
|
|
5
|
+
|
|
6
|
+
## Reporting a vulnerability
|
|
7
|
+
|
|
8
|
+
**Do not open a public issue for a security problem.** Use
|
|
9
|
+
[GitHub's private vulnerability reporting](https://github.com/tox-dev/python-discovery/security/advisories/new). If
|
|
10
|
+
neither works for you, email [gaborjbernat@gmail.com](mailto:gaborjbernat@gmail.com).
|
|
11
|
+
|
|
12
|
+
Include what the attacker controls and what they gain, the steps or a proof of concept, and the versions and platform
|
|
13
|
+
you tested. Write the report yourself; unreviewed tool or model output takes longer to triage.
|
|
14
|
+
|
|
15
|
+
## What to expect
|
|
16
|
+
|
|
17
|
+
Volunteers maintain python-discovery, with no on-call rotation. We aim to acknowledge a report within **5 working days**
|
|
18
|
+
and assess it within **15 working days**. Fixes are developed in a private fork attached to the draft advisory, ship in
|
|
19
|
+
a new release, and the advisory, with a CVE requested through GitHub, goes out with that release. The default embargo is
|
|
20
|
+
**90 days** from the report; we agree any change with the reporter. We credit reporters in the advisory under the name
|
|
21
|
+
they choose, or not at all. There is no bug bounty.
|
|
22
|
+
|
|
23
|
+
## Supported versions
|
|
24
|
+
|
|
25
|
+
Only the latest release receives fixes. Confirm the problem reproduces on it before reporting.
|
|
26
|
+
|
|
27
|
+
## Vulnerability or bug
|
|
28
|
+
|
|
29
|
+
A report is a vulnerability when an attacker who controls only an input that the [threat model](THREAT_MODEL.md) lists
|
|
30
|
+
as untrusted breaks a guarantee python-discovery makes. A report that first needs control of something the threat model
|
|
31
|
+
trusts, such as an executable on `PATH` or in a version manager's directory, is a bug: we fix it in the open and publish
|
|
32
|
+
no advisory. Classify by who supplies the dangerous input, not by how bad the outcome sounds.
|
|
33
|
+
|
|
34
|
+
**In scope**
|
|
35
|
+
|
|
36
|
+
- Executing a binary from a location the documented search order does not include, such as the current directory through
|
|
37
|
+
an empty `PATH` entry.
|
|
38
|
+
- A cache entry from one interpreter being reported for another, or surviving a change of the binary.
|
|
39
|
+
- Interrogation output from one candidate being parsed as another candidate's metadata.
|
|
40
|
+
- A spec's version, implementation, architecture, free-threading or debug constraint passing for a shim or launcher
|
|
41
|
+
while the interpreter it resolves to fails it.
|
|
42
|
+
- A PEP 514 record or a spec making discovery run a program other than the candidate with its registered arguments.
|
|
43
|
+
- Another local user writing a shared cache directory so a victim accepts an interpreter, or metadata, that discovery
|
|
44
|
+
would otherwise reject.
|
|
45
|
+
- A small candidate response exhausting memory or processes.
|
|
46
|
+
|
|
47
|
+
**Out of scope**
|
|
48
|
+
|
|
49
|
+
- A malicious interpreter in a searched location: python-discovery runs candidates to learn about them, so whoever can
|
|
50
|
+
place one there already runs code as the user.
|
|
51
|
+
- Values in the process environment (`PATH`, `PYENV_ROOT`, `UV_PYTHON_INSTALL_DIR`, `PY_DISCOVERY_TIMEOUT`) and the
|
|
52
|
+
Windows registry entries of PEP 514.
|
|
53
|
+
- A `.python-version` file choosing among interpreters that discovery would find anyway.
|
|
54
|
+
- Tampering with a cache directory only the caller can write.
|
|
55
|
+
|
|
56
|
+
If you cannot tell which side a finding falls on, report it privately and we will decide.
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# Threat model
|
|
2
|
+
|
|
3
|
+
This model says what python-discovery trusts, where untrusted input enters, and which guarantees hold at each boundary,
|
|
4
|
+
so a report can be classified as a vulnerability or a bug. [SECURITY.md](SECURITY.md) covers reporting; if the two
|
|
5
|
+
disagree, SECURITY.md wins and we fix this file.
|
|
6
|
+
|
|
7
|
+
## How python-discovery works
|
|
8
|
+
|
|
9
|
+
A caller passes a requirement such as `python3.12` or `>=3.11,<3.13`. python-discovery walks `try_first_with` paths, the
|
|
10
|
+
running interpreter, the PEP 514 registry on Windows, `PATH` (resolving pyenv, mise and asdf shims to the binary they
|
|
11
|
+
select), and uv's install directories. It runs each candidate with a bundled interrogation script and reads a JSON
|
|
12
|
+
answer framed by two random cookies, then caches that answer in a directory the caller supplies, valid while the
|
|
13
|
+
binary's path and modification time, the script's hash and any PEP 514 arguments stay the same.
|
|
14
|
+
|
|
15
|
+
```mermaid
|
|
16
|
+
flowchart LR
|
|
17
|
+
caller["Caller<br/>spec, env, cache dir (trusted)"] --> pd["python-discovery"]
|
|
18
|
+
pd -->|search| locs[("PATH, version managers,<br/>PEP 514 registry (trusted)")]
|
|
19
|
+
pd -->|"run candidate + script"| py["Candidate interpreter"]
|
|
20
|
+
py -->|"JSON between cookies"| pd
|
|
21
|
+
pd <-->|"checked against path, mtime,<br/>script hash, PEP 514 args"| cache[("Cache dir")]
|
|
22
|
+
classDef trusted fill:#cfe4ff,stroke:#1f6feb,color:#0b1f3a;
|
|
23
|
+
classDef boundary fill:#ffe3a3,stroke:#d29200,color:#3a2c00;
|
|
24
|
+
class caller,pd,locs trusted;
|
|
25
|
+
class py,cache boundary;
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Compared with similar tools
|
|
29
|
+
|
|
30
|
+
We drew the boundary where comparable projects in other ecosystems draw theirs. The shared rule, stated by the
|
|
31
|
+
[Node.js threat model](https://github.com/nodejs/node/blob/main/SECURITY.md#the-nodejs-threat-model), is that a report
|
|
32
|
+
which first needs a trusted element compromised is out of scope; the first triage question, as
|
|
33
|
+
[DOMPurify](https://github.com/cure53/DOMPurify/blob/main/SECURITY.md#what-we-consider-a-vulnerability) puts it, is what
|
|
34
|
+
the attacker controls.
|
|
35
|
+
|
|
36
|
+
| Project | Language | Where it draws the line |
|
|
37
|
+
| ---------------------------------------------------------------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------- |
|
|
38
|
+
| [Go `os/exec` path lookup](https://go.dev/blog/path-security) | Go | Refuses to run a binary found through the current directory; python-discovery skips empty `PATH` entries for the same reason. |
|
|
39
|
+
| [nvm](https://github.com/nvm-sh/nvm/blob/HEAD/.github/THREAT_MODEL.md) | Shell | Trusts what it installs and executes as the user; treats mirror metadata, not payloads, as the untrusted boundary. |
|
|
40
|
+
| [uv](https://github.com/astral-sh/uv/security/policy) | Rust | Its policy says invoking the Python interpreters it finds, to read their metadata, is not a vulnerability. |
|
|
41
|
+
|
|
42
|
+
## Trusted
|
|
43
|
+
|
|
44
|
+
An attacker who controls any of these already has what python-discovery could give them:
|
|
45
|
+
|
|
46
|
+
- The caller and the spec, environment mapping, cache directory and `try_first_with` paths it passes.
|
|
47
|
+
- Every directory searched: `PATH` entries, version-manager roots and install directories, and the PEP 514 registry,
|
|
48
|
+
including `ExecutableArguments`.
|
|
49
|
+
- The interpreters found there; running them is how discovery works.
|
|
50
|
+
- A cache directory that only the caller can write (for example virtualenv's app-data).
|
|
51
|
+
|
|
52
|
+
## Untrusted inputs
|
|
53
|
+
|
|
54
|
+
| Input | Comes from | What python-discovery guarantees |
|
|
55
|
+
| ----------------------------- | --------------------------------------------------- | -------------------------------------------------------------------------------------------------------------- |
|
|
56
|
+
| The current working directory | Wherever the caller happens to run | Empty `PATH` components, which shells read as the current directory, are skipped. |
|
|
57
|
+
| Interrogation stdout | Startup noise or a `sitecustomize` that prints | Only the JSON between two per-run random cookies is parsed; anything else is a failed candidate. |
|
|
58
|
+
| Cache entries | Earlier runs, possibly of another interpreter build | Reused only when the binary's path and modification time, the script hash and the PEP 514 arguments all match. |
|
|
59
|
+
| A shared cache directory | Another local user who can write it | Must not make a victim accept an interpreter or metadata that discovery would reject; report any way it does. |
|
|
60
|
+
|
|
61
|
+
## Threats and controls
|
|
62
|
+
|
|
63
|
+
| STRIDE | Threat | Control |
|
|
64
|
+
| ---------------------- | ----------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- |
|
|
65
|
+
| Spoofing | Output printed by a candidate's startup code impersonates its metadata. | Random start and end cookies frame the answer. |
|
|
66
|
+
| Tampering | A stale cache entry describes a binary that has since been replaced. | The entry records the binary's modification time, the script's hash and the PEP 514 arguments. |
|
|
67
|
+
| Denial of service | A candidate hangs during interrogation. | The interrogation has a timeout, configurable with `PY_DISCOVERY_TIMEOUT`. |
|
|
68
|
+
| Elevation of privilege | A binary in the current directory is picked up through `PATH`. | Empty `PATH` entries are skipped. |
|
|
69
|
+
|
|
70
|
+
## Release chain
|
|
71
|
+
|
|
72
|
+
Releases run on the shared [tox-dev/github-workflows](https://github.com/tox-dev/github-workflows) pipeline. A release
|
|
73
|
+
App, not a person, pushes the release commit and tag; the build installs its tools from a hash-checked `pylock.toml`
|
|
74
|
+
resolved with a seven-day upload cooldown by default; PyPI receives the files through
|
|
75
|
+
[trusted publishing](https://docs.pypi.org/trusted-publishers/) with attestations, and the GitHub Release is immutable.
|
|
76
|
+
Every workflow pins third-party actions to a commit SHA.
|
|
77
|
+
|
|
78
|
+
## Vulnerability or bug
|
|
79
|
+
|
|
80
|
+
| Report | Verdict | Why |
|
|
81
|
+
| --------------------------------------------------------------------------- | ------------------- | ---------------------------------------------------------------------------------------------------- |
|
|
82
|
+
| A `python3` in the working directory runs because `PATH` ends with `:` | Vulnerability | The empty entry must not reach the current directory. |
|
|
83
|
+
| A `pyenv` shim that is malware runs during discovery | Not a vulnerability | Searched locations are trusted. |
|
|
84
|
+
| A cached answer for `/usr/bin/python3` is returned after the OS upgraded it | Bug | Cache correctness, crossing no boundary; a vulnerability only if it can point at a different binary. |
|
|
85
|
+
| `PY_DISCOVERY_TIMEOUT=inf` lets a hung interpreter block forever | Not a vulnerability | The environment is trusted and the value is documented. |
|
|
86
|
+
|
|
87
|
+
## Severity
|
|
88
|
+
|
|
89
|
+
- **High:** argument handling runs a separate command the attacker chose, or another local user poisons a shared cache
|
|
90
|
+
so a victim runs an interpreter outside the requested constraints, without control of the victim's `PATH`, registry or
|
|
91
|
+
interpreters.
|
|
92
|
+
- **Medium:** cache poisoning changes security-relevant metadata without execution, or a small candidate response causes
|
|
93
|
+
sustained memory or process exhaustion.
|
|
94
|
+
- **Low:** the wrong interpreter selected without crossing a privilege boundary, a crash on malformed output, or stale
|
|
95
|
+
metadata from a cache only the caller writes.
|
|
96
|
+
|
|
97
|
+
## Accepted risks
|
|
98
|
+
|
|
99
|
+
- Discovery executes every candidate it considers; it cannot learn an interpreter's version without running it.
|
|
100
|
+
- PEP 514 `ExecutableArguments` are raw command-line text from the registry, passed to the candidate as written, without
|
|
101
|
+
a shell.
|
|
102
|
+
|
|
103
|
+
## Keeping this current
|
|
104
|
+
|
|
105
|
+
Revisit this model when python-discovery gains a new input source, network access, a new way to run code, or a new place
|
|
106
|
+
it writes to, and whenever an advisory is published.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 16 16"><path fill-rule="evenodd" d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0 0 16 8c0-4.42-3.58-8-8-8z"></path></svg>
|
|
@@ -6,6 +6,53 @@
|
|
|
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
|
+
|
|
23
|
+
.. _release-1-7-0:
|
|
24
|
+
|
|
25
|
+
*********************
|
|
26
|
+
v1.7.0 (2026-10-30)
|
|
27
|
+
*********************
|
|
28
|
+
|
|
29
|
+
.. _release-1-7-0-added:
|
|
30
|
+
|
|
31
|
+
Added
|
|
32
|
+
-----
|
|
33
|
+
|
|
34
|
+
- Accept the free-threaded, debug, architecture and machine suffixes after a version specifier, as in ``>=3.13t`` or
|
|
35
|
+
``cpython>=3.11,<3.14-64``, and raise ``ValueError`` for a spec that starts with a comparison operator but does not
|
|
36
|
+
parse, such as ``>=3.13.``, instead of looking it up as an executable name (:pr:`176`) by :user:`gaborbernat`.
|
|
37
|
+
(:issue:`175`)
|
|
38
|
+
|
|
39
|
+
.. _release-1-7-0-fixed:
|
|
40
|
+
|
|
41
|
+
Fixed
|
|
42
|
+
-----
|
|
43
|
+
|
|
44
|
+
- Stop a ``.python-version`` file that is not valid UTF-8, or that cannot be read, from aborting discovery through a
|
|
45
|
+
pyenv, mise or asdf shim; a stray byte no longer hides the versions it names, and an unreadable file is skipped like a
|
|
46
|
+
missing one (:pr:`173`) by :user:`darrenhuai` and :user:`gaborbernat`.
|
|
47
|
+
|
|
48
|
+
.. _release-1-7-0-documentation:
|
|
49
|
+
|
|
50
|
+
Documentation
|
|
51
|
+
-------------
|
|
52
|
+
|
|
53
|
+
- Link every documentation page to its source and edit view on GitHub, and add a GitHub icon to the footer (:pr:`177`)
|
|
54
|
+
by :user:`gaborbernat`. (:issue:`174`)
|
|
55
|
+
|
|
9
56
|
.. _release-1-6-7:
|
|
10
57
|
|
|
11
58
|
*********************
|
|
@@ -10,6 +10,7 @@ from python_discovery import __version__
|
|
|
10
10
|
|
|
11
11
|
company = "tox-dev"
|
|
12
12
|
name = "python-discovery"
|
|
13
|
+
repository = f"https://github.com/{company}/{name}"
|
|
13
14
|
version = ".".join(__version__.split(".")[:2])
|
|
14
15
|
release = __version__
|
|
15
16
|
copyright = f"2026-{datetime.now(tz=timezone.utc).year}, {company}" # ruff:ignore[builtin-variable-shadowing]
|
|
@@ -31,9 +32,9 @@ towncrier_draft_working_directory = Path(__file__).parent.parent
|
|
|
31
32
|
autosectionlabel_maxdepth = 2
|
|
32
33
|
|
|
33
34
|
extlinks = {
|
|
34
|
-
"issue": ("
|
|
35
|
-
"pr": ("
|
|
36
|
-
"pull": ("
|
|
35
|
+
"issue": (f"{repository}/issues/%s", "#%s"),
|
|
36
|
+
"pr": (f"{repository}/pull/%s", "PR #%s"),
|
|
37
|
+
"pull": (f"{repository}/pull/%s", "PR #%s"),
|
|
37
38
|
"user": ("https://github.com/%s", "@%s"),
|
|
38
39
|
}
|
|
39
40
|
|
|
@@ -60,6 +61,18 @@ html_theme_options = {
|
|
|
60
61
|
"light_logo": "logo.svg",
|
|
61
62
|
"dark_logo": "logo.svg",
|
|
62
63
|
"sidebar_hide_name": True,
|
|
64
|
+
"source_repository": repository,
|
|
65
|
+
"source_branch": "main",
|
|
66
|
+
"source_directory": "docs/",
|
|
67
|
+
"footer_icons": [
|
|
68
|
+
{
|
|
69
|
+
"name": "GitHub",
|
|
70
|
+
"url": repository,
|
|
71
|
+
# footer icons are inlined into every page, so a path to the image would not resolve
|
|
72
|
+
"html": (Path(__file__).parent / "_static" / "github.svg").read_text(encoding="utf-8"),
|
|
73
|
+
"class": "",
|
|
74
|
+
},
|
|
75
|
+
],
|
|
63
76
|
}
|
|
64
77
|
html_css_files = ["custom.css"]
|
|
65
78
|
|
|
@@ -52,7 +52,7 @@ detects these shims and resolves them to the actual binary.
|
|
|
52
52
|
flowchart TD
|
|
53
53
|
Shim["Shim detected"] --> EnvVar{"PYENV_VERSION<br>set?"}
|
|
54
54
|
EnvVar -->|Yes| Use["Use that version"]
|
|
55
|
-
EnvVar -->|No| File{".python-version<br>
|
|
55
|
+
EnvVar -->|No| File{".python-version<br>names a version?"}
|
|
56
56
|
File -->|Yes| Use
|
|
57
57
|
File -->|No| Global{"pyenv global<br>version exists?"}
|
|
58
58
|
Global -->|Yes| Use
|
|
@@ -364,10 +364,19 @@ and machine segments, leaves the string unrecognized, so it falls back to a lite
|
|
|
364
364
|
* - ``cpython>=3.11``
|
|
365
365
|
- `Version specifier <https://packaging.python.org/en/latest/specifications/version-specifiers/>`_
|
|
366
366
|
restricted to CPython
|
|
367
|
+
* - ``>=3.13t``
|
|
368
|
+
- `Version specifier <https://packaging.python.org/en/latest/specifications/version-specifiers/>`_
|
|
369
|
+
restricted to free-threaded builds
|
|
367
370
|
|
|
368
371
|
`Version specifiers <https://packaging.python.org/en/latest/specifications/version-specifiers/>`_
|
|
369
372
|
(``>=``, ``<=``, ``~=``, ``!=``, ``==``, ``===``) are supported. Multiple specifiers can be comma-separated,
|
|
370
373
|
for example ``>=3.11,<3.13``. Each version is a release of up to three numbers with an optional ``a``, ``b`` or
|
|
371
374
|
``rc`` pre-release suffix, such as ``3.12`` or ``3.13.0rc1``; ``==`` and ``!=`` also take a trailing ``.*``
|
|
372
|
-
wildcard, as in ``==3.12.*``.
|
|
373
|
-
|
|
375
|
+
wildcard, as in ``==3.12.*``.
|
|
376
|
+
|
|
377
|
+
The ABI flags, ``-arch`` and ``-machine`` parts described above follow the last specifier and apply to the whole set:
|
|
378
|
+
``>=3.13t`` asks for a free-threaded 3.13 or newer, ``cpython>=3.11,<3.14-64`` for a 64-bit CPython in that range.
|
|
379
|
+
Without ``t`` a specifier accepts any build, while a plain ``3.13`` asks for the default (GIL) build. A string that
|
|
380
|
+
starts with a comparison operator but does not parse this way, such as ``>=3.x``, ``>=3.10.post1``, ``>=3.12 <4``
|
|
381
|
+
(missing comma) or ``>=3.13t,<3.15`` (a flag on an inner item), raises :exc:`ValueError` instead of being looked up as
|
|
382
|
+
an executable name.
|
|
@@ -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
|
|
@@ -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
|
|
|
@@ -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):
|
|
@@ -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)
|
|
@@ -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
|
[
|
|
@@ -119,7 +119,7 @@ def test_discovery_fallback_fail(session_cache: DiskCache, caplog: pytest.LogCap
|
|
|
119
119
|
assert "accepted" not in caplog.text
|
|
120
120
|
|
|
121
121
|
|
|
122
|
-
@pytest.mark.parametrize("missing", ["magic-one", "python."
|
|
122
|
+
@pytest.mark.parametrize("missing", ["magic-one", "python."])
|
|
123
123
|
def test_discovery_fallback_ok(missing: str, session_cache: DiskCache, caplog: pytest.LogCaptureFixture) -> None:
|
|
124
124
|
caplog.set_level(logging.DEBUG)
|
|
125
125
|
result = get_interpreter([missing, sys.executable], cache=session_cache)
|
|
@@ -128,6 +128,11 @@ def test_discovery_fallback_ok(missing: str, session_cache: DiskCache, caplog: p
|
|
|
128
128
|
assert "accepted" in caplog.text
|
|
129
129
|
|
|
130
130
|
|
|
131
|
+
def test_discovery_invalid_specifier_raises(session_cache: DiskCache) -> None:
|
|
132
|
+
with pytest.raises(ValueError, match=r"^invalid version specifier '>=3\.12 <4'$"):
|
|
133
|
+
get_interpreter([">=3.12 <4", sys.executable], cache=session_cache)
|
|
134
|
+
|
|
135
|
+
|
|
131
136
|
@pytest.fixture
|
|
132
137
|
def mock_find_interpreter(mocker: MockerFixture) -> None:
|
|
133
138
|
mocker.patch(
|
|
@@ -260,6 +265,11 @@ def test_discovery_via_version_specifier(session_cache: DiskCache) -> None:
|
|
|
260
265
|
assert interpreter.implementation == "CPython"
|
|
261
266
|
|
|
262
267
|
|
|
268
|
+
_POSIX_PERMISSIONS: Final[pytest.MarkDecorator] = pytest.mark.skipif(
|
|
269
|
+
IS_WIN or os.geteuid() == 0, reason="POSIX file permissions, which root bypasses"
|
|
270
|
+
)
|
|
271
|
+
|
|
272
|
+
|
|
263
273
|
def _create_version_manager(tmp_path: Path, env_var: str) -> Path:
|
|
264
274
|
root = tmp_path / env_var.lower()
|
|
265
275
|
root.mkdir()
|
|
@@ -358,6 +368,61 @@ def test_shim_uses_python_version_file(tmp_path: Path, monkeypatch: pytest.Monke
|
|
|
358
368
|
assert mock_from_exe.call_args_list[0][0][0] == str(real_binary)
|
|
359
369
|
|
|
360
370
|
|
|
371
|
+
def test_shim_python_version_file_not_utf8(
|
|
372
|
+
tmp_path: Path, monkeypatch: pytest.MonkeyPatch, pyenv_probed: Callable[[], tuple[str, ...]]
|
|
373
|
+
) -> None:
|
|
374
|
+
(tmp_path / ".python-version").write_bytes(b"# pinned by M\xfcller\n2.7.18\n")
|
|
375
|
+
monkeypatch.chdir(tmp_path)
|
|
376
|
+
|
|
377
|
+
assert pyenv_probed() == ("versions", "2.7.18")
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
@_POSIX_PERMISSIONS
|
|
381
|
+
def test_shim_unreadable_python_version_file_is_skipped(
|
|
382
|
+
tmp_path: Path, monkeypatch: pytest.MonkeyPatch, pyenv_probed: Callable[[], tuple[str, ...]]
|
|
383
|
+
) -> None:
|
|
384
|
+
(tmp_path / ".python-version").write_text("2.7.18\n", encoding="utf-8")
|
|
385
|
+
(unreadable := tmp_path / "child" / ".python-version").parent.mkdir()
|
|
386
|
+
unreadable.write_text("3.12.0\n", encoding="utf-8")
|
|
387
|
+
unreadable.chmod(0)
|
|
388
|
+
monkeypatch.chdir(unreadable.parent)
|
|
389
|
+
|
|
390
|
+
assert pyenv_probed() == ("versions", "2.7.18")
|
|
391
|
+
|
|
392
|
+
|
|
393
|
+
@_POSIX_PERMISSIONS
|
|
394
|
+
def test_shim_unsearchable_directory_is_skipped(
|
|
395
|
+
tmp_path: Path, monkeypatch: pytest.MonkeyPatch, pyenv_probed: Callable[[], tuple[str, ...]]
|
|
396
|
+
) -> None:
|
|
397
|
+
(tmp_path / ".python-version").write_text("2.7.18\n", encoding="utf-8")
|
|
398
|
+
(work := tmp_path / "locked" / "work").mkdir(parents=True)
|
|
399
|
+
monkeypatch.chdir(work)
|
|
400
|
+
work.parent.chmod(0o600)
|
|
401
|
+
try:
|
|
402
|
+
assert pyenv_probed() == ("versions", "2.7.18")
|
|
403
|
+
finally:
|
|
404
|
+
work.parent.chmod(0o700)
|
|
405
|
+
|
|
406
|
+
|
|
407
|
+
@pytest.fixture
|
|
408
|
+
def pyenv_probed(
|
|
409
|
+
tmp_path: Path, monkeypatch: pytest.MonkeyPatch, mocker: MockerFixture
|
|
410
|
+
) -> Callable[[], tuple[str, ...]]:
|
|
411
|
+
root = _create_version_manager(tmp_path, "PYENV_ROOT")
|
|
412
|
+
_create_versioned_binary(root, ("versions",), "2.7.18", "python2.7")
|
|
413
|
+
(root / "shims" / ("python2.7.exe" if IS_WIN else "python2.7")).touch(mode=0o755)
|
|
414
|
+
monkeypatch.setenv("PATH", str(root / "shims"))
|
|
415
|
+
monkeypatch.setenv("PYENV_ROOT", str(root))
|
|
416
|
+
monkeypatch.delenv("PYENV_VERSION", raising=False)
|
|
417
|
+
from_exe = mocker.patch("python_discovery._discovery.PathPythonInfo.from_exe", return_value=None)
|
|
418
|
+
|
|
419
|
+
def _probed() -> tuple[str, ...]:
|
|
420
|
+
get_interpreter("python2.7", [])
|
|
421
|
+
return Path(from_exe.call_args_list[0].args[0]).relative_to(root).parts[:2]
|
|
422
|
+
|
|
423
|
+
return _probed
|
|
424
|
+
|
|
425
|
+
|
|
361
426
|
def test_shim_pyenv_version_env_takes_priority_over_file(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
|
362
427
|
root = _create_version_manager(tmp_path, "PYENV_ROOT")
|
|
363
428
|
_create_versioned_binary(root, ("versions",), "2.7.18", "python2.7")
|
|
@@ -195,6 +195,18 @@ def test_satisfies_version_specifier_fails() -> None:
|
|
|
195
195
|
assert CURRENT.satisfies(spec, impl_must_match=False) is False
|
|
196
196
|
|
|
197
197
|
|
|
198
|
+
@pytest.mark.parametrize(
|
|
199
|
+
("suffix", "expected"),
|
|
200
|
+
[
|
|
201
|
+
pytest.param("t", CURRENT.free_threaded, id="free-threaded"),
|
|
202
|
+
pytest.param("", True, id="any-build"),
|
|
203
|
+
],
|
|
204
|
+
)
|
|
205
|
+
def test_satisfies_version_specifier_free_threaded(suffix: str, expected: bool) -> None:
|
|
206
|
+
spec = PythonSpec.from_string_spec(f">={sys.version_info.major}.{sys.version_info.minor}{suffix}")
|
|
207
|
+
assert CURRENT.satisfies(spec, impl_must_match=False) is expected
|
|
208
|
+
|
|
209
|
+
|
|
198
210
|
def test_satisfies_version_specifier_unparsable_version() -> None:
|
|
199
211
|
specifier = SimpleSpecifierSet.from_string(">=3.x")
|
|
200
212
|
spec = PythonSpec(">=3.x", None, None, None, None, None, None, version_specifier=specifier)
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
+
import re
|
|
3
4
|
import sys
|
|
4
5
|
from typing import TYPE_CHECKING
|
|
5
6
|
|
|
@@ -23,15 +24,6 @@ if TYPE_CHECKING:
|
|
|
23
24
|
"python.",
|
|
24
25
|
"cpython..",
|
|
25
26
|
"pypy...",
|
|
26
|
-
">=3.x",
|
|
27
|
-
">=3.12 <4",
|
|
28
|
-
">=3.10.post1",
|
|
29
|
-
"cpython>=v3.10",
|
|
30
|
-
">=3.12,<4.x",
|
|
31
|
-
">=3.x,<4",
|
|
32
|
-
"<,4",
|
|
33
|
-
">=3.12,foo",
|
|
34
|
-
">=3.12, 4",
|
|
35
27
|
],
|
|
36
28
|
)
|
|
37
29
|
def test_bad_py_spec(text: str) -> None:
|
|
@@ -45,6 +37,49 @@ def test_bad_py_spec(text: str) -> None:
|
|
|
45
37
|
assert all(v is None for v in content.values())
|
|
46
38
|
|
|
47
39
|
|
|
40
|
+
@pytest.mark.parametrize(
|
|
41
|
+
"text",
|
|
42
|
+
[
|
|
43
|
+
pytest.param(">=3.x", id="non-numeric-version"),
|
|
44
|
+
pytest.param(">=3.13.", id="trailing-dot"),
|
|
45
|
+
pytest.param(">=3.10.post1", id="post-release"),
|
|
46
|
+
pytest.param("cpython>=v3.10", id="v-prefix"),
|
|
47
|
+
pytest.param(">=3.12 <4", id="missing-comma"),
|
|
48
|
+
pytest.param(">=3.12,<4.x", id="bad-last-item"),
|
|
49
|
+
pytest.param(">=3.x,<4", id="bad-first-item"),
|
|
50
|
+
pytest.param("<,4", id="operator-without-version"),
|
|
51
|
+
pytest.param(">=3.12,foo", id="item-without-operator"),
|
|
52
|
+
pytest.param(">=", id="bare-operator"),
|
|
53
|
+
pytest.param(">=3.13t,<3.15", id="modifier-before-last-item"),
|
|
54
|
+
],
|
|
55
|
+
)
|
|
56
|
+
def test_invalid_specifier_raises(text: str) -> None:
|
|
57
|
+
with pytest.raises(ValueError, match=f"^invalid version specifier {re.escape(repr(text))}$"):
|
|
58
|
+
PythonSpec.from_string_spec(text)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
@pytest.mark.parametrize(
|
|
62
|
+
("text", "expected"),
|
|
63
|
+
[
|
|
64
|
+
pytest.param(">=3.13t", (">=3.13", True, None, None, None), id="free-threaded"),
|
|
65
|
+
pytest.param(">=3.13td", (">=3.13", True, True, None, None), id="free-threaded-debug"),
|
|
66
|
+
pytest.param(">=3.13-dbg", (">=3.13", None, True, None, None), id="debug"),
|
|
67
|
+
pytest.param(">=3.11,<3.14t", (">=3.11,<3.14", True, None, None, None), id="set"),
|
|
68
|
+
pytest.param("cpython>=3.12-64-arm64", (">=3.12", None, None, 64, "arm64"), id="arch-machine"),
|
|
69
|
+
pytest.param(">=3.13", (">=3.13", None, None, None, None), id="any-build"),
|
|
70
|
+
],
|
|
71
|
+
)
|
|
72
|
+
def test_specifier_modifiers(text: str, expected: tuple[str, bool | None, bool | None, int | None, str | None]) -> None:
|
|
73
|
+
spec = PythonSpec.from_string_spec(text)
|
|
74
|
+
assert (
|
|
75
|
+
str(spec.version_specifier),
|
|
76
|
+
spec.free_threaded,
|
|
77
|
+
spec.debug,
|
|
78
|
+
spec.architecture,
|
|
79
|
+
spec.machine,
|
|
80
|
+
) == expected
|
|
81
|
+
|
|
82
|
+
|
|
48
83
|
def test_py_spec_first_digit_only_major() -> None:
|
|
49
84
|
spec = PythonSpec.from_string_spec("278")
|
|
50
85
|
assert spec.major == 2
|
|
@@ -101,11 +101,6 @@ def test_single_digit_version() -> None:
|
|
|
101
101
|
assert spec.minor is None
|
|
102
102
|
|
|
103
103
|
|
|
104
|
-
def test_specifier_with_invalid_inner() -> None:
|
|
105
|
-
spec = PythonSpec.from_string_spec(">=not_a_version")
|
|
106
|
-
assert spec.path is None or spec.version_specifier is not None or spec.path == ">=not_a_version"
|
|
107
|
-
|
|
108
|
-
|
|
109
104
|
def test_two_digit_version() -> None:
|
|
110
105
|
spec = PythonSpec.from_string_spec("python312")
|
|
111
106
|
assert spec.major == 3
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
# Security Policy
|
|
2
|
-
|
|
3
|
-
## Supported Versions
|
|
4
|
-
|
|
5
|
-
Only the latest released version is supported with security updates. Older versions will not receive patches.
|
|
6
|
-
|
|
7
|
-
## Reporting a Vulnerability
|
|
8
|
-
|
|
9
|
-
Please report security vulnerabilities via [GitHub's private vulnerability reporting](../../security/advisories/new).
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{python_discovery-1.6.7 → python_discovery-1.8.0}/.github/workflows/upgrade-release-tools.yaml
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{python_discovery-1.6.7 → python_discovery-1.8.0}/tests/py_info/test_py_info_exe_based_of.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|