@@ -455,13 +455,22 @@ def from_dist(cls, dist: BaseDistribution) -> "UninstallPathSet":
455455 paths_to_remove = cls (dist )
456456 develop_egg_link = egg_link_path_from_location (dist .raw_name )
457457
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+
458470 # Uninstall cases order do matter as in the case of 2 installs of the
459471 # 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.
463- if info_location is not None :
464- paths_to_remove .add (info_location )
472+ if setuptools_flat_installation :
473+ paths_to_remove .add (info_location )
465474 installed_files = dist .iter_declared_entries ()
466475 if installed_files is not None :
467476 for installed_file in installed_files :
@@ -512,15 +521,16 @@ def from_dist(cls, dist: BaseDistribution) -> "UninstallPathSet":
512521 for path in uninstallation_paths (dist ):
513522 paths_to_remove .add (path )
514523
515- elif dist . editable and develop_egg_link :
524+ elif develop_egg_link :
516525 # PEP 660 modern editable is handled in the ``.dist-info`` case
517526 # above, so this only covers the setuptools-style editable.
518527 with open (develop_egg_link ) as fh :
519528 link_pointer = os .path .normcase (fh .readline ().strip ())
520529 assert (
521530 link_pointer == dist_location
522- ), "Egg-link {} does not match installed location of {} (at {})" .format (
523- link_pointer , dist .raw_name , dist_location
531+ ), (
532+ f"Egg-link { link_pointer } does not match installed location of "
533+ f"{ dist .raw_name } (at { dist_location } )"
524534 )
525535 paths_to_remove .add (develop_egg_link )
526536 easy_install_pth = os .path .join (
0 commit comments