Skip to content

Commit 8996163

Browse files
nox: support nox uv backend (#1757) (#1808)
Nox now has a separate venv backend that uses the Rust-based pip replacement, uv. Let's add support for this to our install function so that the constraints are respected when using the uv backend. (cherry picked from commit a74da7d) Co-authored-by: Maxwell G <[email protected]>
1 parent 8ead12f commit 8996163

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

noxfile.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import os
4+
import shlex
45
from argparse import ArgumentParser, BooleanOptionalAction
56
from glob import iglob
67
from pathlib import Path
@@ -17,11 +18,29 @@
1718
nox.options.sessions = ("clone-core", "lint", "checkers", "make")
1819

1920

21+
def _set_env_verbose(session: nox.Session, **env: str) -> dict[str, str]:
22+
"""
23+
Helper function to verbosely set environment variables
24+
"""
25+
final_env: dict[str, str] = {}
26+
for key, value in env.items():
27+
final_env[key] = value
28+
session.log(f"export {key}={shlex.quote(value)}")
29+
return final_env
30+
31+
2032
def install(session: nox.Session, *args, req: str, **kwargs):
2133
if PINNED:
2234
pip_constraint = f"tests/{req}.txt"
23-
kwargs.setdefault("env", {})["PIP_CONSTRAINT"] = pip_constraint
24-
session.log(f"export PIP_CONSTRAINT={pip_constraint!r}")
35+
# Set constraint environment variables for both pip and uv to support
36+
# the nox uv backend
37+
env = _set_env_verbose(
38+
session,
39+
PIP_CONSTRAINT=pip_constraint,
40+
UV_CONSTRAINT=pip_constraint,
41+
UV_BUILD_CONSTRAINT=pip_constraint,
42+
)
43+
kwargs.setdefault("env", {}).update(env)
2544
session.install("-r", f"tests/{req}.in", *args, **kwargs)
2645

2746

0 commit comments

Comments
 (0)