Skip to content

Commit 35c0084

Browse files
Add supported CPython/PyPy versions to cargo package metadata (#4756)
* Add supported CPython/PyPy versions to cargo package metadata * Update max pypy version to 3.11 Co-authored-by: David Hewitt <[email protected]> * Address code review comments --------- Co-authored-by: David Hewitt <[email protected]>
1 parent 31bb2f4 commit 35c0084

File tree

4 files changed

+46
-8
lines changed

4 files changed

+46
-8
lines changed

Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ indexmap = { version = ">= 2.5.0, < 3", optional = true }
4242
jiff-02 = { package = "jiff", version = "0.2", optional = true }
4343
num-bigint = { version = "0.4.2", optional = true }
4444
num-complex = { version = ">= 0.4.6, < 0.5", optional = true }
45-
num-rational = {version = "0.4.1", optional = true }
45+
num-rational = { version = "0.4.1", optional = true }
4646
rust_decimal = { version = "1.15", default-features = false, optional = true }
4747
serde = { version = "1.0", optional = true }
4848
smallvec = { version = "1.0", optional = true }
@@ -65,7 +65,7 @@ rayon = "1.6.1"
6565
futures = "0.3.28"
6666
tempfile = "3.12.0"
6767
static_assertions = "1.1.0"
68-
uuid = {version = "1.10.0", features = ["v4"] }
68+
uuid = { version = "1.10.0", features = ["v4"] }
6969

7070
[build-dependencies]
7171
pyo3-build-config = { path = "pyo3-build-config", version = "=0.23.5", features = ["resolve-config"] }

newsfragments/4756.packaging.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add supported CPython/PyPy versions to cargo package metadata.

noxfile.py

+35-6
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
Iterable,
1818
Iterator,
1919
List,
20+
Literal,
2021
Optional,
2122
Tuple,
2223
Generator,
@@ -41,11 +42,43 @@
4142
PYO3_GUIDE_SRC = PYO3_DIR / "guide" / "src"
4243
PYO3_GUIDE_TARGET = PYO3_TARGET / "guide"
4344
PYO3_DOCS_TARGET = PYO3_TARGET / "doc"
44-
PY_VERSIONS = ("3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13")
45-
PYPY_VERSIONS = ("3.9", "3.10", "3.11")
4645
FREE_THREADED_BUILD = bool(sysconfig.get_config_var("Py_GIL_DISABLED"))
4746

4847

48+
def _get_output(*args: str) -> str:
49+
return subprocess.run(args, capture_output=True, text=True, check=True).stdout
50+
51+
52+
def _parse_supported_interpreter_version(
53+
python_impl: Literal["cpython", "pypy"],
54+
) -> Tuple[str, str]:
55+
output = _get_output("cargo", "metadata", "--format-version=1", "--no-deps")
56+
cargo_packages = json.loads(output)["packages"]
57+
# Check Python interpreter version support in package metadata
58+
package = "pyo3-ffi"
59+
metadata = next(pkg["metadata"] for pkg in cargo_packages if pkg["name"] == package)
60+
version_info = metadata[python_impl]
61+
assert "min-version" in version_info, f"missing min-version for {python_impl}"
62+
assert "max-version" in version_info, f"missing max-version for {python_impl}"
63+
return version_info["min-version"], version_info["max-version"]
64+
65+
66+
def _supported_interpreter_versions(
67+
python_impl: Literal["cpython", "pypy"],
68+
) -> List[str]:
69+
min_version, max_version = _parse_supported_interpreter_version(python_impl)
70+
major = int(min_version.split(".")[0])
71+
assert major == 3, f"unsupported Python major version {major}"
72+
min_minor = int(min_version.split(".")[1])
73+
max_minor = int(max_version.split(".")[1])
74+
versions = [f"{major}.{minor}" for minor in range(min_minor, max_minor + 1)]
75+
return versions
76+
77+
78+
PY_VERSIONS = _supported_interpreter_versions("cpython")
79+
PYPY_VERSIONS = _supported_interpreter_versions("pypy")
80+
81+
4982
@nox.session(venv_backend="none")
5083
def test(session: nox.Session) -> None:
5184
test_rust(session)
@@ -931,10 +964,6 @@ def _run_cargo_set_package_version(
931964
_run(session, *command, external=True)
932965

933966

934-
def _get_output(*args: str) -> str:
935-
return subprocess.run(args, capture_output=True, text=True, check=True).stdout
936-
937-
938967
def _for_all_version_configs(
939968
session: nox.Session, job: Callable[[Dict[str, str]], None]
940969
) -> None:

pyo3-ffi/Cargo.toml

+8
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,11 @@ pyo3-build-config = { path = "../pyo3-build-config", version = "=0.23.5", featur
4646

4747
[lints]
4848
workspace = true
49+
50+
[package.metadata.cpython]
51+
min-version = "3.7"
52+
max-version = "3.13" # inclusive
53+
54+
[package.metadata.pypy]
55+
min-version = "3.9"
56+
max-version = "3.11" # inclusive

0 commit comments

Comments
 (0)