Skip to content

Commit 16f1b4b

Browse files
authored
Merge pull request #7046 from chrahunt/refactor/constructors-req-parsing
Refactoring req.constructors requirement parsing
2 parents 67856e3 + d0336be commit 16f1b4b

File tree

1 file changed

+40
-19
lines changed

1 file changed

+40
-19
lines changed

src/pip/_internal/req/constructors.py

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -272,23 +272,22 @@ def _get_url_from_path(path, name):
272272
return path_to_url(path)
273273

274274

275-
def install_req_from_line(
276-
name, # type: str
277-
comes_from=None, # type: Optional[Union[str, InstallRequirement]]
278-
use_pep517=None, # type: Optional[bool]
279-
isolated=False, # type: bool
280-
options=None, # type: Optional[Dict[str, Any]]
281-
wheel_cache=None, # type: Optional[WheelCache]
282-
constraint=False, # type: bool
283-
line_source=None, # type: Optional[str]
284-
):
285-
# type: (...) -> InstallRequirement
286-
"""Creates an InstallRequirement from a name, which might be a
287-
requirement, directory containing 'setup.py', filename, or URL.
288-
289-
:param line_source: An optional string describing where the line is from,
290-
for logging purposes in case of an error.
291-
"""
275+
class RequirementParts(object):
276+
def __init__(
277+
self,
278+
requirement, # type: Optional[Requirement]
279+
link, # type: Optional[Link]
280+
markers, # type: Optional[Marker]
281+
extras, # type: Set[str]
282+
):
283+
self.requirement = requirement
284+
self.link = link
285+
self.markers = markers
286+
self.extras = extras
287+
288+
289+
def parse_req_from_line(name, line_source):
290+
# type: (str, Optional[str]) -> RequirementParts
292291
if is_url(name):
293292
marker_sep = '; '
294293
else:
@@ -363,13 +362,35 @@ def with_source(text):
363362
else:
364363
req = None
365364

365+
return RequirementParts(req, link, markers, extras)
366+
367+
368+
def install_req_from_line(
369+
name, # type: str
370+
comes_from=None, # type: Optional[Union[str, InstallRequirement]]
371+
use_pep517=None, # type: Optional[bool]
372+
isolated=False, # type: bool
373+
options=None, # type: Optional[Dict[str, Any]]
374+
wheel_cache=None, # type: Optional[WheelCache]
375+
constraint=False, # type: bool
376+
line_source=None, # type: Optional[str]
377+
):
378+
# type: (...) -> InstallRequirement
379+
"""Creates an InstallRequirement from a name, which might be a
380+
requirement, directory containing 'setup.py', filename, or URL.
381+
382+
:param line_source: An optional string describing where the line is from,
383+
for logging purposes in case of an error.
384+
"""
385+
parts = parse_req_from_line(name, line_source)
386+
366387
return InstallRequirement(
367-
req, comes_from, link=link, markers=markers,
388+
parts.requirement, comes_from, link=parts.link, markers=parts.markers,
368389
use_pep517=use_pep517, isolated=isolated,
369390
options=options if options else {},
370391
wheel_cache=wheel_cache,
371392
constraint=constraint,
372-
extras=extras,
393+
extras=parts.extras,
373394
)
374395

375396

0 commit comments

Comments
 (0)