Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use uv for session.install with conda backend #802

Open
jayqi opened this issue Mar 19, 2024 · 2 comments
Open

Use uv for session.install with conda backend #802

jayqi opened this issue Mar 19, 2024 · 2 comments

Comments

@jayqi
Copy link

jayqi commented Mar 19, 2024

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

@henryiii
Copy link
Collaborator

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.

@jayqi
Copy link
Author

jayqi commented Mar 29, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants