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 0863945
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions nox/virtualenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
}

0 comments on commit 0863945

Please sign in to comment.