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

Issue using uv with nox: uv insists using .venv instead of the nox-managed virtualenv #9125

Open
sfermigier opened this issue Nov 14, 2024 · 1 comment

Comments

@sfermigier
Copy link

I have trouble integrating uv with nox.

Here is what I would like to work:

nox.options.default_venv_backend = "uv|virtualenv"

@nox.session
def lint(session: nox.Session) -> None:
    session.run("uv", "sync", "--no-dev")
    session.run("uv", "pip", "install", "pyright")
    session.run("uv", "run", "pyright")

If fails, because uv ignores the virtualenv supplied by nox:

warning: `VIRTUAL_ENV=.nox/lint` does not match the project environment path `.venv` and will be ignored

Here's a workaround:

nox.options.default_venv_backend = "uv|virtualenv"

@nox.session
def lint(session: nox.Session) -> None:
    session.run("rm", "-rf", ".venv", external=True)
    session.run("ln", "-s", ".nox/lint", ".venv", external=True)
    session.run("uv", "sync", "--no-dev")
    session.run("uv", "pip", "install", "abilian-devtools")
    session.run("just", "lint", external=True)

Here's a successful run:

nox -e lint -r
nox > Running session lint
nox > Creating virtual environment (uv) using python in .nox/lint
nox > rm -rf .venv
nox > ln -s .nox/lint .venv
nox > uv sync --no-dev
...

However, at the end of the run, I have to run uv sync to recreate my .venv to keep working.

I have eventually found another workaround, but anyway, I still think the use case of running "uv sync" from a virtualenv created by something else (e.g. tox or nox) could be useful.

Another thing that breaks is if I have a Makefile or Justfile that calls uv run make something, then uv will use .venv and not .nox/whatever and this breaks.

Version infos:

❯ nox --version
2024.10.9
❯ uv --version
uv 0.5.1 (Homebrew 2024-11-08)
@zanieb
Copy link
Member

zanieb commented Nov 14, 2024

Please see #6834 and the discussions linked there.

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

No branches or pull requests

2 participants