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

Remove all env #3212

Merged
merged 21 commits into from
Nov 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
5633263
Added suppor for removing multiple virtualenvs in CLI.
DustinMoriarty Oct 15, 2020
13e9e0a
Added tests.
DustinMoriarty Oct 15, 2020
875a490
Formatted with black.
DustinMoriarty Oct 15, 2020
3105085
Ran pre-comit.
DustinMoriarty Oct 15, 2020
6da7cce
Update poetry/console/commands/env/remove.py
DustinMoriarty Oct 17, 2020
5d92452
Update poetry/console/commands/env/remove.py
DustinMoriarty Oct 17, 2020
1257b99
Update poetry/console/commands/env/remove.py
DustinMoriarty Oct 17, 2020
a4b87cf
Reverted changes to poetry.lock.
DustinMoriarty Oct 17, 2020
6ed33c7
Remove pythons before all if both are provided.
DustinMoriarty Oct 18, 2020
d0b81ba
Handle ambiguity for remove all and python version with more predicta…
DustinMoriarty Oct 18, 2020
a0c16c0
Ran pre-commit.
DustinMoriarty Oct 18, 2020
56564f4
Updated documentation and merged upstream.
DustinMoriarty Mar 12, 2021
bf57817
Restored wording for description.
DustinMoriarty Mar 12, 2021
9753d0c
Updated python argument description.
DustinMoriarty Mar 12, 2021
a53e767
Updated argument description
DustinMoriarty Mar 12, 2021
bb2e3e9
Merge branch 'master' into remove-all-env
DustinMoriarty Apr 25, 2021
0ec2961
Merge branch 'master' into remove-all-env
Nov 14, 2021
0b93a55
Update poetry/console/commands/env/remove.py
DustinMoriarty Nov 14, 2021
5a2b7a3
Update docs/managing-environments.md
DustinMoriarty Nov 14, 2021
1b7ec97
Update poetry/console/commands/env/remove.py
DustinMoriarty Nov 14, 2021
eb9ea74
Update poetry/console/commands/env/remove.py
DustinMoriarty Nov 14, 2021
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
9 changes: 9 additions & 0 deletions docs/managing-environments.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,13 @@ poetry env remove 3.7
poetry env remove test-O3eWbxRl-py3.7
```

You can delete more than one environment at a time.
```bash
poetry env remove python3.6 python3.7 python3.8
```
Use the `--all` option to delete all virtual environments at once.
```bash
poetry env remove --all
```

If you remove the currently activated virtual environment, it will be automatically deactivated.
34 changes: 29 additions & 5 deletions poetry/console/commands/env/remove.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,45 @@
from cleo.helpers import argument
from cleo.helpers import option

from ..command import Command


class EnvRemoveCommand(Command):

name = "env remove"
description = "Removes a specific virtualenv associated with the project."
description = "Remove virtual environments associated with the project."

arguments = [
argument("python", "The python executable to remove the virtualenv for.")
argument(
"python",
"The python executables associated with, or names of the virtual environments which are to "
"be removed.",
optional=True,
multiple=True,
)
]
options = [
option(
"all",
description="Remove all managed virtual environments associated with the "
"project.",
),
]

def handle(self) -> None:
from poetry.utils.env import EnvManager

manager = EnvManager(self.poetry)
venv = manager.remove(self.argument("python"))
pythons = self.argument("python")
all = self.option("all")
if not (pythons or all):
self.line("No virtualenv provided.")

self.line("Deleted virtualenv: <comment>{}</comment>".format(venv.path))
manager = EnvManager(self.poetry)
# TODO: refactor env.py to allow removal with one loop
for python in pythons:
DustinMoriarty marked this conversation as resolved.
Show resolved Hide resolved
venv = manager.remove(python)
self.line("Deleted virtualenv: <comment>{}</comment>".format(venv.path))
if all:
for venv in manager.list():
manager.remove_venv(venv.path)
self.line("Deleted virtualenv: <comment>{}</comment>".format(venv.path))
31 changes: 31 additions & 0 deletions tests/console/commands/env/test_remove.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,34 @@ def test_remove_by_name(tester, venvs_in_cache_dirs, venv_name, venv_cache):
expected += "Deleted virtualenv: {}\n".format((venv_cache / name))

assert expected == tester.io.fetch_output()


def test_remove_all(tester, venvs_in_cache_dirs, venv_name, venv_cache):
expected = {""}
tester.execute("--all")
for name in venvs_in_cache_dirs:
assert not (venv_cache / name).exists()
expected.add("Deleted virtualenv: {}".format((venv_cache / name)))
assert expected == set(tester.io.fetch_output().split("\n"))


def test_remove_all_and_version(tester, venvs_in_cache_dirs, venv_name, venv_cache):
expected = {""}
tester.execute("--all {}".format(venvs_in_cache_dirs[0]))
for name in venvs_in_cache_dirs:
assert not (venv_cache / name).exists()
expected.add("Deleted virtualenv: {}".format((venv_cache / name)))
assert expected == set(tester.io.fetch_output().split("\n"))


def test_remove_multiple(tester, venvs_in_cache_dirs, venv_name, venv_cache):
expected = {""}
removed_envs = venvs_in_cache_dirs[0:2]
remaining_envs = venvs_in_cache_dirs[2:]
tester.execute(" ".join(removed_envs))
for name in removed_envs:
assert not (venv_cache / name).exists()
expected.add("Deleted virtualenv: {}".format((venv_cache / name)))
for name in remaining_envs:
assert (venv_cache / name).exists()
assert expected == set(tester.io.fetch_output().split("\n"))