Nox-UV Integration
Nox-UV facilitates the integration of `uv`, a fast Python package installer and resolver, into `nox` sessions. It streamlines dependency management and session setup for testing, linting, and other development tasks, leveraging `uv`'s performance benefits. The current version is 0.7.1, and the library maintains an active development pace with frequent updates.
Common errors
-
uv: command not found
cause The `uv` executable is not installed or not available in the system's PATH.fixInstall `uv` using `pip install uv` (if you have pipx) or `cargo install uv`. Ensure its installation directory is in your PATH. -
NameError: name 'uvsession' is not defined
cause The `uvsession` decorator was not correctly imported from `nox_uv`.fixAdd `from nox_uv import uvsession` to the top of your `noxfile.py`. -
nox.session must be passed as a decorator.
cause You are using `uvsession` as a regular function call instead of a decorator.fixEnsure `@uvsession` is placed directly above your session function definition (e.g., `@uvsession(...) def mysession(...)`). -
nox.virtualenv.VirtualEnv.install: uv is not a valid dependency name or path.
cause You might be trying to install `uv` itself using `session.install('uv')` inside a `nox-uv` session. `uv` needs to be globally available or managed outside the specific session.fix`uv` is expected to be present in the environment where Nox runs. Do not attempt to install `uv` *within* a `nox-uv` managed session.
Warnings
- gotcha The `uv` executable must be installed and accessible in the system's PATH or within the Nox virtual environment. `nox-uv` is a bridge, not a `uv` installer.
- breaking Handling of project `extras` changed significantly in v0.3.0 (removed arbitrary extras) and was refined in v0.7.0 (allowing exclusion of specific groups). Old `session.install` calls might behave differently.
- gotcha From v0.7.1, a `uv_quiet` option was added to suppress `uv sync` output for cleaner logs. If you're missing this option, you're on an older version.
- gotcha For scenarios where the current project should *not* be installed into the session's environment, use `uv_no_project_install=True`.
Install
-
pip install nox-uv
Imports
- uvsession
import nox_uv.uvsession
from nox_uv import uvsession
Quickstart
import nox
from nox_uv import uvsession
@uvsession(python=["3.9", "3.10", "3.11", "3.12"])
def test(session: uvsession):
# Installs project and test dependencies using uv
session.install("-e", ".[test]")
session.run("pytest", *session.posargs)
@uvsession(python="3.12")
def lint(session: uvsession):
# Installs ruff using uv
session.install("ruff")
session.run("ruff", "check", ".")
session.run("ruff", "format", "--check", ".")