1
1
import collections
2
2
import logging
3
3
import os
4
- from typing import (
5
- Container ,
6
- Dict ,
7
- Iterable ,
8
- Iterator ,
9
- List ,
10
- NamedTuple ,
11
- Optional ,
12
- Set ,
13
- Union ,
14
- )
4
+ from typing import Container , Dict , Iterable , Iterator , List , NamedTuple , Optional , Set
15
5
16
- from pip ._vendor .packaging .requirements import Requirement
17
6
from pip ._vendor .packaging .utils import canonicalize_name
18
7
from pip ._vendor .packaging .version import Version
19
8
30
19
31
20
32
21
class _EditableInfo (NamedTuple ):
33
- requirement : Optional [str ]
34
- editable : bool
22
+ requirement : str
35
23
comments : List [str ]
36
24
37
25
@@ -164,11 +152,9 @@ def _format_as_name_version(dist: BaseDistribution) -> str:
164
152
165
153
def _get_editable_info (dist : BaseDistribution ) -> _EditableInfo :
166
154
"""
167
- Compute and return values (req, editable, comments) for use in
155
+ Compute and return values (req, comments) for use in
168
156
FrozenRequirement.from_dist().
169
157
"""
170
- if not dist .editable :
171
- return _EditableInfo (requirement = None , editable = False , comments = [])
172
158
editable_project_location = dist .editable_project_location
173
159
assert editable_project_location
174
160
location = os .path .normcase (os .path .abspath (editable_project_location ))
@@ -186,7 +172,6 @@ def _get_editable_info(dist: BaseDistribution) -> _EditableInfo:
186
172
)
187
173
return _EditableInfo (
188
174
requirement = location ,
189
- editable = True ,
190
175
comments = [f"# Editable install with no version control ({ display } )" ],
191
176
)
192
177
@@ -198,44 +183,35 @@ def _get_editable_info(dist: BaseDistribution) -> _EditableInfo:
198
183
display = _format_as_name_version (dist )
199
184
return _EditableInfo (
200
185
requirement = location ,
201
- editable = True ,
202
186
comments = [f"# Editable { vcs_name } install with no remote ({ display } )" ],
203
187
)
204
188
except RemoteNotValidError as ex :
205
189
display = _format_as_name_version (dist )
206
190
return _EditableInfo (
207
191
requirement = location ,
208
- editable = True ,
209
192
comments = [
210
193
f"# Editable { vcs_name } install ({ display } ) with either a deleted "
211
194
f"local remote or invalid URI:" ,
212
195
f"# '{ ex .url } '" ,
213
196
],
214
197
)
215
-
216
198
except BadCommand :
217
199
logger .warning (
218
200
"cannot determine version of editable source in %s "
219
201
"(%s command not found in path)" ,
220
202
location ,
221
203
vcs_backend .name ,
222
204
)
223
- return _EditableInfo (requirement = None , editable = True , comments = [])
224
-
205
+ return _EditableInfo (requirement = location , comments = [])
225
206
except InstallationError as exc :
226
- logger .warning (
227
- "Error when trying to get requirement for VCS system %s, "
228
- "falling back to uneditable format" ,
229
- exc ,
230
- )
207
+ logger .warning ("Error when trying to get requirement for VCS system %s" , exc )
231
208
else :
232
- return _EditableInfo (requirement = req , editable = True , comments = [])
209
+ return _EditableInfo (requirement = req , comments = [])
233
210
234
211
logger .warning ("Could not determine repository location of %s" , location )
235
212
236
213
return _EditableInfo (
237
- requirement = None ,
238
- editable = False ,
214
+ requirement = location ,
239
215
comments = ["## !! Could not determine repository location" ],
240
216
)
241
217
@@ -244,7 +220,7 @@ class FrozenRequirement:
244
220
def __init__ (
245
221
self ,
246
222
name : str ,
247
- req : Union [ str , Requirement ] ,
223
+ req : str ,
248
224
editable : bool ,
249
225
comments : Iterable [str ] = (),
250
226
) -> None :
@@ -256,19 +232,18 @@ def __init__(
256
232
257
233
@classmethod
258
234
def from_dist (cls , dist : BaseDistribution ) -> "FrozenRequirement" :
259
- # TODO `get_requirement_info` is taking care of editable requirements.
260
- # TODO This should be refactored when we will add detection of
261
- # editable that provide .dist-info metadata.
262
- req , editable , comments = _get_editable_info (dist )
263
- if req is None and not editable :
264
- # if PEP 610 metadata is present, attempt to use it
235
+ editable = dist .editable
236
+ if editable :
237
+ req , comments = _get_editable_info (dist )
238
+ else :
239
+ comments = []
265
240
direct_url = dist .direct_url
266
241
if direct_url :
242
+ # if PEP 610 metadata is present, use it
267
243
req = direct_url_as_pep440_direct_reference (direct_url , dist .raw_name )
268
- comments = []
269
- if req is None :
270
- # name==version requirement
271
- req = _format_as_name_version (dist )
244
+ else :
245
+ # name==version requirement
246
+ req = _format_as_name_version (dist )
272
247
273
248
return cls (dist .raw_name , req , editable , comments = comments )
274
249
0 commit comments