Skip to content

Commit

Permalink
fix: detect uv environments
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
  • Loading branch information
henryiii committed Feb 19, 2024
1 parent c691507 commit 80ab56d
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions nox/virtualenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,21 +350,21 @@ def _clean_location(self) -> bool:

def _check_reused_environment_type(self) -> bool:
"""Check if reused environment type is the same."""
path = os.path.join(self.location, "pyvenv.cfg")
if not os.path.isfile(path):
try:
with open(os.path.join(self.location, "pyvenv.cfg")) as fp:
parts = (x.partition("=") for x in fp if "=" in x)
config = {k.strip(): v.strip() for k, _, v in parts}
if "gourgeist" in config:
old_env = "uv"
elif "virtualenv" in config:
old_env = "virtualenv"
else:
old_env = "venv"
except FileNotFoundError:
# virtualenv < 20.0 does not create pyvenv.cfg
old_env = "virtualenv" # pragma: win32 no cover
else:
pattern = re.compile("virtualenv[ \t]*=")
with open(path) as fp:
old_env = (
"virtualenv" if any(pattern.match(line) for line in fp) else "venv"
)
# We can't distinguish a uv env from a venv env, so just treat them
# the same.
return old_env == self.venv_backend or (
{old_env, self.venv_backend} == {"uv", "venv"}
)

return old_env == self.venv_backend

def _check_reused_environment_interpreter(self) -> bool:
"""Check if reused environment interpreter is the same."""
Expand Down

0 comments on commit 80ab56d

Please sign in to comment.