Skip to content

Commit efdd39a

Browse files
committed
Update noxfile to use uv
The `session.install()` process uses `uv pip ...` under the hood. This ends up installing all the dependencies of the project. While fast, this is not ideal. Replaced that with an explict `uv sync` call using `session.run()` Removed update, upgrade, and install sessions as they no longer apply.
1 parent 937aa5a commit efdd39a

File tree

1 file changed

+26
-74
lines changed

1 file changed

+26
-74
lines changed

noxfile.py

Lines changed: 26 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,18 @@
11
from __future__ import annotations
22

3-
import os
3+
import functools
44
import pathlib
55
import shutil
6-
import sys
76

87
import nox
98

109
# Control factors for finding pieces of the module
1110
MODULE_NAME = "module_name"
1211
TESTS_PATH = "tests"
1312
COVERAGE_FAIL_UNDER = 50
14-
DEFAULT_PYTHON_VERSION = "3.12"
13+
DEFAULT_PYTHON_VERSION = None
1514
PYTHON_MATRIX = ["3.9", "3.10", "3.11", "3.12", "3.13"]
16-
VENV_BACKEND = "venv"
17-
VENV_PATH = ".venv"
18-
REQUIREMENT_IN_FILES = [
19-
pathlib.Path("requirements/requirements.in"),
20-
]
15+
VENV_BACKEND = "uv"
2116

