From 447d4c5acbf0916af227ec8d0fb8da32db88a38c Mon Sep 17 00:00:00 2001 From: Julian Berman Date: Mon, 8 Jul 2024 18:26:14 -0400 Subject: [PATCH] uv in the noxfile and CI. --- .github/workflows/CI.yml | 3 +++ noxfile.py | 31 +++++++++++++++++-------------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 35eaadd..221355d 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -66,8 +66,11 @@ jobs: 3.13 pypy3.10 allow-prereleases: true + - name: Set up uv + uses: hynek/setup-cached-uv@v1 - name: Set up nox uses: wntrblm/nox@2024.04.15 + - name: Run nox run: nox -s "${{ matrix.noxenv }}" diff --git a/noxfile.py b/noxfile.py index 4b81a5e..ba4719f 100644 --- a/noxfile.py +++ b/noxfile.py @@ -5,21 +5,22 @@ import nox ROOT = Path(__file__).parent -TESTS = ROOT / "tests" PYPROJECT = ROOT / "pyproject.toml" DOCS = ROOT / "docs" +TESTS = ROOT / "tests" REQUIREMENTS = dict( docs=DOCS / "requirements.txt", tests=TESTS / "requirements.txt", ) REQUIREMENTS_IN = [ # this is actually ordered, as files depend on each other - path.parent / f"{path.stem}.in" for path in REQUIREMENTS.values() + (path.parent / f"{path.stem}.in", path) for path in REQUIREMENTS.values() ] -SUPPORTED = ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "pypy3.10"] +SUPPORTED = ["3.8", "3.9", "3.10", "pypy3.10", "3.11", "3.12", "3.13"] LATEST = "3.12" +nox.options.default_venv_backend = "uv|virtualenv" nox.options.sessions = [] @@ -145,15 +146,17 @@ def docs_style(session): @session(default=False) def requirements(session): """ - Update the project's pinned requirements. Commit the result. + Update the project's pinned requirements. + + You should commit the result afterwards. """ - session.install("pip-tools") - for each in REQUIREMENTS_IN: - session.run( - "pip-compile", - "--resolver", - "backtracking", - "--strip-extras", - "-U", - each.relative_to(ROOT), - ) + if session.venv_backend == "uv": + cmd = ["uv", "pip", "compile"] + else: + session.install("pip-tools") + cmd = ["pip-compile", "--resolver", "backtracking", "--strip-extras"] + + for each, out in REQUIREMENTS_IN: + # otherwise output files end up with silly absolute path comments... + relative = each.relative_to(ROOT) + session.run(*cmd, "--upgrade", "--output-file", out, relative)