1- import functools
21import importlib .metadata
32import logging
43import os
54import pathlib
65import sys
76import zipfile
8- import zipimport
97from typing import Iterator , List , Optional , Sequence , Set , Tuple
108
119from pip ._vendor .packaging .utils import (
1614)
1715
1816from pip ._internal .metadata .base import BaseDistribution , BaseEnvironment
19- from pip ._internal .utils .deprecation import deprecated
2017from pip ._internal .utils .filetypes import WHEEL_EXTENSION
2118
2219from ._compat import BadMetadata , BasePath , get_dist_canonical_name , get_info_location
@@ -88,7 +85,7 @@ def find(self, location: str) -> Iterator[BaseDistribution]:
8885 installed_location = info_location .parent
8986 yield Distribution (dist , info_location , installed_location )
9087
91- def find_linked (self , location : str ) -> Iterator [BaseDistribution ]:
88+ def find_legacy_editables (self , location : str ) -> Iterator [BaseDistribution ]:
9289 """Read location in egg-link files and return distributions in there.
9390
9491 The path should be a directory; otherwise this returns nothing. This
@@ -112,54 +109,6 @@ def find_linked(self, location: str) -> Iterator[BaseDistribution]:
112109 for dist , info_location in self ._find_impl (target_location ):
113110 yield Distribution (dist , info_location , path )
114111
115- def _find_eggs_in_dir (self , location : str ) -> Iterator [BaseDistribution ]:
116- from pip ._vendor .pkg_resources import find_distributions
117-
118- from pip ._internal .metadata import pkg_resources as legacy
119-
120- with os .scandir (location ) as it :
121- for entry in it :
122- if not entry .name .endswith (".egg" ):
123- continue
124- for dist in find_distributions (entry .path ):
125- yield legacy .Distribution (dist )
126-
127- def _find_eggs_in_zip (self , location : str ) -> Iterator [BaseDistribution ]:
128- from pip ._vendor .pkg_resources import find_eggs_in_zip
129-
130- from pip ._internal .metadata import pkg_resources as legacy
131-
132- try :
133- importer = zipimport .zipimporter (location )
134- except zipimport .ZipImportError :
135- return
136- for dist in find_eggs_in_zip (importer , location ):
137- yield legacy .Distribution (dist )
138-
139- def find_eggs (self , location : str ) -> Iterator [BaseDistribution ]:
140- """Find eggs in a location.
141-
142- This actually uses the old *pkg_resources* backend. We likely want to
143- deprecate this so we can eventually remove the *pkg_resources*
144- dependency entirely. Before that, this should first emit a deprecation
145- warning for some versions when using the fallback since importing
146- *pkg_resources* is slow for those who don't need it.
147- """
148- if os .path .isdir (location ):
149- yield from self ._find_eggs_in_dir (location )
150- if zipfile .is_zipfile (location ):
151- yield from self ._find_eggs_in_zip (location )
152-
153-
154- @functools .lru_cache (maxsize = None ) # Warn a distribution exactly once.
155- def _emit_egg_deprecation (location : Optional [str ]) -> None :
156- deprecated (
157- reason = f"Loading egg at { location } is deprecated." ,
158- replacement = "to use pip for package installation" ,
159- gone_in = "25.1" ,
160- issue = 12330 ,
161- )
162-
163112
164113class Environment (BaseEnvironment ):
165114 def __init__ (self , paths : Sequence [str ]) -> None :
@@ -179,12 +128,7 @@ def _iter_distributions(self) -> Iterator[BaseDistribution]:
179128 finder = _DistributionFinder ()
180129 for location in self ._paths :
181130 yield from finder .find (location )
182- if sys .version_info < (3 , 14 ):
183- for dist in finder .find_eggs (location ):
184- _emit_egg_deprecation (dist .location )
185- yield dist
186- # This must go last because that's how pkg_resources tie-breaks.
187- yield from finder .find_linked (location )
131+ yield from finder .find_legacy_editables (location )
188132
189133 def get_distribution (self , name : str ) -> Optional [BaseDistribution ]:
190134 canonical_name = canonicalize_name (name )
0 commit comments