Skip to content

Commit e1680b2

Browse files
committed
Fix distutils uninstallation error
1 parent 5c4fd71 commit e1680b2

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

src/pip/_internal/metadata/base.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def info_location(self) -> Optional[str]:
148148
raise NotImplementedError()
149149

150150
@property
151-
def installed_by_legacy_distutils(self) -> bool:
151+
def installed_by_distutils(self) -> bool:
152152
"""Whether this distribution is installed with legacy distutils format.
153153
154154
A distribution installed with "raw" distutils not patched by setuptools
@@ -173,19 +173,22 @@ def installed_as_egg(self) -> bool:
173173
return info_location.endswith(".egg")
174174

175175
@property
176-
def installed_with_egg_info(self) -> bool:
176+
def installed_with_setuptools_egg_info(self) -> bool:
177177
"""Whether this distribution is installed with the ``.egg-info`` format.
178178
179179
This usually indicates the distribution was installed with setuptools
180180
with an old pip version or with ``single-version-externally-managed``.
181181
182-
Note that this *does not* ensure ``.egg-info`` is a directory. It can
183-
be a file when ``installed_by_legacy_distutils`` is also True.
182+
Note that this ensure the metadata store is a directory. distutils can
183+
also installs an ``.egg-info``, but as a file, not a directory. This
184+
property is *False* for that case. Also see ``installed_by_distutils``.
184185
"""
185186
info_location = self.info_location
186187
if not info_location:
187188
return False
188-
return info_location.endswith(".egg-info")
189+
if not info_location.endswith(".egg-info"):
190+
return False
191+
return pathlib.Path(info_location).is_dir()
189192

190193
@property
191194
def installed_with_dist_info(self) -> bool:

src/pip/_internal/req/req_uninstall.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ def commit(self) -> None:
423423
def from_dist(cls, dist: BaseDistribution) -> "UninstallPathSet":
424424
dist_location = dist.location
425425
info_location = dist.info_location
426-
if dist_location is None or info_location is None:
426+
if dist_location is None:
427427
logger.info(
428428
"Not uninstalling %s since it is not installed",
429429
dist.canonical_name,
@@ -457,10 +457,11 @@ def from_dist(cls, dist: BaseDistribution) -> "UninstallPathSet":
457457

458458
# Uninstall cases order do matter as in the case of 2 installs of the
459459
# same package, pip needs to uninstall the currently detected version
460-
if dist.installed_with_egg_info and not dist.editable:
460+
if dist.installed_with_setuptools_egg_info and not dist.editable:
461461
# if dist is editable and the location points to a ``.egg-info``,
462462
# we are in fact in the ``.egg_link`` case.
463-
paths_to_remove.add(info_location)
463+
if info_location is not None:
464+
paths_to_remove.add(info_location)
464465
installed_files = dist.iter_declared_entries()
465466
if installed_files is not None:
466467
for installed_file in installed_files:
@@ -486,7 +487,7 @@ def from_dist(cls, dist: BaseDistribution) -> "UninstallPathSet":
486487
paths_to_remove.add(f"{path}.pyc")
487488
paths_to_remove.add(f"{path}.pyo")
488489

489-
elif dist.installed_by_legacy_distutils:
490+
elif dist.installed_by_distutils:
490491
raise UninstallationError(
491492
"Cannot uninstall {!r}. It is a distutils installed project "
492493
"and thus we cannot accurately determine which files belong "

0 commit comments

Comments
 (0)