Skip to content

Commit

Permalink
Corrected behavior regression for uninstall --all
Browse files Browse the repository at this point in the history
  • Loading branch information
matteius committed Aug 25, 2024
1 parent c6d7aba commit bcbb3fa
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
29 changes: 18 additions & 11 deletions pipenv/routines/uninstall.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from pipenv.utils.resolver import venv_resolve_deps
from pipenv.utils.shell import cmd_list_to_shell, project_python
from pipenv.vendor import click
from pipenv.vendor.importlib_metadata.compat.py39 import normalized_name


def _uninstall_from_environment(project, package, system=False):
Expand Down Expand Up @@ -82,22 +83,29 @@ def do_uninstall(
if all:
click.secho(
click.style(
"Un-installing all {}...".format(click.style("[packages]", fg="yellow")),
"Un-installing all packages...",
bold=True,
)
)
# Uninstall all dev-packages from environment
for package in project.get_pipfile_section("packages"):
_uninstall_from_environment(project, package, system=system)
# Remove the package from the Pipfile
if project.reset_category_in_pipfile(category="packages"):
click.echo("Removed [packages] from Pipfile.")
# Uninstall all packages from all groups
for category in project.get_package_categories():
if category in ["source", "requires"]:
continue
for package in project.get_pipfile_section(category):
_uninstall_from_environment(project, package, system=system)

# Clear all categories in the lockfile
for category in list(lockfile_content.keys()):
if category != "_meta":
lockfile_content[category] = {}

# Finalize changes to lockfile
lockfile_content["default"] = {}
lockfile_content.update({"_meta": project.get_lockfile_meta()})
project.write_lockfile(lockfile_content)

# Call do_purge to remove all packages from the environment
do_purge(project, bare=False, downloads=False, allow_global=system)
return

package_args = list(packages) + [f"-e {pkg}" for pkg in editable_packages]

# Determine packages and their dependencies for removal
Expand Down Expand Up @@ -177,8 +185,7 @@ def do_purge(project, bare=False, downloads=False, allow_global=False):

# Remove comments from the output, if any.
installed = {
pep423_name(pkg.project_name)
for pkg in project.environment.get_installed_packages()
normalized_name(pkg) for pkg in project.environment.get_installed_packages()
}
bad_pkgs = {pep423_name(pkg) for pkg in BAD_PACKAGES}
# Remove setuptools, pip, etc from targets for removal
Expand Down
2 changes: 1 addition & 1 deletion pipenv/utils/virtualenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def ensure_virtualenv(project, python=None, site_packages=None, pypi_mirror=None
def cleanup_virtualenv(project, bare=True):
"""Removes the virtualenv directory from the system."""
if not bare:
console.pritn("[red]Environment creation aborted.[/red]")
console.print("[red]Environment creation aborted.[/red]")
try:
# Delete the virtualenv.
shutil.rmtree(project.virtualenv_location)
Expand Down
7 changes: 5 additions & 2 deletions tests/integration/test_uninstall.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,11 @@ def test_uninstall_all_local_files(pipenv_instance_private_pypi, testsroot):
c = p.pipenv(f"install {file_uri}")
assert c.returncode == 0
c = p.pipenv("uninstall --all")
assert "tablib" not in p.pipfile["packages"]
assert "tablib" not in p.lockfile["default"]
assert c.returncode == 0
assert "tablib" in c.stdout
# Uninstall --all is not supposed to remove things from the pipfile
# Note that it didn't before, but that instead local filenames showed as hashes
assert "tablib" in p.pipfile["packages"]


@pytest.mark.install
Expand Down

0 comments on commit bcbb3fa

Please sign in to comment.