Skip to content

Commit

Permalink
Properly normalize and handle linked dist
Browse files Browse the repository at this point in the history
  • Loading branch information
uranusjr committed Dec 12, 2021
1 parent 2242358 commit 4e25f68
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/pip/_internal/metadata/importlib/_dists.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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(self._installed_location)

def _get_dist_name_from_location(self) -> Optional[str]:
"""Try to get the name from the metadata directory name.
Expand Down
3 changes: 2 additions & 1 deletion src/pip/_internal/metadata/importlib/_envs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down
6 changes: 3 additions & 3 deletions src/pip/_internal/req/req_uninstall.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 4 additions & 2 deletions tests/functional/test_uninstall.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")


Expand Down

0 comments on commit 4e25f68

Please sign in to comment.