5
5
import os
6
6
import re
7
7
8
- from pip ._vendor import pkg_resources , six
8
+ from pip ._vendor import six
9
9
from pip ._vendor .packaging .utils import canonicalize_name
10
10
from pip ._vendor .pkg_resources import RequirementParseError
11
11
12
- from pip ._internal .exceptions import InstallationError
12
+ from pip ._internal .exceptions import BadCommand , InstallationError
13
13
from pip ._internal .req .constructors import (
14
14
install_req_from_editable , install_req_from_line ,
15
15
)
@@ -34,27 +34,14 @@ def freeze(
34
34
if skip_regex :
35
35
skip_match = re .compile (skip_regex ).search
36
36
37
- dependency_links = []
38
-
39
- for dist in pkg_resources .working_set :
40
- if dist .has_metadata ('dependency_links.txt' ):
41
- dependency_links .extend (
42
- dist .get_metadata_lines ('dependency_links.txt' )
43
- )
44
- for link in find_links :
45
- if '#egg=' in link :
46
- dependency_links .append (link )
47
37
for link in find_links :
48
38
yield '-f %s' % link
49
39
installations = {}
50
40
for dist in get_installed_distributions (local_only = local_only ,
51
41
skip = (),
52
42
user_only = user_only ):
53
43
try :
54
- req = FrozenRequirement .from_dist (
55
- dist ,
56
- dependency_links
57
- )
44
+ req = FrozenRequirement .from_dist (dist )
58
45
except RequirementParseError :
59
46
logger .warning (
60
47
"Could not parse requirement: %s" ,
@@ -156,56 +143,64 @@ def freeze(
156
143
yield str (installation ).rstrip ()
157
144
158
145
159
- class FrozenRequirement (object ):
160
- def __init__ (self , name , req , editable , comments = ()):
161
- self .name = name
162
- self .req = req
163
- self .editable = editable
164
- self .comments = comments
146
+ def get_requirement_info (dist ):
147
+ """
148
+ Compute and return values (req, editable, comments) for use in
149
+ FrozenRequirement.from_dist().
150
+ """
151
+ if not dist_is_editable (dist ):
152
+ return (None , False , [])
165
153
166
- @classmethod
167
- def _init_args_from_dist (cls , dist , dependency_links ):
168
- """
169
- Compute and return arguments (req, editable, comments) to pass to
170
- FrozenRequirement.__init__().
171
-
172
- This method is for use in FrozenRequirement.from_dist().
173
- """
174
- location = os .path .normcase (os .path .abspath (dist .location ))
175
- from pip ._internal .vcs import vcs , get_src_requirement
176
- if not dist_is_editable (dist ):
177
- req = dist .as_requirement ()
178
- return (req , False , [])
154
+ location = os .path .normcase (os .path .abspath (dist .location ))
179
155
180
- vc_type = vcs .get_backend_type (location )
156
+ from pip ._internal .vcs import vcs
157
+ vc_type = vcs .get_backend_type (location )
181
158
182
- if not vc_type :
183
- req = dist .as_requirement ()
184
- return (req , False , [])
159
+ if not vc_type :
160
+ return (None , False , [])
185
161
186
- try :
187
- req = get_src_requirement (vc_type , dist , location )
188
- except InstallationError as exc :
189
- logger .warning (
190
- "Error when trying to get requirement for VCS system %s, "
191
- "falling back to uneditable format" , exc
192
- )
193
- else :
194
- if req is not None :
195
- return (req , True , [])
162
+ try :
163
+ req = vc_type (). get_src_requirement (dist , location )
164
+ except BadCommand :
165
+ logger .warning (
166
+ 'cannot determine version of editable source in %s '
167
+ '(%s command not found in path)' ,
168
+ location ,
169
+ vc_type . name ,
170
+ )
171
+ return (None , True , [])
196
172
173
+ except InstallationError as exc :
197
174
logger .warning (
198
- 'Could not determine repository location of %s' , location
175
+ "Error when trying to get requirement for VCS system %s, "
176
+ "falling back to uneditable format" , exc
199
177
)
200
- comments = ['## !! Could not determine repository location' ]
201
- req = dist .as_requirement ()
178
+ else :
179
+ if req is not None :
180
+ return (req , True , [])
181
+
182
+ logger .warning (
183
+ 'Could not determine repository location of %s' , location
184
+ )
185
+ comments = ['## !! Could not determine repository location' ]
202
186
203
- return (req , False , comments )
187
+ return (None , False , comments )
188
+
189
+
190
+ class FrozenRequirement (object ):
191
+ def __init__ (self , name , req , editable , comments = ()):
192
+ self .name = name
193
+ self .req = req
194
+ self .editable = editable
195
+ self .comments = comments
204
196
205
197
@classmethod
206
- def from_dist (cls , dist , dependency_links ):
207
- args = cls ._init_args_from_dist (dist , dependency_links )
208
- return cls (dist .project_name , * args )
198
+ def from_dist (cls , dist ):
199
+ req , editable , comments = get_requirement_info (dist )
200
+ if req is None :
201
+ req = dist .as_requirement ()
202
+
203
+ return cls (dist .project_name , req , editable , comments = comments )
209
204
210
205
def __str__ (self ):
211
206
req = self .req
0 commit comments