@@ -455,11 +455,21 @@ def from_dist(cls, dist: BaseDistribution) -> "UninstallPathSet":
455
455
paths_to_remove = cls (dist )
456
456
develop_egg_link = egg_link_path_from_location (dist .raw_name )
457
457
458
+ # Distribution is installed with metadata in a "flat" .egg-info
459
+ # directory. This means it is not a modern .dist-info installation, an
460
+ # egg, or legacy editable.
461
+ setuptools_flat_installation = (
462
+ dist .installed_with_setuptools_egg_info
463
+ and info_location is not None
464
+ and os .path .exists (info_location )
465
+ # If dist is editable and the location points to a ``.egg-info``,
466
+ # we are in fact in the legacy editable case.
467
+ and not info_location .endswith (f"{ dist .setuptools_filename } .egg-info" )
468
+ )
469
+
458
470
# Uninstall cases order do matter as in the case of 2 installs of the
459
471
# same package, pip needs to uninstall the currently detected version
460
- if dist .installed_with_setuptools_egg_info and not dist .editable :
461
- # if dist is editable and the location points to a ``.egg-info``,
462
- # we are in fact in the ``.egg_link`` case.
472
+ if setuptools_flat_installation :
463
473
if info_location is not None :
464
474
paths_to_remove .add (info_location )
465
475
installed_files = dist .iter_declared_entries ()
@@ -512,15 +522,14 @@ def from_dist(cls, dist: BaseDistribution) -> "UninstallPathSet":
512
522
for path in uninstallation_paths (dist ):
513
523
paths_to_remove .add (path )
514
524
515
- elif dist . editable and develop_egg_link :
525
+ elif develop_egg_link :
516
526
# PEP 660 modern editable is handled in the ``.dist-info`` case
517
527
# above, so this only covers the setuptools-style editable.
518
528
with open (develop_egg_link ) as fh :
519
529
link_pointer = os .path .normcase (fh .readline ().strip ())
520
- assert (
521
- link_pointer == dist_location
522
- ), "Egg-link {} does not match installed location of {} (at {})" .format (
523
- link_pointer , dist .raw_name , dist_location
530
+ assert link_pointer == dist_location , (
531
+ f"Egg-link { link_pointer } does not match installed location of "
532
+ f"{ dist .raw_name } (at { dist_location } )"
524
533
)
525
534
paths_to_remove .add (develop_egg_link )
526
535
easy_install_pth = os .path .join (
0 commit comments