diff --git a/Cargo.toml b/Cargo.toml index 778a8f7df2e..d977337d40e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,7 +41,7 @@ hashbrown = { version = ">= 0.14.5, < 0.16", optional = true } indexmap = { version = ">= 2.5.0, < 3", optional = true } num-bigint = { version = "0.4.2", optional = true } num-complex = { version = ">= 0.4.6, < 0.5", optional = true } -num-rational = {version = "0.4.1", optional = true } +num-rational = { version = "0.4.1", optional = true } rust_decimal = { version = "1.15", default-features = false, optional = true } serde = { version = "1.0", optional = true } smallvec = { version = "1.0", optional = true } @@ -63,7 +63,7 @@ rayon = "1.6.1" futures = "0.3.28" tempfile = "3.12.0" static_assertions = "1.1.0" -uuid = {version = "1.10.0", features = ["v4"] } +uuid = { version = "1.10.0", features = ["v4"] } [build-dependencies] pyo3-build-config = { path = "pyo3-build-config", version = "=0.23.2", features = ["resolve-config"] } @@ -150,6 +150,14 @@ no-default-features = true features = ["full"] rustdoc-args = ["--cfg", "docsrs"] +[package.metadata.cpython] +min-version = "3.7" +max-version = "3.13" # inclusive + +[package.metadata.pypy] +min-version = "3.9" +max-version = "3.10" # inclusive + [workspace.lints.clippy] checked_conversions = "warn" dbg_macro = "warn" diff --git a/newsfragments/4756.packaging.md b/newsfragments/4756.packaging.md new file mode 100644 index 00000000000..a3259c1fc42 --- /dev/null +++ b/newsfragments/4756.packaging.md @@ -0,0 +1 @@ +Add supported CPython/PyPy versions to cargo package metadata. diff --git a/noxfile.py b/noxfile.py index 25cb8d1eb92..47a592a9305 100644 --- a/noxfile.py +++ b/noxfile.py @@ -44,6 +44,8 @@ def test(session: nox.Session) -> None: @nox.session(name="test-rust", venv_backend="none") def test_rust(session: nox.Session): + _run_cargo_package_metadata_test(session, packages=["pyo3", "pyo3-ffi"]) + _run_cargo_test(session, package="pyo3-build-config") _run_cargo_test(session, package="pyo3-macros-backend") _run_cargo_test(session, package="pyo3-macros") @@ -914,6 +916,22 @@ def _run_cargo_set_package_version( _run(session, *command, external=True) +def _run_cargo_package_metadata_test( + session: nox.Session, *, packages: List[str] +) -> None: + output = _get_output("cargo", "metadata", "--format-version=1", "--no-deps") + cargo_packages = json.loads(output)["packages"] + for package in packages: + # Check Python interpreter version support in package metadata + metadata = next( + pkg["metadata"] for pkg in cargo_packages if pkg["name"] == package + ) + for python_impl in ["cpython", "pypy"]: + version_info = metadata[python_impl] + assert "min-version" in version_info + assert "max-version" in version_info + + def _get_output(*args: str) -> str: return subprocess.run(args, capture_output=True, text=True, check=True).stdout diff --git a/pyo3-ffi/Cargo.toml b/pyo3-ffi/Cargo.toml index 1a8cd7f09d7..7f9c85b0458 100644 --- a/pyo3-ffi/Cargo.toml +++ b/pyo3-ffi/Cargo.toml @@ -46,3 +46,11 @@ pyo3-build-config = { path = "../pyo3-build-config", version = "=0.23.2", featur [lints] workspace = true + +[package.metadata.cpython] +min-version = "3.7" +max-version = "3.13" # inclusive + +[package.metadata.pypy] +min-version = "3.9" +max-version = "3.10" # inclusive