-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Fix for the removal of all the environments using the --all
option
#8665
Changes from all commits
9606bbe
ab08473
2071558
9755fee
2376761
f83f949
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -338,7 +338,7 @@ def remove(self, python: str) -> Env: | |
if venv.path.name == python: | ||
# Exact virtualenv name | ||
if not envs_file.exists(): | ||
self.remove_venv(venv.path) | ||
self.remove_venv_dir(venv.path) | ||
|
||
return venv | ||
|
||
|
@@ -348,15 +348,15 @@ def remove(self, python: str) -> Env: | |
|
||
current_env = envs.get(base_env_name) | ||
if not current_env: | ||
self.remove_venv(venv.path) | ||
self.remove_venv_dir(venv.path) | ||
|
||
return venv | ||
|
||
if current_env["minor"] == venv_minor: | ||
del envs[base_env_name] | ||
envs_file.write(envs) | ||
|
||
self.remove_venv(venv.path) | ||
self.remove_venv_dir(venv.path) | ||
|
||
return venv | ||
|
||
|
@@ -405,10 +405,34 @@ def remove(self, python: str) -> Env: | |
del envs[base_env_name] | ||
envs_file.write(envs) | ||
|
||
self.remove_venv(venv_path) | ||
self.remove_venv_dir(venv_path) | ||
|
||
return VirtualEnv(venv_path, venv_path) | ||
|
||
def remove_venv(self, venv: VirtualEnv) -> Env: | ||
venv_path = self._poetry.config.virtualenvs_path | ||
cwd = self._poetry.file.path.parent | ||
envs_file = TOMLFile(venv_path / self.ENVS_FILE) | ||
base_env_name = self.generate_env_name(self._poetry.package.name, str(cwd)) | ||
|
||
env_path = venv.path | ||
major, minor, _ = venv.get_version_info() | ||
|
||
name = f"{base_env_name}-py{major}.{minor}" | ||
|
||
if not env_path.exists(): | ||
raise ValueError(f'<warning>Environment "{name}" does not exist.</warning>') | ||
|
||
if envs_file.exists(): | ||
envs = envs_file.read() | ||
if base_env_name in envs: | ||
del envs[base_env_name] | ||
envs_file.write(envs) | ||
Comment on lines
+428
to
+430
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It may not make a difference for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed, this may no make a difference. The check is only there if there is an inconsistency between the TOML env file and the virtual env folders. |
||
|
||
self.remove_venv_dir(env_path) | ||
|
||
return VirtualEnv(env_path, env_path) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we return a venv? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, I sticked to what appears to be the norm in the Poetry repository. The original |
||
|
||
def use_in_project_venv(self) -> bool: | ||
in_project: bool | None = self._poetry.config.get("virtualenvs.in-project") | ||
if in_project is not None: | ||
|
@@ -576,7 +600,7 @@ def create_venv( | |
self._io.write_error_line( | ||
f"Recreating virtualenv <c1>{name}</> in {venv!s}" | ||
) | ||
self.remove_venv(venv) | ||
self.remove_venv_dir(venv) | ||
create_venv = True | ||
elif self._io.is_very_verbose(): | ||
self._io.write_error_line(f"Virtualenv <c1>{name}</> already exists.") | ||
|
@@ -684,7 +708,7 @@ def build_venv( | |
return cli_result | ||
|
||
@classmethod | ||
def remove_venv(cls, path: Path) -> None: | ||
def remove_venv_dir(cls, path: Path) -> None: | ||
assert path.is_dir() | ||
try: | ||
remove_directory(path) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this warning? At least raising a
ValueError
seems to be wrong, especially for a warning.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ValueError
is the error type that was chosen for this kind of warning I guess. I sticked to the behavior of the original.remove()
method which usesValueError
in this exact same way.