diff --git a/src/pip/_internal/metadata/importlib/_dists.py b/src/pip/_internal/metadata/importlib/_dists.py index 6ac8b87a213..986dedd034c 100644 --- a/src/pip/_internal/metadata/importlib/_dists.py +++ b/src/pip/_internal/metadata/importlib/_dists.py @@ -26,6 +26,7 @@ InfoPath, Wheel, ) +from pip._internal.utils.misc import normalize_path from pip._internal.utils.packaging import safe_extra from pip._internal.utils.wheel import parse_wheel, read_wheel_metadata_file @@ -141,7 +142,7 @@ def info_location(self) -> Optional[str]: def installed_location(self) -> Optional[str]: if self._installed_location is None: return None - return str(self._installed_location) + return normalize_path(str(self._installed_location)) def _get_dist_name_from_location(self) -> Optional[str]: """Try to get the name from the metadata directory name. diff --git a/src/pip/_internal/metadata/importlib/_envs.py b/src/pip/_internal/metadata/importlib/_envs.py index da623e849da..3da192adb83 100644 --- a/src/pip/_internal/metadata/importlib/_envs.py +++ b/src/pip/_internal/metadata/importlib/_envs.py @@ -151,10 +151,11 @@ def _iter_distributions(self) -> Iterator[BaseDistribution]: finder = _DistributionFinder() for location in self._paths: yield from finder.find(location) - yield from finder.find_linked(location) for dist in finder.find_eggs(location): # _emit_egg_deprecation(dist.location) # TODO: Enable this. yield dist + # This must go last because that's how pkg_resources tie-breaks. + yield from finder.find_linked(location) def get_distribution(self, name: str) -> Optional[BaseDistribution]: matches = ( diff --git a/src/pip/_internal/req/req_uninstall.py b/src/pip/_internal/req/req_uninstall.py index ce03600dd06..41d49e88517 100644 --- a/src/pip/_internal/req/req_uninstall.py +++ b/src/pip/_internal/req/req_uninstall.py @@ -526,10 +526,10 @@ def from_dist(cls, dist: BaseDistribution) -> "UninstallPathSet": # PEP 660 modern editable is handled in the ``.dist-info`` case # above, so this only covers the setuptools-style editable. with open(develop_egg_link) as fh: - link_pointer = os.path.normcase(fh.readline().strip()) - assert link_pointer == dist_location, ( + link_pointer = normalize_path(fh.readline().strip()) + assert link_pointer == normalized_dist_location, ( f"Egg-link {link_pointer} does not match installed location of " - f"{dist.raw_name} (at {dist_location})" + f"{dist.raw_name} (at {normalized_dist_location})" ) paths_to_remove.add(develop_egg_link) easy_install_pth = os.path.join( diff --git a/tests/functional/test_uninstall.py b/tests/functional/test_uninstall.py index 13baad1779d..b616c242057 100644 --- a/tests/functional/test_uninstall.py +++ b/tests/functional/test_uninstall.py @@ -615,11 +615,13 @@ def test_uninstall_setuptools_develop_install( script.assert_installed(FSPkg="0.1.dev0") # Uninstall both develop and install uninstall = script.pip("uninstall", "FSPkg", "-y") - assert any(filename.endswith(".egg") for filename in uninstall.files_deleted.keys()) + assert any(filename.endswith(".egg") for filename in uninstall.files_deleted), str( + uninstall + ) uninstall2 = script.pip("uninstall", "FSPkg", "-y") assert ( join(script.site_packages, "FSPkg.egg-link") in uninstall2.files_deleted - ), list(uninstall2.files_deleted.keys()) + ), str(uninstall2) script.assert_not_installed("FSPkg")