Skip to content

Commit c6c8914

Browse files
committed
Remove support for installed eggs distributions
1 parent 6d4b551 commit c6c8914

File tree

2 files changed

+1
-53
lines changed

2 files changed

+1
-53
lines changed

news/12308.removal.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Remove support for discovering installed ``egg`` distributions, on Python 3.11+.

src/pip/_internal/metadata/importlib/_envs.py

-53
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
1-
import functools
21
import importlib.metadata
32
import logging
43
import os
54
import pathlib
65
import sys
76
import zipfile
8-
import zipimport
97
from typing import Iterator, List, Optional, Sequence, Set, Tuple
108

119
from pip._vendor.packaging.utils import NormalizedName, canonicalize_name
1210

1311
from pip._internal.metadata.base import BaseDistribution, BaseEnvironment
1412
from pip._internal.models.wheel import Wheel
15-
from pip._internal.utils.deprecation import deprecated
1613
from pip._internal.utils.filetypes import WHEEL_EXTENSION
1714

1815
from ._compat import BadMetadata, BasePath, get_dist_name, get_info_location
@@ -107,53 +104,6 @@ def find_linked(self, location: str) -> Iterator[BaseDistribution]:
107104
for dist, info_location in self._find_impl(target_location):
108105
yield Distribution(dist, info_location, path)
109106

110-
def _find_eggs_in_dir(self, location: str) -> Iterator[BaseDistribution]:
111-
from pip._vendor.pkg_resources import find_distributions
112-
113-
from pip._internal.metadata import pkg_resources as legacy
114-
115-
with os.scandir(location) as it:
116-
for entry in it:
117-
if not entry.name.endswith(".egg"):
118-
continue
119-
for dist in find_distributions(entry.path):
120-
yield legacy.Distribution(dist)
121-
122-
def _find_eggs_in_zip(self, location: str) -> Iterator[BaseDistribution]:
123-
from pip._vendor.pkg_resources import find_eggs_in_zip
124-
125-
from pip._internal.metadata import pkg_resources as legacy
126-
127-
try:
128-
importer = zipimport.zipimporter(location)
129-
except zipimport.ZipImportError:
130-
return
131-
for dist in find_eggs_in_zip(importer, location):
132-
yield legacy.Distribution(dist)
133-
134-
def find_eggs(self, location: str) -> Iterator[BaseDistribution]:
135-
"""Find eggs in a location.
136-
137-
This actually uses the old *pkg_resources* backend. We likely want to
138-
deprecate this so we can eventually remove the *pkg_resources*
139-
dependency entirely. Before that, this should first emit a deprecation
140-
warning for some versions when using the fallback since importing
141-
*pkg_resources* is slow for those who don't need it.
142-
"""
143-
if os.path.isdir(location):
144-
yield from self._find_eggs_in_dir(location)
145-
if zipfile.is_zipfile(location):
146-
yield from self._find_eggs_in_zip(location)
147-
148-
149-
@functools.lru_cache(maxsize=None) # Warn a distribution exactly once.
150-
def _emit_egg_deprecation(location: Optional[str]) -> None:
151-
deprecated(
152-
reason=f"Loading egg at {location} is deprecated.",
153-
replacement="to use pip for package installation.",
154-
gone_in="23.3",
155-
)
156-
157107

158108
class Environment(BaseEnvironment):
159109
def __init__(self, paths: Sequence[str]) -> None:
@@ -173,9 +123,6 @@ def _iter_distributions(self) -> Iterator[BaseDistribution]:
173123
finder = _DistributionFinder()
174124
for location in self._paths:
175125
yield from finder.find(location)
176-
for dist in finder.find_eggs(location):
177-
_emit_egg_deprecation(dist.location)
178-
yield dist
179126
# This must go last because that's how pkg_resources tie-breaks.
180127
yield from finder.find_linked(location)
181128

0 commit comments

Comments
 (0)