Use uv for session.install with conda backend
How would this feature be useful?
uv supports replacing pip install for both regular virtual environments and conda environments. It would be great to use it with conda backend sessions because it is fast.
Describe the solution you'd like
Currently, the only way to use uv is to specify it as the venv_backend. This uses it to create a regular virtual environment, and makes it the installer when you do session.install.
When using either conda or mamba as the venv_backend in order to get a conda environment, session.install uses regular pip. It would be nice to be able to do something like installer="uv|pip" like the way that venv_backend is specified.
Describe alternatives you've considered
No response
Anything else?
No response
Can't you install "uv" then use that? Or even do shutil.which("uv"), and then install it if that returns None, otherwise use the external one?
Not saying having an installer option, and then having venv's default to the right thing but making it settable is bad. But it does complicate things.
I did end up making a workaround with shutil.which("uv") based on the find_uv function that I saw in nox's source code.
In noxfile.py global namespace:
def find_uv() -> tuple[bool, str]:
# Inspired by:
# https://github.com/wntrblm/nox/blob/08813c3c6b0d2171c280bbfcf219d089a16d1ac2/nox/virtualenv.py#L42
uv = shutil.which("uv")
if uv is not None:
return True, uv
return False, "uv"
HAS_UV, UV = find_uv()
Then in the session:
if HAS_UV:
session.run(UV, "pip", "install", "-r", "requirements/dev.txt", external=True)
else:
session.install("-r", "requirements/dev.txt")
Kind of messy but seems to work well enough.