1
- import functools
2
1
import importlib .metadata
3
2
import logging
4
3
import os
5
4
import pathlib
6
5
import sys
7
6
import zipfile
8
- import zipimport
9
7
from typing import Iterator , List , Optional , Sequence , Set , Tuple
10
8
11
9
from pip ._vendor .packaging .utils import (
16
14
)
17
15
18
16
from pip ._internal .metadata .base import BaseDistribution , BaseEnvironment
19
- from pip ._internal .utils .deprecation import deprecated
20
17
from pip ._internal .utils .filetypes import WHEEL_EXTENSION
21
18
22
19
from ._compat import BadMetadata , BasePath , get_dist_canonical_name , get_info_location
@@ -88,7 +85,7 @@ def find(self, location: str) -> Iterator[BaseDistribution]:
88
85
installed_location = info_location .parent
89
86
yield Distribution (dist , info_location , installed_location )
90
87
91
- def find_linked (self , location : str ) -> Iterator [BaseDistribution ]:
88
+ def find_legacy_editables (self , location : str ) -> Iterator [BaseDistribution ]:
92
89
"""Read location in egg-link files and return distributions in there.
93
90
94
91
The path should be a directory; otherwise this returns nothing. This
@@ -112,54 +109,6 @@ def find_linked(self, location: str) -> Iterator[BaseDistribution]:
112
109
for dist , info_location in self ._find_impl (target_location ):
113
110
yield Distribution (dist , info_location , path )
114
111
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
-
163
112
164
113
class Environment (BaseEnvironment ):
165
114
def __init__ (self , paths : Sequence [str ]) -> None :
@@ -179,12 +128,7 @@ def _iter_distributions(self) -> Iterator[BaseDistribution]:
179
128
finder = _DistributionFinder ()
180
129
for location in self ._paths :
181
130
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 )
188
132
189
133
def get_distribution (self , name : str ) -> Optional [BaseDistribution ]:
190
134
canonical_name = canonicalize_name (name )
0 commit comments