Add a variant of a nox script runner that entirely delegates to uv run - #1095
Add a variant of a nox script runner that entirely delegates to uv run#1095agriyakhetarpal wants to merge 11 commits into
uv run#1095Conversation
|
What is the difference to just using |
|
Feedback on the design welcome! The conda test failures are unrelated; I'm investigating them. |
@henryiii I'd say that it's just nicer. We sidestep the fact that we could be using the wrong/different |
|
We already have special handling to ensure |
|
Or a generic |
|
Hmm, I think we could. Do you mean something like: def run_script(self, script, *args, uv_args=(), ...):
if nox.virtualenv.HAS_UV:
# uv owns the environment
return self.run(nox.virtualenv.UV, "run", *uv_args, script, *args, external=True, ...)
else:
# fallback: install deps into session venv, run with python
if uv_args:
msg = "uv_args requires uv to be installed."
raise ValueError(msg)
deps = (nox.project.load_toml(script) or {}).get("dependencies", [])
self.install(*deps)
return self.run("python", script, *args, ...)I considered that at first, but I didn't do it because it felt a bit odd, and Or do you think it's better to close this PR? Thanks! |
This PR adds a
session.uv_run_script()to complement thesession.install_and_run_script()session method. Whileinstall_and_run_scriptinstalls PEP 723 dependencies into the session's own virtualenv and runs with Python,uv_run_scriptdelegates the entire run touv run, souvowns environment creation, dependency resolution, caching, and so on.I've added docs and tests, and some test plumbing in this PR that I found useful to include.
cc: @henryiii
xref pypa/cibuildwheel#2873 (comment)
some use cases
tool.uv.sources(git, path, or workspace overrides, etc.),tool.uv.indexfor custom indices, ortool.uv.exclude-newerare silently ignored byinstall_and_run_scriptbut respected if you useuv runto run them.uv's global cache, without reinstalling into the session venv (not a big help by any sense, but still pretty useful)uv_args=["--python", "3.12"]uv_args=["--with", "pkg"]and the likeOf course, this raises an error if
nox[uv]isn't present. My idea with this is that this feature is along the lines of Python packaging tools such as pypa/build passing on touvas the installer withbuild[uv]and so on.caveats
There are two that I can note:
install_and_run_scriptis better to use when the script needs access to the session's environment.AI disclosure
I used Claude Sonnet 4.6 to draw up an initial plan for the PR when I started it. The code was partly written by me and partly by Claude Code, especially for the test plumbing that I felt lazy to write myself. I authored the docs and used the model to review the additions.