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 NormalizedName , canonicalize_name
12
10
13
11
from pip ._internal .metadata .base import BaseDistribution , BaseEnvironment
14
12
from pip ._internal .models .wheel import Wheel
15
- from pip ._internal .utils .deprecation import deprecated
16
13
from pip ._internal .utils .filetypes import WHEEL_EXTENSION
17
14
18
15
from ._compat import BadMetadata , BasePath , get_dist_name , get_info_location
@@ -107,53 +104,6 @@ def find_linked(self, location: str) -> Iterator[BaseDistribution]:
107
104
for dist , info_location in self ._find_impl (target_location ):
108
105
yield Distribution (dist , info_location , path )
109
106
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
-
157
107
158
108
class Environment (BaseEnvironment ):
159
109
def __init__ (self , paths : Sequence [str ]) -> None :
@@ -173,9 +123,6 @@ def _iter_distributions(self) -> Iterator[BaseDistribution]:
173
123
finder = _DistributionFinder ()
174
124
for location in self ._paths :
175
125
yield from finder .find (location )
176
- for dist in finder .find_eggs (location ):
177
- _emit_egg_deprecation (dist .location )
178
- yield dist
179
126
# This must go last because that's how pkg_resources tie-breaks.
180
127
yield from finder .find_linked (location )
181
128
0 commit comments