Skip to content

Commit

Permalink
Use conda remove to clean up existing conda environment. Closes #372. (
Browse files Browse the repository at this point in the history
…#373)

Co-authored-by: Santos Gallegos <santos_g@outlook.com>
Co-authored-by: Christopher Wilcox <crwilcox@google.com>
  • Loading branch information
3 people authored Dec 31, 2020
1 parent e2db5ed commit 4d42022
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions nox/virtualenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,17 +139,6 @@ def locate_using_path_and_version(version: str) -> Optional[str]:
return None


def _clean_location(self: "Union[CondaEnv, VirtualEnv]") -> bool:
"""Deletes any existing path-based environment"""
if os.path.exists(self.location):
if self.reuse_existing:
return False
else:
shutil.rmtree(self.location)

return True


class PassthroughEnv(ProcessEnv):
"""Represents the environment used to run nox itself
Expand Down Expand Up @@ -200,7 +189,21 @@ def __init__(
self.venv_params = venv_params if venv_params else []
super(CondaEnv, self).__init__()

_clean_location = _clean_location
def _clean_location(self) -> bool:
"""Deletes existing conda environment"""
if os.path.exists(self.location):
if self.reuse_existing:
return False
else:
cmd = ["conda", "remove", "--yes", "--prefix", self.location, "--all"]
nox.command.run(cmd, silent=True, log=False)
# Make sure that location is clean
try:
shutil.rmtree(self.location)
except FileNotFoundError:
pass

return True

@property
def bin_paths(self) -> List[str]:
Expand Down Expand Up @@ -302,7 +305,15 @@ def __init__(
self.venv_params = venv_params if venv_params else []
super(VirtualEnv, self).__init__(env={"VIRTUAL_ENV": self.location})

_clean_location = _clean_location
def _clean_location(self) -> bool:
"""Deletes any existing virtual environment"""
if os.path.exists(self.location):
if self.reuse_existing:
return False
else:
shutil.rmtree(self.location)

return True

@property
def _resolved_interpreter(self) -> str:
Expand Down

0 comments on commit 4d42022

Please sign in to comment.