Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/decorator/.template/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ build-backend = "maturin"
name = "{{project-name}}"
version = "0.1.0"

[project.optional-dependencies]
[dependency-groups]
dev = ["pytest"]
13 changes: 12 additions & 1 deletion examples/decorator/noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,16 @@ def python(session: nox.Session):
session.env["MATURIN_PEP517_ARGS"] = "--profile=dev"
if args.features:
session.env["MATURIN_PEP517_ARGS"] += f" --features={args.features}"
session.install(".[dev]")

session.run_install(
"uv",
"sync",
"--group=dev",
"--no-default-groups",
env={
"UV_PROJECT_ENVIRONMENT": session.virtualenv.location,
"UV_PYTHON": session.virtualenv.location,
},
)

session.run("pytest")
2 changes: 1 addition & 1 deletion examples/decorator/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ classifiers = [
"Operating System :: MacOS :: MacOS X",
]

[project.optional-dependencies]
[dependency-groups]
dev = ["pytest"]
2 changes: 1 addition & 1 deletion examples/getitem/.template/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ build-backend = "maturin"
name = "{{project-name}}"
version = "0.1.0"

[project.optional-dependencies]
[dependency-groups]
dev = ["pytest"]
13 changes: 12 additions & 1 deletion examples/getitem/noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,16 @@ def python(session: nox.Session):
session.env["MATURIN_PEP517_ARGS"] = "--profile=dev"
if args.features:
session.env["MATURIN_PEP517_ARGS"] += f" --features={args.features}"
session.install(".[dev]")

session.run_install(
"uv",
"sync",
"--group=dev",
"--no-default-groups",
env={
"UV_PROJECT_ENVIRONMENT": session.virtualenv.location,
"UV_PYTHON": session.virtualenv.location,
},
)

session.run("pytest")
2 changes: 1 addition & 1 deletion examples/getitem/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ classifiers = [
"Operating System :: MacOS :: MacOS X",
]

[project.optional-dependencies]
[dependency-groups]
dev = ["pytest"]
2 changes: 1 addition & 1 deletion examples/maturin-starter/.template/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ build-backend = "maturin"
name = "{{project-name}}"
version = "0.1.0"

[project.optional-dependencies]
[dependency-groups]
dev = ["pytest"]
12 changes: 11 additions & 1 deletion examples/maturin-starter/noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,15 @@ def python(session):
if args.features:
session.env["MATURIN_PEP517_ARGS"] += f" --features={args.features}"

session.install(".[dev]")
session.run_install(
"uv",
"sync",
"--group=dev",
"--no-default-groups",
env={
"UV_PROJECT_ENVIRONMENT": session.virtualenv.location,
"UV_PYTHON": session.virtualenv.location,
},
)

session.run("pytest")
2 changes: 1 addition & 1 deletion examples/maturin-starter/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ classifiers = [
"Operating System :: MacOS :: MacOS X",
]

[project.optional-dependencies]
[dependency-groups]
dev = ["pytest"]
2 changes: 1 addition & 1 deletion examples/meson-starter/.template/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ build-backend = "mesonpy"
name = "{{project-name}}"
version = "0.1.0"

[project.optional-dependencies]
[dependency-groups]
dev = ["pytest"]

[tool.meson-python.args]
Expand Down
13 changes: 12 additions & 1 deletion examples/plugin/plugin_api/noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,16 @@ def python(session: nox.Session):
session.env["MATURIN_PEP517_ARGS"] = "--profile=dev"
if args.features:
session.env["MATURIN_PEP517_ARGS"] += f" --features={args.features}"
session.install(".[dev]")

session.run_install(
"uv",
"sync",
"--group=dev",
"--no-default-groups",
env={
"UV_PROJECT_ENVIRONMENT": session.virtualenv.location,
"UV_PYTHON": session.virtualenv.location,
},
)

session.run("pytest")
2 changes: 1 addition & 1 deletion examples/plugin/plugin_api/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ classifiers = [
"Programming Language :: Python :: Implementation :: PyPy",
]