2217
# What we allowed to clean (delete)
2318
CLEANABLE_TARGETS = [
@@ -47,98 +42,55 @@
4742
def version_coverage(session: nox.Session) -> None:
4843
"""Run unit tests with coverage saved to partial file."""
4944
print_standard_logs(session)
45+
uv_run = functools.partial(session.run, "uv", "run", "--active")
5046

51-
session.install(".[test]")
52-
session.run("coverage", "run", "-p", "-m", "pytest", TESTS_PATH)
47+
session.run("uv", "sync", "--active", "--no-dev", "--group", "test")
48+
uv_run("coverage", "run", "-p", "-m", "pytest", TESTS_PATH)
5349

5450

5551
@nox.session(python=DEFAULT_PYTHON_VERSION, venv_backend=VENV_BACKEND)
5652
def coverage_combine(session: nox.Session) -> None:
5753
"""Combine all coverage partial files and generate JSON report."""
5854
print_standard_logs(session)
55+
uv_run = functools.partial(session.run, "uv", "run", "--active")
5956

60-
fail_under = f"--fail-under={COVERAGE_FAIL_UNDER}"
61-
62-
session.install(".[test]")
63-
session.run("python", "-m", "coverage", "combine")
64-
session.run("python", "-m", "coverage", "report", "-m", fail_under)
65-
session.run("python", "-m", "coverage", "json")
57+
session.run("uv", "sync", "--active", "--no-dev", "--group", "test")
58+
uv_run("coverage", "combine")
59+
uv_run("coverage", "report", "-m", f"--fail-under={COVERAGE_FAIL_UNDER}")
60+
uv_run("coverage", "json")
6661

6762

6863
@nox.session(python=DEFAULT_PYTHON_VERSION, venv_backend=VENV_BACKEND)
6964
def mypy(session: nox.Session) -> None:
7065
"""Run mypy against package and all required dependencies."""
7166
print_standard_logs(session)
67+
uv_run = functools.partial(session.run, "uv", "run", "--active")
7268

73-
session.install(".")
74-
session.install("mypy")
75-
session.run("mypy", "-p", MODULE_NAME, "--no-incremental")
69+
session.run("uv", "sync", "--active", "--no-dev", "--group", "lint")
70+
uv_run("mypy", "-p", MODULE_NAME, "--no-incremental")
7671

7772

78-
@nox.session(python=False, venv_backend=VENV_BACKEND)
73+
@nox.session(python=DEFAULT_PYTHON_VERSION, venv_backend=VENV_BACKEND)
7974
def coverage(session: nox.Session) -> None:
8075
"""Generate a coverage report. Does not use a venv."""
81-
session.run("coverage", "erase")
82-
session.run("coverage", "run", "-m", "pytest", TESTS_PATH)
83-
session.run("coverage", "report", "-m")
84-
85-
86-
@nox.session(python=DEFAULT_PYTHON_VERSION, venv_backend=VENV_BACKEND)
87-
def build(session: nox.Session) -> None:
88-
"""Build distribution files."""
8976
print_standard_logs(session)
77+
uv_run = functools.partial(session.run, "uv", "run", "--active")
9078

91-
session.install("build")
92-
session.run("python", "-m", "build")
79+
session.run("uv", "sync", "--active", "--no-dev", "--group", "test")
80+
uv_run("coverage", "erase")
81+
uv_run("coverage", "run", "-m", "pytest", TESTS_PATH)
82+
uv_run("coverage", "report", "-m")
83+
uv_run("coverage", "html")
9384

9485

9586
@nox.session(python=False, venv_backend=VENV_BACKEND)
96-
def install(session: nox.Session) -> None:
97-
"""Setup a development environment. Uses active venv if available, builds one if not."""
98-
# Use the active environement if it exists, otherwise create a new one
99-
venv_path = os.environ.get("VIRTUAL_ENV", VENV_PATH)
100-
101-
if sys.platform == "win32":
102-
py_command = "py"
103-
venv_path = f"{venv_path}/Scripts"
104-
activate_command = f"{venv_path}/activate"
105-
else:
106-
py_command = f"python{DEFAULT_PYTHON_VERSION}"
107-
venv_path = f"{venv_path}/bin"
108-
activate_command = f"source {venv_path}/activate"
109-
110-
if not os.path.exists(VENV_PATH):
111-
session.run(py_command, "-m", "venv", VENV_PATH, "--upgrade-deps")
112-
113-
session.run(f"{venv_path}/python", "-m", "pip", "install", "-e", ".[dev,test]")
114-
session.run(f"{venv_path}/pre-commit", "install")
115-
116-
if not venv_path:
117-
session.log(f"\n\nRun '{activate_command}' to enter the virtual environment.\n")
118-
119-
120-
@nox.session(python=DEFAULT_PYTHON_VERSION, venv_backend=VENV_BACKEND)
121-
def update(session: nox.Session) -> None:
122-
"""Process requirement*.in files, updating only additions/removals."""
123-
print_standard_logs(session)
124-
125-
session.install("pip-tools")
126-
for filename in REQUIREMENT_IN_FILES:
127-
session.run("pip-compile", "--no-emit-index-url", str(filename))
128-
129-
130-
@nox.session(python=DEFAULT_PYTHON_VERSION, venv_backend=VENV_BACKEND)
131-
def upgrade(session: nox.Session) -> None:
132-
"""Process requirement*.in files and upgrade all libraries as possible."""
133-
print_standard_logs(session)
134-
135-
session.install("pip-tools")
136-
for filename in REQUIREMENT_IN_FILES:
137-
session.run("pip-compile", "--no-emit-index-url", "--upgrade", str(filename))
87+
def build(session: nox.Session) -> None:
88+
"""Generate sdist and wheel."""
89+
session.run("uv", "build")
13890

13991

14092
@nox.session(python=False, venv_backend=VENV_BACKEND)
141-
def clean(_: nox.Session) -> None:
93+
def clean(session: nox.Session) -> None:
14294
"""Clean cache, .pyc, .pyo, and test/build artifact files from project."""
14395
count = 0
14496
for searchpath in CLEANABLE_TARGETS:
@@ -149,7 +101,7 @@ def clean(_: nox.Session) -> None:
149101
filepath.unlink()
150102
count += 1
151103

152-
print(f"{count} files cleaned.")
104+
session.log(f"{count} files cleaned.")
153105

154106

155107
def print_standard_logs(session: nox.Session) -> None:

0 commit comments

Comments
 (0)