From 08639451d4f989e4b0c363d4f93ea4e6fe0cf258 Mon Sep 17 00:00:00 2001 From: Claudio Jolowicz Date: Tue, 5 Mar 2024 10:05:40 +0100 Subject: [PATCH] fix: look for uv next to python if it's not on PATH --- nox/virtualenv.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/nox/virtualenv.py b/nox/virtualenv.py index 6f4b6099..1d288f01 100644 --- a/nox/virtualenv.py +++ b/nox/virtualenv.py @@ -39,6 +39,22 @@ _SYSTEM = platform.system() +def find_uv() -> str | None: + uv = shutil.which("uv") + if uv is not None: + return uv + + # Handle `pipx install nox[uv]` by looking for uv next to python. + uv = os.path.join(os.path.dirname(sys.executable), "uv") + if os.path.exists(uv): + return uv + + return None + + +UV = find_uv() + + class InterpreterNotFound(OSError): def __init__(self, interpreter: str) -> None: super().__init__(f"Python interpreter {interpreter} not found") @@ -524,7 +540,7 @@ def create(self) -> bool: cmd.extend(["-p", self._resolved_interpreter]) elif self.venv_backend == "uv": cmd = [ - "uv", + UV or "uv", "venv", "-p", self._resolved_interpreter if self.interpreter else sys.executable, @@ -560,5 +576,5 @@ def create(self) -> bool: OPTIONAL_VENVS = { "conda": shutil.which("conda") is not None, "mamba": shutil.which("mamba") is not None, - "uv": shutil.which("uv") is not None, + "uv": UV is not None, }