Skip to content

Commit 17ea716

Browse files
mayeuthenryiii
andauthored
chore: use dependency-groups (#292)
* chore: use dependency-groups * chore: add the ability to run from generic runner --------- Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com>
1 parent 7a70669 commit 17ea716

File tree

4 files changed

+54
-33
lines changed

4 files changed

+54
-33
lines changed

.github/workflows/build.yml

+16-3
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ jobs:
7171
uses: docker/setup-qemu-action@v3.6.0
7272
if: runner.os == 'Linux' && runner.arch == 'X64'
7373

74-
- uses: yezz123/setup-uv@v4
74+
- uses: astral-sh/setup-uv@v5
75+
with:
76+
enable-cache: false
7577

7678
- name: Build wheels
7779
uses: pypa/cibuildwheel@v2.23.1
@@ -122,8 +124,19 @@ jobs:
122124
- uses: actions/checkout@v4
123125
- uses: actions/setup-python@v5
124126
name: Install Python ${{ matrix.python }}
127+
id: python
125128
with:
126129
python-version: ${{ matrix.python }}
130+
update-environment: false
131+
132+
- uses: astral-sh/setup-uv@v5
133+
with:
134+
enable-cache: false
135+
136+
- name: Setup environment
137+
run: |
138+
uv venv --python "${{ steps.python.outputs.python-path }}"
139+
uv pip install pip --group test
127140
128141
- uses: actions/download-artifact@v4
129142
with:
@@ -147,10 +160,10 @@ jobs:
147160
done
148161
149162
- name: Install SDist
150-
run: pip install --no-binary=ninja $(ls sdist/*.tar.gz)[test]
163+
run: .venv/bin/pip install --no-binary=ninja $(ls sdist/*.tar.gz)
151164

152165
- name: Test installed SDist
153-
run: pip check && pytest ./tests
166+
run: .venv/bin/pip check && .venv/bin/pytest ./tests
154167

155168
check_dist:
156169
name: Check dist

.pre-commit-config.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ repos:
1010
- id: debug-statements
1111
- id: end-of-file-fixer
1212
- id: mixed-line-ending
13-
- id: requirements-txt-fixer
1413
- id: trailing-whitespace
1514

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

noxfile.py

+30-22
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# /// script
2+
# dependencies = ["nox>=2025.2.9"]
3+
# ///
4+
15
from __future__ import annotations
26

37
import argparse
@@ -6,9 +10,8 @@
610

711
import nox
812

9-
nox.needs_version = ">=2024.4.15"
13+
nox.needs_version = ">=2025.2.9"
1014
nox.options.default_venv_backend = "uv|virtualenv"
11-
nox.options.sessions = ["lint", "build", "tests"]
1215

1316
if sys.platform.startswith("darwin"):
1417
BUILD_ENV = {
@@ -18,29 +21,29 @@
1821
else:
1922
BUILD_ENV = {}
2023

21-
built = ""
24+
wheel = ""
2225

2326

2427
@nox.session
2528
def build(session: nox.Session) -> str:
2629
"""
2730
Make an SDist and a wheel. Only runs once.
2831
"""
29-
global built # noqa: PLW0603
30-
if not built:
31-
session.log(
32-
"The files produced locally by this job are not intended to be redistributable"
33-
)
34-
session.install("build")
35-
tmpdir = session.create_tmp()
36-
session.run("python", "-m", "build", "--outdir", tmpdir, env=BUILD_ENV)
37-
(wheel_path,) = Path(tmpdir).glob("*.whl")
38-
(sdist_path,) = Path(tmpdir).glob("*.tar.gz")
39-
Path("dist").mkdir(exist_ok=True)
40-
wheel_path.rename(f"dist/{wheel_path.name}")
41-
sdist_path.rename(f"dist/{sdist_path.name}")
42-
built = wheel_path.name
43-
return built
32+
session.log(
33+
"The files produced locally by this job are not intended to be redistributable"
34+
)
35+
extra = ["--installer=uv"] if session.venv_backend == "uv" else []
36+
session.install("build")
37+
tmpdir = session.create_tmp()
38+
session.run("python", "-m", "build", "--outdir", tmpdir, *extra, env=BUILD_ENV)
39+
(wheel_path,) = Path(tmpdir).glob("*.whl")
40+
(sdist_path,) = Path(tmpdir).glob("*.tar.gz")
41+
Path("dist").mkdir(exist_ok=True)
42+
wheel_path.rename(f"dist/{wheel_path.name}")
43+
sdist_path.rename(f"dist/{sdist_path.name}")
44+
45+
global wheel # noqa: PLW0603
46+
wheel = f"dist/{wheel_path.name}"
4447

4548

4649
@nox.session
@@ -52,17 +55,18 @@ def lint(session: nox.Session) -> str:
5255
session.run("pre-commit", "run", "-a", *session.posargs)
5356

5457

55-
@nox.session
58+
@nox.session(requires=["build"])
5659
def tests(session: nox.Session) -> str:
5760
"""
5861
Run the tests.
5962
"""
60-
wheel = build(session)
61-
session.install(f"./dist/{wheel}[test]")
63+
pyproject = nox.project.load_toml("pyproject.toml")
64+
deps = nox.project.dependency_groups(pyproject, "test")
65+
session.install(wheel, *deps)
6266
session.run("pytest", *session.posargs)
6367

6468

65-
@nox.session
69+
@nox.session(default=False)
6670
def bump(session: nox.Session) -> None:
6771
"""
6872
Set to a new version, use -- <version>, otherwise will use the latest version.
@@ -115,3 +119,7 @@ def bump(session: nox.Session) -> None:
115119
session.log(
116120
'Complete! Now run: gh pr create --fill --body "Created by running `nox -s bump -- --commit`"'
117121
)
122+
123+
124+
if __name__ == "__main__":
125+
nox.main()

pyproject.toml

+8-7
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,6 @@ classifiers = [
3434
]
3535
requires-python = ">=3.7"
3636

37-
[project.optional-dependencies]
38-
test = [
39-
"importlib_metadata>=2.0",
40-
"pytest>=6.0",
41-
]
42-
4337
[project.urls]
4438
"Bug Tracker" = "https://github.com/scikit-build/ninja-python-distributions/issues"
4539
Documentation = "https://github.com/scikit-build/ninja-python-distributions#readme"
@@ -48,6 +42,13 @@ Homepage = "http://ninja-build.org/"
4842
"Mailing list" = "https://groups.google.com/forum/#!forum/scikit-build"
4943
"Source Code" = "https://github.com/scikit-build/ninja-python-distributions"
5044

45+
[dependency-groups]
46+
test = [
47+
"importlib_metadata>=2.0",
48+
"pytest>=6.0",
49+
]
50+
dev = [{ include-group="test" }]
51+
5152
[tool.scikit-build]
5253
minimum-version = "build-system.requires"
5354
cmake.version = "CMakeLists.txt" # Force parsing version from CMakeLists.txt and disable fallback to '>=3.15'
@@ -87,7 +88,7 @@ replacement = ""
8788
build = "cp39-*"
8889
build-frontend = "build[uv]"
8990
build-verbosity = 1
90-
test-extras = "test"
91+
test-groups = "test"
9192
test-command = "pytest {project}/tests"
9293
test-skip = ["*-win_arm64", "*-macosx_universal2:arm64"]
9394
environment = { NINJA_PYTHON_DIST_ALLOW_NINJA_DEP = "1" }

0 commit comments

Comments
 (0)