Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use conda remove to clean up existing conda environment #373

Merged
merged 4 commits into from
Dec 31, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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