Skip to content

Commit 540bc21

Browse files
committed
Merge pull request #2451 from xavfernandez/uninstall_order
Reset uninstall order as before c509c5c
2 parents f09efba + 0cf2a49 commit 540bc21

File tree

2 files changed

+44
-13
lines changed

2 files changed

+44
-13
lines changed

pip/req/req_install.py

+23-13
Original file line numberDiff line numberDiff line change
@@ -560,22 +560,18 @@ def uninstall(self, auto_confirm=False):
560560

561561
paths_to_remove = UninstallPathSet(dist)
562562
develop_egg_link = egg_link_path(dist)
563+
develop_egg_link_egg_info = '{0}.egg-info'.format(
564+
pkg_resources.to_filename(dist.project_name))
563565
egg_info_exists = dist.egg_info and os.path.exists(dist.egg_info)
564566
# Special case for distutils installed package
565567
distutils_egg_info = getattr(dist._provider, 'path', None)
566-
if develop_egg_link:
567-
# develop egg
568-
with open(develop_egg_link, 'r') as fh:
569-
link_pointer = os.path.normcase(fh.readline().strip())
570-
assert (link_pointer == dist.location), (
571-
'Egg-link %s does not match installed location of %s '
572-
'(at %s)' % (link_pointer, self.name, dist.location)
573-
)
574-
paths_to_remove.add(develop_egg_link)
575-
easy_install_pth = os.path.join(os.path.dirname(develop_egg_link),
576-
'easy-install.pth')
577-
paths_to_remove.add_pth(easy_install_pth, dist.location)
578-
elif egg_info_exists and dist.egg_info.endswith('.egg-info'):
568+
569+
# Uninstall cases order do matter as in the case of 2 installs of the
570+
# same package, pip needs to uninstall the currently detected version
571+
if (egg_info_exists and dist.egg_info.endswith('.egg-info') and
572+
not dist.egg_info.endswith(develop_egg_link_egg_info)):
573+
# if dist.egg_info.endswith(develop_egg_link_egg_info), we
574+
# are in fact in the develop_egg_link case
579575
paths_to_remove.add(dist.egg_info)
580576
if dist.has_metadata('installed-files.txt'):
581577
for installed_file in dist.get_metadata(
@@ -621,9 +617,23 @@ def uninstall(self, auto_confirm=False):
621617
'easy-install.pth')
622618
paths_to_remove.add_pth(easy_install_pth, './' + easy_install_egg)
623619

620+
elif develop_egg_link:
621+
# develop egg
622+
with open(develop_egg_link, 'r') as fh:
623+
link_pointer = os.path.normcase(fh.readline().strip())
624+
assert (link_pointer == dist.location), (
625+
'Egg-link %s does not match installed location of %s '
626+
'(at %s)' % (link_pointer, self.name, dist.location)
627+
)
628+
paths_to_remove.add(develop_egg_link)
629+
easy_install_pth = os.path.join(os.path.dirname(develop_egg_link),
630+
'easy-install.pth')
631+
paths_to_remove.add_pth(easy_install_pth, dist.location)
632+
624633
elif egg_info_exists and dist.egg_info.endswith('.dist-info'):
625634
for path in pip.wheel.uninstallation_paths(dist):
626635
paths_to_remove.add(path)
636+
627637
else:
628638
logger.debug(
629639
'Not sure how to uninstall: %s - Check: %s',

tests/functional/test_uninstall.py

+21
Original file line numberDiff line numberDiff line change
@@ -388,3 +388,24 @@ def test_uninstall_wheel(script, data):
388388
assert dist_info_folder in result.files_created
389389
result2 = script.pip('uninstall', 'simple.dist', '-y')
390390
assert_all_changes(result, result2, [])
391+
392+
393+
def test_uninstall_setuptools_develop_install(script, data):
394+
"""Try uninstall after setup.py develop followed of setup.py install"""
395+
pkg_path = data.packages.join("FSPkg")
396+
script.run('python', 'setup.py', 'develop',
397+
expect_stderr=True, cwd=pkg_path)
398+
script.run('python', 'setup.py', 'install',
399+
expect_stderr=True, cwd=pkg_path)
400+
list_result = script.pip('list')
401+
assert "FSPkg (0.1.dev0)" in list_result.stdout
402+
# Uninstall both develop and install
403+
uninstall = script.pip('uninstall', 'FSPkg', '-y')
404+
assert any(filename.endswith('.egg')
405+
for filename in uninstall.files_deleted.keys())
406+
uninstall2 = script.pip('uninstall', 'FSPkg', '-y')
407+
assert join(
408+
script.site_packages, 'FSPkg.egg-link'
409+
) in uninstall2.files_deleted, list(uninstall2.files_deleted.keys())
410+
list_result2 = script.pip('list')
411+
assert "FSPkg" not in list_result2.stdout

0 commit comments

Comments
 (0)