Skip to content

Commit

Permalink
fix: look for uv next to python if it's not on PATH
Browse files Browse the repository at this point in the history
  • Loading branch information
cjolowicz committed Mar 5, 2024
1 parent 545a621 commit 845da69
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions nox/virtualenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,21 @@
_SYSTEM = platform.system()


def find_uv() -> str | None:
if uv := shutil.which("uv"):
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")
Expand Down Expand Up @@ -524,7 +539,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,
Expand Down Expand Up @@ -560,5 +575,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,
}

0 comments on commit 845da69

Please sign in to comment.