wntrblm / nox

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

uv executable not found when installed with `pipx install nox[uv]` #791

Closed edgarrmondragon closed 6 months ago

edgarrmondragon commented 6 months ago

Current Behavior

The following exception is raised when a global uv installation is not available.

ValueError: No backends present, looked for ['uv'].

https://github.com/wntrblm/nox/blob/4c8e89164d90718312e4819a48243797924f55a9/nox/sessions.py#L790

The underlying cause seems to be shutil.which("uv") not being able to find uv installed alongside nox.

https://github.com/wntrblm/nox/blob/4c8e89164d90718312e4819a48243797924f55a9/nox/virtualenv.py#L563

Expected Behavior

Installing nox[uv] is sufficient to use uv as a backend, without relying on a global uv installation.

Steps To Reproduce

  1. Install nox[uv]
  2. Configure uv as a venv backend, for example by setting nox.options.default_venv_backend = "uv" in the Noxfile
  3. Run any session

Environment

- OS: macOS
- Python: 3.12
- Nox: 2024.3.2

Anything else?

No response

cjolowicz commented 6 months ago

pipx doesn't include apps of dependent packages by default. Workaround:

pipx install --include-deps nox[uv]
cjolowicz commented 6 months ago

Some options:

  1. Document --include-deps
  2. Use python -m uv
  3. Search for uv next to sys.executable if shutil.which returns empty handed

Option 1 puts the burden on the user, and it puts a bunch of unrelated apps on PATH (activate-global-python-argcomplete, python-argcomplete-check-easy-install-script, register-python-argcomplete, virtualenv), producing a warning if any of them already exist.

Option 2 is what we do for virtualenv but incurs unnecessary overhead on startup.

Option 3 is a bit messy but would work out of the box. (Only Windows installations don't have the interpreter next to entry-point scripts, but those would be covered by shutil.which.)

(I guess there's also option 4: Drop the extra in a quick follow-up release? I don't know if there's a five-second rule for backward compatibility.)

Proposal: option 3

layday commented 6 months ago

pipx install --include-deps nox[uv] is probably worse than installing nox and uv separately with pipx install nox uv since it'll put a bunch of other, unrelated stuff on $PATH.