wntrblm / nox

Flexible test automation for Python
https://nox.thea.codes
Apache License 2.0
1.3k stars 148 forks source link

fix: ensure 'uv' always works in a uv venv #818

Closed henryiii closed 4 months ago

henryiii commented 4 months ago

It's necessary sometimes to use the backend tool (pip, uv, conda, mamba, micromamba) inside a virtual environment. We already have a bit of special casing for it, making sure it's not considered "external". This PR just makes sure that .run("uv", ...) is always supported if you are using the uv backend. All the other backends are already gaurenteed to be on the path if they are active, so no change is needed (yet, anyway - this mechanism could also enable using pip from outside instead of always installing it, might be worth investigating in the future).

Followup to and generalizes #795.

henryiii commented 4 months ago

Added handling for one more corner case: if a user installs uv into a uv environment, they'd probably expect the new uv to be used after they installed it, just like pip is for pip environments. This worked except for the "installed alongside nox" case. Now it matches the "on path" case. Tested locally with:

@nox.session(venv_backend="uv")
def uv(session):
    session.install("uv")
    session.install("pip")
$ pipx run --spec .[uv] nox -s uv
⚠️  nox is already on your PATH and installed at /usr/local/bin/nox. Downloading and running anyway.
nox > Running session uv
nox > Creating virtual environment (uv) using python in .nox/uv
nox > /Users/henryschreiner/.local/pipx/.cache/ee854022650cc85/bin/uv pip install uv
nox > uv pip install pip
cjolowicz commented 4 months ago

Can you add a source code comment to explain this edge case?

It would also be good to have a comment for the Path.samefile call in find_uv, and to add both branches to the test matrix in test_find_uv.

henryiii commented 4 months ago

Added comments and added to tests.