Skip to content

Commit 4e6bdf6

Browse files
authored
Merge pull request #5881 from cjerdonek/remove-vcs-get-src-requirement
Remove the module-level get_src_requirement().
2 parents 06ccf39 + 46ffb13 commit 4e6bdf6

File tree

3 files changed

+51
-69
lines changed

3 files changed

+51
-69
lines changed

news/EFE4CACD-41B3-478D-926D-2069D76A6059.trivial

Whitespace-only changes.

src/pip/_internal/operations/freeze.py

Lines changed: 51 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
import os
66
import re
77

8-
from pip._vendor import pkg_resources, six
8+
from pip._vendor import six
99
from pip._vendor.packaging.utils import canonicalize_name
1010
from pip._vendor.pkg_resources import RequirementParseError
1111

12-
from pip._internal.exceptions import InstallationError
12+
from pip._internal.exceptions import BadCommand, InstallationError
1313
from pip._internal.req.constructors import (
1414
install_req_from_editable, install_req_from_line,
1515
)
@@ -34,27 +34,14 @@ def freeze(
3434
if skip_regex:
3535
skip_match = re.compile(skip_regex).search
3636

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)
4737
for link in find_links:
4838
yield '-f %s' % link
4939
installations = {}
5040
for dist in get_installed_distributions(local_only=local_only,
5141
skip=(),
5242
user_only=user_only):
5343
try:
54-
req = FrozenRequirement.from_dist(
55-
dist,
56-
dependency_links
57-
)
44+
req = FrozenRequirement.from_dist(dist)
5845
except RequirementParseError:
5946
logger.warning(
6047
"Could not parse requirement: %s",
@@ -156,56 +143,64 @@ def freeze(
156143
yield str(installation).rstrip()
157144

158145

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, [])
165153

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))
179155

180-
vc_type = vcs.get_backend_type(location)
156+
from pip._internal.vcs import vcs
157+
vc_type = vcs.get_backend_type(location)
181158

182-
if not vc_type:
183-
req = dist.as_requirement()
184-
return (req, False, [])
159+
if not vc_type:
160+
return (None, False, [])
185161

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, [])
196172

173+
except InstallationError as exc:
197174
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
199177
)
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']
202186

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
204196

205197
@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)
209204

210205
def __str__(self):
211206
req = self.req

src/pip/_internal/vcs/__init__.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -479,16 +479,3 @@ def controls_location(cls, location):
479479
the Git override checks that Git is actually available.
480480
"""
481481
return cls.is_repository_directory(location)
482-
483-
484-
def get_src_requirement(vc_type, dist, location):
485-
try:
486-
return vc_type().get_src_requirement(dist, location)
487-
except BadCommand:
488-
logger.warning(
489-
'cannot determine version of editable source in %s '
490-
'(%s command not found in path)',
491-
location,
492-
vc_type.name,
493-
)
494-
return dist.as_requirement()

0 commit comments

Comments
 (0)