Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: new nox, pytest-xdist #987

Merged
merged 2 commits into from
Mar 5, 2025
Merged
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
37 changes: 18 additions & 19 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
# /// script
# dependencies = ["nox>=2025.2.9"]
# ///

from __future__ import annotations

import argparse
from typing import Any

import nox

nox.needs_version = ">=2024.4.15"
nox.needs_version = ">=2025.2.9"
nox.options.default_venv_backend = "uv|virtualenv"


def _get_group(name: str, groups: dict[str, Any]) -> list[str]:
group = groups[name]
return [d if isinstance(d, str) else _get_group(d, groups) for d in group]


def dependency_groups(pyproject: dict[str, Any], *names: str) -> list[str]:
groups = pyproject["dependency-groups"]
return [item for name in names for item in _get_group(name, groups)]


@nox.session
def tests(session: nox.Session) -> None:
"""
Expand All @@ -27,26 +20,28 @@ def tests(session: nox.Session) -> None:
opts = (
["--reinstall-package=boost-histogram"] if session.venv_backend == "uv" else []
)
args = session.posargs or ["-n", "auto"]
pyproject = nox.project.load_toml("pyproject.toml")
session.install(*dependency_groups(pyproject, "test"))
session.install(*nox.project.dependency_groups(pyproject, "test"))
session.install("-v", ".", *opts, silent=False)
session.run("pytest", *session.posargs)
session.run("pytest", *args)


@nox.session(default=False)
def hist(session: nox.Session) -> None:
"""
Run Hist's test suite
"""
args = session.posargs or ["-n", "auto"]
pyproject = nox.project.load_toml("pyproject.toml")
session.install(".")
tmpdir = session.create_tmp()
session.chdir(tmpdir)
session.run("git", "clone", "https://github.com/scikit-hep/hist", external=True)
session.chdir("hist")
session.install(".", *dependency_groups(pyproject, "test", "plot"))
session.install(".", *nox.project.dependency_groups(pyproject, "test", "plot"))
session.run("pip", "list")
session.run("pytest", *session.posargs)
session.run("pytest", *args)


@nox.session(reuse_venv=True, default=False)
Expand All @@ -64,7 +59,7 @@ def docs(session: nox.Session) -> None:
serve = args.builder == "html" and session.interactive

extra_installs = ["sphinx-autobuild"] if serve else []
session.install(*dependency_groups(pyproject, "docs"), *extra_installs)
session.install(*nox.project.dependency_groups(pyproject, "docs"), *extra_installs)

shared_args = (
"-n", # nitpicky mode
Expand All @@ -89,7 +84,7 @@ def build_api_docs(session: nox.Session) -> None:
"""
pyproject = nox.project.load_toml("pyproject.toml")

session.install(*dependency_groups(pyproject, "docs"))
session.install(*nox.project.dependency_groups(pyproject, "docs"))
session.run(
"sphinx-apidoc",
"-o",
Expand Down Expand Up @@ -129,5 +124,9 @@ def make_pickle(session: nox.Session) -> None:
Make a pickle file for this version
"""
pyproject = nox.project.load_toml("pyproject.toml")
session.install(".", *dependency_groups(pyproject, "dev"))
session.install(".", *nox.project.dependency_groups(pyproject, "dev"))
session.run("python", "tests/pickles/make_pickle.py", *session.posargs)


if __name__ == "__main__":
nox.main()
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ test = [
"hypothesis>=6.0",
"pytest-benchmark",
"pytest>=6.0",
"pytest-xdist",
]


Expand Down Expand Up @@ -161,13 +162,14 @@ ignore_missing_imports = true
[tool.cibuildwheel]
build-frontend = "build[uv]"
test-groups = ["test"]
test-command = "pytest --benchmark-disable {project}/tests"
test-command = "pytest -n auto --benchmark-disable {project}/tests"
skip = [
"pp38-*",
]
test-skip = [
"cp*-musllinux_*", # Segfaults
"cp313t-*win*",
"pp311-*", # no numpy wheels
]
enable = ["cpython-freethreading", "pypy"]
environment-pass = ["SETUPTOOLS_SCM_PRETEND_VERSION"]
Expand All @@ -177,6 +179,7 @@ environment.PIP_PREFER_BINARY = "1"
[[tool.cibuildwheel.overrides]]
select = "*pyodide*"
build-frontend = {name = "build", args = ["--exports", "whole_archive"]}
test-command = "pytest --benchmark-disable {project}/tests"

[[tool.cibuildwheel.overrides]]
select = "pp310-macosx_arm64"
Expand Down
Loading