From 283423854bf9e678528c1f730674868be8dea3c8 Mon Sep 17 00:00:00 2001 From: mayeut Date: Wed, 19 Mar 2025 12:36:25 +0100 Subject: [PATCH 1/2] chore: use dependency-groups --- .github/workflows/build.yml | 19 ++++++++++++--- .pre-commit-config.yaml | 1 - noxfile.py | 48 ++++++++++++++++++++----------------- pyproject.toml | 15 ++++++------ 4 files changed, 50 insertions(+), 33 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8c0f6d7..eed491d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -70,7 +70,9 @@ jobs: uses: docker/setup-qemu-action@v3.6.0 if: runner.os == 'Linux' && runner.arch == 'X64' - - uses: yezz123/setup-uv@v4 + - uses: astral-sh/setup-uv@v5 + with: + enable-cache: false - name: Build wheels uses: pypa/cibuildwheel@v2.23.1 @@ -120,8 +122,19 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 name: Install Python ${{ matrix.python }} + id: python with: python-version: ${{ matrix.python }} + update-environment: false + + - uses: astral-sh/setup-uv@v5 + with: + enable-cache: false + + - name: Setup environment + run: | + uv venv --python "${{ steps.python.outputs.python-path }}" + uv pip install pip --group test - uses: actions/download-artifact@v4 with: @@ -145,10 +158,10 @@ jobs: done - name: Install SDist - run: pip install --no-binary=ninja $(ls sdist/*.tar.gz)[test] + run: .venv/bin/pip install --no-binary=ninja $(ls sdist/*.tar.gz) - name: Test installed SDist - run: pip check && pytest ./tests + run: .venv/bin/pip check && .venv/bin/pytest ./tests check_dist: name: Check dist diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0c8dadf..044dec0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -10,7 +10,6 @@ repos: - id: debug-statements - id: end-of-file-fixer - id: mixed-line-ending - - id: requirements-txt-fixer - id: trailing-whitespace - repo: https://github.com/astral-sh/ruff-pre-commit diff --git a/noxfile.py b/noxfile.py index 7bf5962..044992b 100644 --- a/noxfile.py +++ b/noxfile.py @@ -1,3 +1,7 @@ +# /// script +# dependencies = ["nox>=2025.2.9"] +# /// + from __future__ import annotations import argparse @@ -6,9 +10,8 @@ import nox -nox.needs_version = ">=2024.4.15" +nox.needs_version = ">=2025.2.9" nox.options.default_venv_backend = "uv|virtualenv" -nox.options.sessions = ["lint", "build", "tests"] if sys.platform.startswith("darwin"): BUILD_ENV = { @@ -18,7 +21,7 @@ else: BUILD_ENV = {} -built = "" +wheel = "" @nox.session @@ -26,21 +29,21 @@ def build(session: nox.Session) -> str: """ Make an SDist and a wheel. Only runs once. """ - global built # noqa: PLW0603 - if not built: - session.log( - "The files produced locally by this job are not intended to be redistributable" - ) - session.install("build") - tmpdir = session.create_tmp() - session.run("python", "-m", "build", "--outdir", tmpdir, env=BUILD_ENV) - (wheel_path,) = Path(tmpdir).glob("*.whl") - (sdist_path,) = Path(tmpdir).glob("*.tar.gz") - Path("dist").mkdir(exist_ok=True) - wheel_path.rename(f"dist/{wheel_path.name}") - sdist_path.rename(f"dist/{sdist_path.name}") - built = wheel_path.name - return built + session.log( + "The files produced locally by this job are not intended to be redistributable" + ) + extra = ["--installer=uv"] if session.venv_backend == "uv" else [] + session.install("build") + tmpdir = session.create_tmp() + session.run("python", "-m", "build", "--outdir", tmpdir, *extra, env=BUILD_ENV) + (wheel_path,) = Path(tmpdir).glob("*.whl") + (sdist_path,) = Path(tmpdir).glob("*.tar.gz") + Path("dist").mkdir(exist_ok=True) + wheel_path.rename(f"dist/{wheel_path.name}") + sdist_path.rename(f"dist/{sdist_path.name}") + + global wheel # noqa: PLW0603 + wheel = f"dist/{wheel_path.name}" @nox.session @@ -52,17 +55,18 @@ def lint(session: nox.Session) -> str: session.run("pre-commit", "run", "-a", *session.posargs) -@nox.session +@nox.session(requires=["build"]) def tests(session: nox.Session) -> str: """ Run the tests. """ - wheel = build(session) - session.install(f"./dist/{wheel}[test]") + pyproject = nox.project.load_toml("pyproject.toml") + deps = nox.project.dependency_groups(pyproject, "test") + session.install(wheel, *deps) session.run("pytest", *session.posargs) -@nox.session +@nox.session(default=False) def bump(session: nox.Session) -> None: """ Set to a new version, use -- , otherwise will use the latest version. diff --git a/pyproject.toml b/pyproject.toml index b7fafe2..e451621 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -34,12 +34,6 @@ classifiers = [ ] requires-python = ">=3.7" -[project.optional-dependencies] -test = [ - "importlib_metadata>=2.0", - "pytest>=6.0", -] - [project.urls] "Bug Tracker" = "https://github.com/scikit-build/ninja-python-distributions/issues" Documentation = "https://github.com/scikit-build/ninja-python-distributions#readme" @@ -48,6 +42,13 @@ Homepage = "http://ninja-build.org/" "Mailing list" = "https://groups.google.com/forum/#!forum/scikit-build" "Source Code" = "https://github.com/scikit-build/ninja-python-distributions" +[dependency-groups] +test = [ + "importlib_metadata>=2.0", + "pytest>=6.0", +] +dev = [{ include-group="test" }] + [tool.scikit-build] minimum-version = "build-system.requires" cmake.version = "CMakeLists.txt" # Force parsing version from CMakeLists.txt and disable fallback to '>=3.15' @@ -86,7 +87,7 @@ replacement = "" build = "cp39-*" build-frontend = "build[uv]" build-verbosity = 1 -test-extras = "test" +test-groups = "test" test-command = "pytest {project}/tests" test-skip = ["*-win_arm64", "*-macosx_universal2:arm64"] environment = { NINJA_PYTHON_DIST_ALLOW_NINJA_DEP = "1" } From e7063e7f703401791084ecea69e39deb4879e553 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Thu, 20 Mar 2025 17:37:37 -0400 Subject: [PATCH 2/2] chore: add the ability to run from generic runner --- noxfile.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/noxfile.py b/noxfile.py index 044992b..0baca02 100644 --- a/noxfile.py +++ b/noxfile.py @@ -122,3 +122,7 @@ def bump(session: nox.Session) -> None: session.log( 'Complete! Now run: gh pr create --fill --body "Created by running `nox -s bump -- --commit`"' ) + + +if __name__ == "__main__": + nox.main()