[project.optional-dependencies]
[dependency-groups]
dev = ["pytest"]
13 changes: 12 additions & 1 deletion examples/setuptools-rust-starter/noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,16 @@
@nox.session
def python(session: nox.Session):
session.env["SETUPTOOLS_RUST_CARGO_PROFILE"] = "dev"
session.install(".[dev]")

session.run_install(
"uv",
"sync",
"--group=dev",
"--no-default-groups",
env={
"UV_PROJECT_ENVIRONMENT": session.virtualenv.location,
"UV_PYTHON": session.virtualenv.location,
},
)

session.run("pytest")
2 changes: 1 addition & 1 deletion examples/setuptools-rust-starter/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ classifiers = [
"Operating System :: MacOS :: MacOS X",
]

[project.optional-dependencies]
[dependency-groups]
dev = ["pytest"]

[tool.setuptools.packages.find]
Expand Down
2 changes: 1 addition & 1 deletion examples/word-count/.template/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ build-backend = "maturin"
name = "{{project-name}}"
version = "0.1.0"

[project.optional-dependencies]
[dependency-groups]
dev = ["pytest"]

[tool.pytest.ini_options]
Expand Down
19 changes: 17 additions & 2 deletions examples/word-count/noxfile.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
import argparse
from collections.abc import Iterable

import nox

nox.options.sessions = ["test"]


def uv_sync(session: nox.Session, groups: Iterable[str] = ()):
cmd = ["uv", "sync", "--locked", "--no-default-groups"]
cmd.extend([f"--group={g}" for g in groups])
session.run_install(
*cmd,
env={
"UV_PROJECT_ENVIRONMENT": session.virtualenv.location,
"UV_PYTHON": session.virtualenv.location,
},
)


@nox.session
def test(session: nox.Session):
parser = argparse.ArgumentParser()
Expand All @@ -14,7 +27,8 @@ def test(session: nox.Session):
session.env["MATURIN_PEP517_ARGS"] = "--profile=dev"
if args.features:
session.env["MATURIN_PEP517_ARGS"] += f" --features={args.features}"
session.install(".[dev]")

uv_sync(session, groups=["dev"])
session.run("pytest")


Expand All @@ -26,5 +40,6 @@ def bench(session: nox.Session):

if args.features:
session.env["MATURIN_PEP517_ARGS"] = f" --features={args.features}"
session.install(".[dev]")

uv_sync(session, groups=["dev"])
session.run("pytest", "--benchmark-enable")
2 changes: 1 addition & 1 deletion examples/word-count/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ classifiers = [
"Operating System :: MacOS :: MacOS X",
]

[project.optional-dependencies]
[dependency-groups]
dev = ["pytest", "pytest-benchmark"]

[tool.pytest.ini_options]
Expand Down
31 changes: 27 additions & 4 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
toml = None

nox.options.sessions = ["test", "clippy", "rustfmt", "ruff", "rumdl", "docs", "typos"]
nox.options.default_venv_backend = "uv"

PYO3_DIR = Path(__file__).parent
PYO3_TARGET = Path(os.environ.get("CARGO_TARGET_DIR", PYO3_DIR / "target")).absolute()
Expand All @@ -41,6 +42,26 @@
FREE_THREADED_BUILD = bool(sysconfig.get_config_var("Py_GIL_DISABLED"))


def uv_sync(
session: nox.Session,
groups: Iterable[str] = (),
packages: Iterable[str] = (),
no_install_project=False,
):
cmd = ["uv", "sync", "--locked", "--no-default-groups"]
cmd.extend([f"--group={g}" for g in groups])
cmd.extend([f"--package={p}" for p in packages])
if no_install_project:
cmd.append("--no-install-project")
session.run_install(
*cmd,
env={
"UV_PROJECT_ENVIRONMENT": session.virtualenv.location,
"UV_PYTHON": session.virtualenv.location,
},
)


