Skip to content

Commit ab6d1d2

Browse files
authored
feat: read build-details.json (PEP 739) for version detection (#452)
Fixes #449. Python 3.14+ ships [`build-details.json`](https://packaging.python.org/en/latest/specifications/build-details/) (PEP 739) in the platform-independent stdlib directory. Read it as a faster, more authoritative source than parsing `patchlevel.h` headers, slotting it between `pyvenv.cfg` and the existing header-based fallback in the version detection chain. ### Changes - New `pet_python_utils::build_details` module — finds and parses `build-details.json` from a sys.prefix-like path. Handles both Unix (`<prefix>/lib/python<X.Y>[t]/`) and Windows (`<prefix>/Lib/`) layouts. - New `version::from_build_details(prefix)` and updated chain in `version::from_prefix`: `pyvenv.cfg → build-details → headers`. - `version::from_creator_for_virtual_env` now also tries `build-details.json` (with a `(major, minor)` hint from `pyvenv.cfg`) on the creator's sys_root before scanning headers. - Schema validation: only `1.x` accepted; unknown `releaselevel` or read failures emit warnings. - Stdlib directory matching uses a strict regex (`^(python|pypy)\d+\.\d+t?$`) to avoid false positives like `python3` (versionless) or `python-config`. - Unit tests in the module + integration tests with realistic JSON fixtures, including chain-priority assertions (`pyvenv.cfg` beats `build-details`, `build-details` beats `headers`).
1 parent 53a78ed commit ab6d1d2

8 files changed

Lines changed: 674 additions & 1 deletion

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/pet-python-utils/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ serde_json = "1.0.93"
1818
sha2 = "0.10.6"
1919
env_logger = "0.10.2"
2020

21+
[dev-dependencies]
22+
tempfile = "3.10"
23+
2124
[features]
2225
ci = []
2326
ci-jupyter-container = []

0 commit comments

Comments
 (0)