Skip to content

Commit 8c35f2f

Browse files
committed
Use nox.options instead of global variable
Move the declaration of the backend to a `nox.options` declaration instead of passing an extra variable to each `@session`.
1 parent 6b34d20 commit 8c35f2f

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

noxfile.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
COVERAGE_FAIL_UNDER = 50
1414
DEFAULT_PYTHON = "3.12"
1515
PYTHON_MATRIX = ["3.9", "3.10", "3.11", "3.12", "3.13"]
16-
VENV_BACKEND = "venv"
1716
VENV_PATH = ".venv"
1817
REQUIREMENTS_PATH = "./requirements"
1918

@@ -32,8 +31,8 @@
3231
"./**/*.pyo",
3332
]
3433

35-
3634
# Define the default sessions run when `nox` is called on the CLI
35+
nox.options.default_venv_backend = "uv|virtualenv"
3736
nox.options.sessions = [
3837
"version_coverage",
3938
"coverage_combine",
@@ -73,7 +72,7 @@ def dev(session: nox.Session) -> None:
7372
session.log(f"\n\nRun '{activate_command}' to enter the virtual environment.\n")
7473

7574

76-
@nox.session(python=PYTHON_MATRIX, venv_backend=VENV_BACKEND)
75+
@nox.session(python=PYTHON_MATRIX)
7776
def version_coverage(session: nox.Session) -> None:
7877
"""Run unit tests with coverage saved to partial file."""
7978
print_standard_logs(session)
@@ -84,7 +83,7 @@ def version_coverage(session: nox.Session) -> None:
8483
session.run("coverage", "run", "-p", "-m", "pytest", TESTS_PATH)
8584

8685

87-
@nox.session(python=DEFAULT_PYTHON, venv_backend=VENV_BACKEND)
86+
@nox.session(python=DEFAULT_PYTHON)
8887
def coverage_combine(session: nox.Session) -> None:
8988
"""Combine all coverage partial files and generate JSON report."""
9089
print_standard_logs(session)
@@ -99,7 +98,7 @@ def coverage_combine(session: nox.Session) -> None:
9998
session.run("python", "-m", "coverage", "json")
10099

101100

102-
@nox.session(python=DEFAULT_PYTHON, venv_backend=VENV_BACKEND)
101+
@nox.session(python=DEFAULT_PYTHON)
103102
def mypy(session: nox.Session) -> None:
104103
"""Run mypy against package and all required dependencies."""
105104
print_standard_logs(session)
@@ -110,15 +109,15 @@ def mypy(session: nox.Session) -> None:
110109
session.run("mypy", "-p", MODULE_NAME, "--no-incremental")
111110

112111

113-
@nox.session(python=False, venv_backend=VENV_BACKEND)
112+
@nox.session(python=False)
114113
def coverage(session: nox.Session) -> None:
115114
"""Generate a coverage report. Does not use a venv."""
116115
session.run("coverage", "erase")
117116
session.run("coverage", "run", "-m", "pytest", TESTS_PATH)
118117
session.run("coverage", "report", "-m")
119118

120119

121-
@nox.session(python=DEFAULT_PYTHON, venv_backend=VENV_BACKEND)
120+
@nox.session(python=DEFAULT_PYTHON)
122121
def build(session: nox.Session) -> None:
123122
"""Build distribution files."""
124123
print_standard_logs(session)
@@ -127,7 +126,7 @@ def build(session: nox.Session) -> None:
127126
session.run("python", "-m", "build")
128127

129128

130-
@nox.session(python=DEFAULT_PYTHON, venv_backend=VENV_BACKEND, name="update-deps")
129+
@nox.session(python=DEFAULT_PYTHON, name="update-deps")
131130
def update_deps(session: nox.Session) -> None:
132131
"""Process requirement*.txt files, updating only additions/removals."""
133132
print_standard_logs(session)
@@ -145,7 +144,7 @@ def update_deps(session: nox.Session) -> None:
145144
)
146145

147146

148-
@nox.session(python=DEFAULT_PYTHON, venv_backend=VENV_BACKEND, name="upgrade-deps")
147+
@nox.session(python=DEFAULT_PYTHON, name="upgrade-deps")
149148
def upgrade_deps(session: nox.Session) -> None:
150149
"""Process requirement*.txt files and upgrade all libraries as possible."""
151150
print_standard_logs(session)
@@ -164,7 +163,7 @@ def upgrade_deps(session: nox.Session) -> None:
164163
)
165164

166165

167-
@nox.session(python=False, venv_backend=VENV_BACKEND)
166+
@nox.session(python=False)
168167
def clean(_: nox.Session) -> None:
169168
"""Clean cache, .pyc, .pyo, and test/build artifact files from project."""
170169
count = 0

0 commit comments

Comments
 (0)