Skip to content

Commit

Permalink
Add supported CPython/PyPy versions to cargo package metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
messense committed Dec 5, 2024
1 parent 2ed3bb4 commit 0bc5125
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
12 changes: 10 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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"] }
Expand Down Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions newsfragments/4756.packaging.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add supported CPython/PyPy versions to cargo package metadata.
18 changes: 18 additions & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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

Expand Down
8 changes: 8 additions & 0 deletions pyo3-ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 0bc5125

Please sign in to comment.