Skip to content

Commit

Permalink
pypa#3722 Finish implementing and debugging fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ianpittwood committed Sep 7, 2019
1 parent 3affc39 commit 403811f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
14 changes: 8 additions & 6 deletions pipenv/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2230,8 +2230,6 @@ def do_uninstall(
click.echo("Ignoring {0}.".format(ignored_pkg), err=True)
pkg_name_index = package_names.index(package_map[ignored_pkg])
del package_names[pkg_name_index]

used_packages = project_pkg_names["combined"] & installed_package_names
failure = False
packages_to_remove = set()
if all:
Expand All @@ -2248,9 +2246,11 @@ def do_uninstall(
overlapping_package_names = set()
if all_dev:
package_names = project_pkg_names["dev"]
overlapping_package_names = project_pkg_names["dev"] & project_pkg_names["default"]
used_packages = (project_pkg_names["combined"] & installed_package_names) - project_pkg_names["default"]
else:
package_names = set([pkg_name for pkg_name in package_names])
used_packages = project_pkg_names["combined"] & installed_package_names

selected_pkg_map = {
canonicalize_name(p): p for p in package_names
}
Expand All @@ -2266,7 +2266,8 @@ def do_uninstall(
)
)
# Uninstall the package.
if package_name in packages_to_remove and package_name not in overlapping_package_names:
# If uninstall --all-dev, skip any common packages between default and dev from pip uninstall
if package_name in packages_to_remove:
with project.environment.activated():
if pip_path is None:
pip_path = which_pip(allow_global=system)
Expand All @@ -2288,7 +2289,8 @@ def do_uninstall(
crayons.white(fix_utf8("Pipfile.lock…")))
)
lockfile = project.get_or_create_lockfile()
if normalized in lockfile.default and package_name not in overlapping_package_names:
# Uninstall with --all-dev should not modify the default packages
if normalized in lockfile.default and not all_dev:
del lockfile.default[normalized]
if normalized in lockfile.develop:
del lockfile.develop[normalized]
Expand All @@ -2309,7 +2311,7 @@ def do_uninstall(
# Remove package from both packages and dev-packages.
if in_dev_packages:
project.remove_package_from_pipfile(package_name, dev=True)
if in_packages:
if in_packages and not all_dev:
project.remove_package_from_pipfile(package_name, dev=False)
if lock:
do_lock(system=system, keep_outdated=keep_outdated, pypi_mirror=pypi_mirror)
Expand Down
15 changes: 8 additions & 7 deletions tests/integration/test_uninstall.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def test_uninstall_all_dev(PipenvInstance):
@pytest.mark.install
def test_uninstall_all_dev_leave_prod_packages(PipenvInstance):
with PipenvInstance() as p:
c = p.pipenv("install --dev black")
c = p.pipenv("install --dev --pre black")
assert c.return_code == 0

c = p.pipenv("install flask")
Expand All @@ -173,14 +173,15 @@ def test_uninstall_all_dev_leave_prod_packages(PipenvInstance):

c = p.pipenv("uninstall --all-dev")
assert c.return_code == 0

assert p.pipfile["dev-packages"] == {}
assert["black"] not in p.lockfile["develop"]
assert["click"] not in p.lockfile["develop"]
assert["flask"] in p.pipfile["packages"]
assert["flask"] in p.lockfile["default"]
assert["click"] in p.lockfile["default"]
assert "black" not in p.lockfile["develop"]
assert "click" not in p.lockfile["develop"]
assert "flask" in p.pipfile["packages"]
assert "flask" in p.lockfile["default"]
assert "click" in p.lockfile["default"]

c = p.pipenv('run python -c "import click')
c = p.pipenv('run python -c "import click"')
assert c.return_code == 0


Expand Down

0 comments on commit 403811f

Please sign in to comment.