def _get_output(*args: str, env: dict[str, str] | None = None) -> str:
try:
return subprocess.run(
Expand Down Expand Up @@ -351,15 +372,16 @@ def bench(session: nox.Session) -> bool:
_run_cargo(session, "bench", _BENCHES, *session.posargs)


@nox.session()
@nox.session
def codspeed(session: nox.Session) -> bool:
# rust benchmarks
os.chdir(PYO3_DIR / "pyo3-benches")
_run_cargo(session, "codspeed", "build")
_run_cargo(session, "codspeed", "run")
# python benchmarks
os.chdir(PYO3_DIR / "pytests")
session.install(".[dev]", "pytest-codspeed")
uv_sync(session, ["dev"])
session.install("pytest-codspeed")
_run(session, "pytest", "--codspeed", external=True)


Expand Down Expand Up @@ -1774,10 +1796,11 @@ def update_ui_tests(session: nox.Session):
@nox.session(name="test-introspection")
def test_introspection(session: nox.Session):
with tempfile.TemporaryDirectory() as stub_dir:
uv_sync(
session, groups=["dev"], packages=["pyo3_pytests"], no_install_project=True
)
session.install("maturin")
session.install("ruff")
# `pytest-benchmark` backs the `--benchmark-disable` in `pytests/pyproject.toml`
session.install("pytest", "pytest-benchmark")
options = []
target = os.environ.get("CARGO_BUILD_TARGET")
if target is not None:
Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ style = "fenced"
[tool.uv]
package = false

[tool.uv.workspace]
members = ["pytests/", "pyo3-introspection/", "examples/*"]
exclude = ["examples/plugin", "examples/meson-starter"]

[tool.uv.dependency-groups]
codecov = { requires-python = ">=3.14" }
dev = { requires-python = ">=3.14" }
Expand Down
24 changes: 19 additions & 5 deletions pytests/noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@
from nox.command import CommandFailed

nox.options.sessions = ["test"]
nox.options.default_venv_backend = "uv"


def uv_sync(session: nox.Session, groups: Iterable[str] = []):
cmd = ["uv", "sync", "--locked", "--no-default-groups"]
cmd.extend([f"--group={g}" for g in groups])
session.run_install(
*cmd,
env={
"UV_PROJECT_ENVIRONMENT": session.virtualenv.location,
"UV_PYTHON": session.virtualenv.location,
},
)


@nox.session
Expand All @@ -19,7 +32,8 @@ def test(session: nox.Session):
session.env["MATURIN_PEP517_ARGS"] = "--profile=dev"
if args.features:
session.env["MATURIN_PEP517_ARGS"] += f" --features={args.features}"
session.install("-v", ".[dev]")

uv_sync(session, ["dev"])

def try_install_binary(package: str, constraint: str):
try:
Expand Down Expand Up @@ -52,15 +66,15 @@ def try_install_binary(package: str, constraint: str):

@nox.session
def bench(session: nox.Session):
session.install(".[dev]")
uv_sync(session, ["dev"])
session.run("pytest", "--benchmark-enable", "--benchmark-only", *session.posargs)


@nox.session
def mypy(session: nox.Session):
type_checker(
session,
("python", "-m", "mypy", "tests"),
("mypy", "tests"),
)
# TODO: enable stubtest session.run_always("python", "-m", "mypy.stubtest", "pyo3_pytests")

Expand All @@ -69,17 +83,17 @@ def mypy(session: nox.Session):
def pyrefly(session: nox.Session):
type_checker(
session,
("python", "-m", "pyrefly", "check", "tests"),
("pyrefly", "check", "--search-path", ".", "tests"),
)


def type_checker(session: nox.Session, command: Iterable[str]):
session.env["MATURIN_PEP517_ARGS"] = "--profile=dev"
uv_sync(session, ["dev"])
try:
# We move the stubs where maturin is expecting them to be
shutil.copytree("stubs", "pyo3_pytests")
(Path("pyo3_pytests") / "py.typed").touch()
session.install(".[dev]")

session.run_always(*command)
finally:
Expand Down
2 changes: 1 addition & 1 deletion pytests/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ requires-python = ">=3.9"
"UP037", # quoted annotations
]

[project.optional-dependencies]
[dependency-groups]
dev = [
# mypy doesn't build on GraalPy when installed via uv
"mypy~=1.0; platform_python_implementation != 'GraalVM'",
Expand Down
Loading
Loading