@@ -560,22 +560,18 @@ def uninstall(self, auto_confirm=False):
560
560
561
561
paths_to_remove = UninstallPathSet (dist )
562
562
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 ))
563
565
egg_info_exists = dist .egg_info and os .path .exists (dist .egg_info )
564
566
# Special case for distutils installed package
565
567
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
579
575
paths_to_remove .add (dist .egg_info )
580
576
if dist .has_metadata ('installed-files.txt' ):
581
577
for installed_file in dist .get_metadata (
@@ -621,9 +617,23 @@ def uninstall(self, auto_confirm=False):
621
617
'easy-install.pth' )
622
618
paths_to_remove .add_pth (easy_install_pth , './' + easy_install_egg )
623
619
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
+
624
633
elif egg_info_exists and dist .egg_info .endswith ('.dist-info' ):
625
634
for path in pip .wheel .uninstallation_paths (dist ):
626
635
paths_to_remove .add (path )
636
+
627
637
else :
628
638
logger .debug (
629
639
'Not sure how to uninstall: %s - Check: %s' ,
0 commit comments