Skip to content

Commit fd392f8

Browse files
fix: use uvx prefix for all third-party commands in nox sessions
1 parent ff82295 commit fd392f8

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

noxfile.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@ def install_with_uv(session: nox.Session, extras: list[str] | None = None) -> No
4141
session.install("ruff") # Explicitly install ruff
4242
if extras:
4343
session.run("uv", "sync", *(f"--extra={extra}" for extra in extras))
44-
# Install pytest and related packages for test sessions
45-
if any(extra == "dev" for extra in extras):
46-
session.install("pytest", "pytest-cov", "pytest-mock")
4744
else:
4845
session.run("uv", "sync")
4946

@@ -62,8 +59,8 @@ def lint(session: nox.Session) -> None:
6259
install_with_uv(session, extras=["dev"])
6360

6461
# Run ruff checks
65-
session.run("ruff", "check", ".")
66-
session.run("ruff", "format", "--check", ".")
62+
session.run("uvx", "ruff", "check", ".")
63+
session.run("uvx", "ruff", "format", "--check", ".")
6764

6865

6966
@nox.session(python=PYTHON_VERSIONS[-1], reuse_venv=True)
@@ -81,6 +78,7 @@ def test(session: nox.Session) -> None:
8178

8279
# Run pytest with coverage
8380
session.run(
81+
"uvx",
8482
"pytest",
8583
"--cov=repo_scaffold",
8684
"--cov-report=term-missing",
@@ -117,7 +115,7 @@ def test_all(session: nox.Session) -> None:
117115
] + test_args
118116

119117
# 运行测试
120-
session.run("pytest", *test_args)
118+
session.run("uvx","pytest", *test_args)
121119

122120

123121
@nox.session(reuse_venv=True)
@@ -130,7 +128,7 @@ def build(session: nox.Session) -> None:
130128
session: Nox session object for running commands
131129
"""
132130
install_with_uv(session, extras=["dev"])
133-
session.run("python", "-m", "build")
131+
session.run("uv","build")
134132

135133

136134
@nox.session(reuse_venv=True)
@@ -198,8 +196,8 @@ def baseline(session: nox.Session) -> None:
198196
install_with_uv(session, extras=["dev"])
199197

200198
# 运行 ruff 并自动修复所有问题
201-
session.run("ruff", "check", ".", "--add-noqa")
202-
session.run("ruff", "format", ".")
199+
session.run("uvx","ruff", "check", ".", "--add-noqa")
200+
session.run("uvx","ruff", "format", ".")
203201

204202

205203
@nox.session(reuse_venv=True)
@@ -212,7 +210,7 @@ def docs(session: nox.Session) -> None:
212210
session: Nox session object for running commands
213211
"""
214212
install_with_uv(session, extras=["docs"])
215-
session.run("mkdocs", "build")
213+
session.run("uvx","mkdocs", "build")
216214

217215

218216
@nox.session(reuse_venv=True)
@@ -225,4 +223,4 @@ def docs_serve(session: nox.Session) -> None:
225223
session: Nox session object for running commands
226224
"""
227225
install_with_uv(session, extras=["docs"])
228-
session.run("mkdocs", "serve")
226+
session.run("uvx","mkdocs", "serve")

repo_scaffold/templates/template-python/{{cookiecutter.project_slug}}/noxfile.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ def lint(session: nox.Session) -> None:
6565
install_with_uv(session, extras=["dev"])
6666

6767
# Run ruff checks
68-
session.run("ruff", "check", ".")
69-
session.run("ruff", "format", "--check", ".")
68+
session.run("uvx", "ruff", "check", ".")
69+
session.run("uvx", "ruff", "format", "--check", ".")
7070

7171

7272
@nox.session(python=PYTHON_VERSIONS[-1], reuse_venv=True)
@@ -84,6 +84,7 @@ def test(session: nox.Session) -> None:
8484

8585
# Run pytest with coverage
8686
session.run(
87+
"uvx",
8788
"pytest",
8889
"--cov={{cookiecutter.project_slug}}",
8990
"--cov-report=term-missing",
@@ -120,7 +121,7 @@ def test_all(session: nox.Session) -> None:
120121
] + test_args
121122

122123
# 运行测试
123-
session.run("pytest", *test_args)
124+
session.run("uvx", "pytest", *test_args)
124125

125126

126127
@nox.session(reuse_venv=True)
@@ -133,7 +134,7 @@ def build(session: nox.Session) -> None:
133134
session: Nox session object for running commands
134135
"""
135136
install_with_uv(session, extras=["dev"])
136-
session.run("python", "-m", "build")
137+
session.run("uv", "build")
137138

138139

139140
@nox.session(reuse_venv=True)
@@ -201,8 +202,8 @@ def baseline(session: nox.Session) -> None:
201202
install_with_uv(session, extras=["dev"])
202203

203204
# 运行 ruff 并自动修复所有问题
204-
session.run("ruff", "check", ".", "--add-noqa")
205-
session.run("ruff", "format", ".")
205+
session.run("uvx", "ruff", "check", ".", "--add-noqa")
206+
session.run("uvx", "ruff", "format", ".")
206207

207208

208209
{% if cookiecutter.use_mkdocs == "yes" %}
@@ -216,7 +217,7 @@ def docs(session: nox.Session) -> None:
216217
session: Nox session object for running commands
217218
"""
218219
install_with_uv(session, extras=["docs"])
219-
session.run("mkdocs", "build")
220+
session.run("uvx", "mkdocs", "build")
220221

221222

222223
@nox.session(reuse_venv=True)
@@ -229,5 +230,5 @@ def docs_serve(session: nox.Session) -> None:
229230
session: Nox session object for running commands
230231
"""
231232
install_with_uv(session, extras=["docs"])
232-
session.run("mkdocs", "serve")
233+
session.run("uvx", "mkdocs", "serve")
233234
{% endif %}

0 commit comments

Comments
 (0)