Skip to content

Commit c131701

Browse files
henryiiimayeut
andauthored
chore: use dependency-groups (#589)
* chore: use dependency-groups Signed-off-by: Henry Schreiner <[email protected]> * Apply suggestions from code review Co-authored-by: Matthieu Darbois <[email protected]> --------- Signed-off-by: Henry Schreiner <[email protected]> Co-authored-by: Matthieu Darbois <[email protected]>
1 parent f0045f4 commit c131701

File tree

6 files changed

+68
-53
lines changed

6 files changed

+68
-53
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,6 @@ wheelhouse/
6767

6868
# Version
6969
_version.py
70+
71+
CMakeCache.txt
72+
CMakeFiles

.pre-commit-config.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ repos:
1414
- id: debug-statements
1515
- id: end-of-file-fixer
1616
- id: mixed-line-ending
17-
- id: requirements-txt-fixer
1817
- id: trailing-whitespace
1918

2019
- repo: https://github.com/astral-sh/ruff-pre-commit

.readthedocs.yaml

+5-7
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@
33

44
version: 2
55

6-
sphinx:
7-
configuration: docs/conf.py
8-
96
build:
107
os: ubuntu-22.04
118
tools:
129
python: "3.12"
13-
14-
python:
15-
install:
16-
- requirements: docs/requirements.txt
10+
commands:
11+
- asdf plugin add uv
12+
- asdf install uv latest
13+
- asdf global uv latest
14+
- uv run --only-group docs sphinx-build -T -b html -d docs/_build/doctrees -D language=en docs $READTHEDOCS_OUTPUT/html

docs/requirements.txt

-7
This file was deleted.

noxfile.py

+35-30
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,44 @@
1+
# /// script
2+
# dependencies = ["nox>=2025.2.9"]
3+
# ///
4+
15
import argparse
26
import re
37
from pathlib import Path
48

59
import nox
610

7-
nox.needs_version = ">=2024.3.2"
11+
nox.needs_version = ">=2025.2.9"
812
nox.options.default_venv_backend = "uv|virtualenv"
9-
nox.options.sessions = ["lint", "build", "tests"]
1013

1114
BUILD_ENV = {
1215
"MACOSX_DEPLOYMENT_TARGET": "10.10",
1316
"ARCHFLAGS": "-arch x86_64 -arch arm64",
1417
}
1518

16-
built = ""
19+
wheel = ""
1720

1821

1922
@nox.session
2023
def build(session: nox.Session) -> str:
2124
"""
22-
Make an SDist and a wheel. Only runs once.
25+
Make an SDist and a wheel.
2326
"""
24-
global built
25-
if not built:
26-
session.log(
27-
"The files produced locally by this job are not intended to be redistributable"
28-
)
29-
session.install("build")
30-
tmpdir = session.create_tmp()
31-
session.run("python", "-m", "build", "--outdir", tmpdir, env=BUILD_ENV)
32-
(wheel_path,) = Path(tmpdir).glob("*.whl")
33-
(sdist_path,) = Path(tmpdir).glob("*.tar.gz")
34-
Path("dist").mkdir(exist_ok=True)
35-
wheel_path.rename(f"dist/{wheel_path.name}")
36-
sdist_path.rename(f"dist/{sdist_path.name}")
37-
built = wheel_path.name
38-
return built
27+
session.log(
28+
"The files produced locally by this job are not intended to be redistributable"
29+
)
30+
extra = ["--installer=uv"] if session.venv_backend == "uv" else []
31+
session.install("build")
32+
tmpdir = session.create_tmp()
33+
session.run("python", "-m", "build", "--outdir", tmpdir, *extra, env=BUILD_ENV)
34+
(wheel_path,) = Path(tmpdir).glob("*.whl")
35+
(sdist_path,) = Path(tmpdir).glob("*.tar.gz")
36+
Path("dist").mkdir(exist_ok=True)
37+
wheel_path.rename(f"dist/{wheel_path.name}")
38+
sdist_path.rename(f"dist/{sdist_path.name}")
39+
40+
global wheel
41+
wheel = f"dist/{wheel_path.name}"
3942

4043

4144
@nox.session
@@ -47,32 +50,34 @@ def lint(session: nox.Session) -> str:
4750
session.run("pre-commit", "run", "-a")
4851

4952

50-
@nox.session
53+
@nox.session(requires=["build"])
5154
def tests(session: nox.Session) -> str:
5255
"""
5356
Run the tests.
5457
"""
55-
wheel = build(session)
56-
session.install(f"./dist/{wheel}[test]")
58+
pyproject = nox.project.load_toml("pyproject.toml")
59+
deps = nox.project.dependency_groups(pyproject, "test")
60+
session.install(wheel, *deps)
5761
session.run("pytest", *session.posargs)
5862

5963

60-
@nox.session(reuse_venv=True)
64+
@nox.session(reuse_venv=True, default=False)
6165
def docs(session: nox.Session) -> None:
6266
"""
6367
Build the docs. Pass "--non-interactive" to avoid serve. Pass "-- -b linkcheck" to check links.
6468
"""
69+
pyproject = nox.project.load_toml("pyproject.toml")
70+
deps = nox.project.dependency_groups(pyproject, "docs")
6571

6672
parser = argparse.ArgumentParser()
67-
parser.add_argument("--serve", action="store_true", help="Serve after building")
6873
parser.add_argument(
6974
"-b", dest="builder", default="html", help="Build target (default: html)"
7075
)
7176
args, posargs = parser.parse_known_args(session.posargs)
7277
serve = args.builder == "html" and session.interactive
7378

7479
extra_installs = ["sphinx-autobuild"] if serve else []
75-
session.install("-r", "docs/requirements.txt", *extra_installs)
80+
session.install(*deps, *extra_installs)
7681
session.chdir("docs")
7782

7883
if args.builder == "linkcheck":
@@ -130,7 +135,7 @@ def _bump(session: nox.Session, name: str, repository: str, branch: str, script:
130135
)
131136

132137

133-
@nox.session
138+
@nox.session(default=False)
134139
def bump(session: nox.Session) -> None:
135140
"""
136141
Set to a new version, use -- <version>, otherwise will use the latest version.
@@ -146,7 +151,7 @@ def bump(session: nox.Session) -> None:
146151
_bump(session, "CMake", "kitware/cmake", "", "scripts/update_cmake_version.py", files)
147152

148153

149-
@nox.session(name="bump-openssl")
154+
@nox.session(name="bump-openssl", default=False)
150155
def bump_openssl(session: nox.Session) -> None:
151156
"""
152157
Set openssl to a new version, use -- <version>, otherwise will use the latest version.
@@ -162,7 +167,7 @@ def _get_version() -> str:
162167
return next(iter(re.finditer(r'^version = "([\d\.]+)"$', txt, flags=re.MULTILINE))).group(1)
163168

164169

165-
@nox.session(venv_backend="none")
170+
@nox.session(venv_backend="none", default=False)
166171
def tag_release(session: nox.Session) -> None:
167172
"""
168173
Print instructions for tagging a release and pushing it to GitHub.
@@ -174,7 +179,7 @@ def tag_release(session: nox.Session) -> None:
174179
print(f"git push origin {current_version}")
175180

176181

177-
@nox.session(venv_backend="none")
182+
@nox.session(venv_backend="none", default=False)
178183
def cmake_version(session: nox.Session) -> None: # noqa: ARG001
179184
"""
180185
Print upstream cmake version.
@@ -184,7 +189,7 @@ def cmake_version(session: nox.Session) -> None: # noqa: ARG001
184189
print(".".join(current_version.split(".")[:3]))
185190

186191

187-
@nox.session(venv_backend="none")
192+
@nox.session(venv_backend="none", default=False)
188193
def openssl_version(session: nox.Session) -> None: # noqa: ARG001
189194
"""
190195
Print upstream OpenSSL version.

pyproject.toml

+25-8
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,31 @@ Source = "https://github.com/scikit-build/cmake-python-distributions"
3838
"Mailing list" = "https://groups.google.com/forum/#!forum/scikit-build"
3939
"Bug Tracker" = "https://github.com/scikit-build/cmake-python-distributions/issues"
4040

41-
[project.optional-dependencies]
42-
test = [
43-
"coverage>=4.2",
44-
"pytest>=3.0.3",
45-
"pytest-cov>=2.4.0",
46-
]
47-
4841
[project.scripts]
4942
ccmake = "cmake:ccmake"
5043
cmake = "cmake:cmake"
5144
cpack = "cmake:cpack"
5245
ctest = "cmake:ctest"
5346

47+
48+
[dependency-groups]
49+
test = [
50+
"coverage>=4.2",
51+
"pytest>=6",
52+
"pytest-cov>=2.4.0",
53+
]
54+
docs = [
55+
"docutils",
56+
"funcparserlib>=1.0.0",
57+
"furo",
58+
"pygments",
59+
"sphinx",
60+
"sphinxcontrib-mermaid",
61+
"tomli; python_version<'3.11'",
62+
]
63+
dev = [{ include-group="test" }]
64+
65+
5466
[tool.scikit-build]
5567
minimum-version = "build-system.requires"
5668
build-dir = "build/{wheel_tag}"
@@ -76,9 +88,14 @@ wheel.cmake = false
7688
wheel.platlib = true
7789

7890

91+
[tool.pytest.ini_options]
92+
minversion = "6.0"
93+
testpaths = ["tests"]
94+
95+
7996
[tool.cibuildwheel]
8097
build = "cp39-*"
81-
test-extras = "test"
98+
test-groups = ["test"]
8299
test-command = "pytest {project}/tests"
83100
build-verbosity = 1
84101
build-frontend = "build[uv]"

0 commit comments

Comments
 (0)