Skip to content

Commit

Permalink
Make sure user_supplied is propagated where needed
Browse files Browse the repository at this point in the history
  • Loading branch information
sbidoul committed May 21, 2020
1 parent 618aaa3 commit 8f7ef08
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 11 deletions.
10 changes: 5 additions & 5 deletions src/pip/_internal/cli/req_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,25 +309,25 @@ def get_requirements(
req_to_add = install_req_from_parsed_requirement(
parsed_req,
isolated=options.isolated_mode,
user_supplied=False,
)
req_to_add.user_supplied = False
requirements.append(req_to_add)

for req in args:
req_to_add = install_req_from_line(
req, None, isolated=options.isolated_mode,
use_pep517=options.use_pep517,
user_supplied=True,
)
req_to_add.user_supplied = True
requirements.append(req_to_add)

for req in options.editables:
req_to_add = install_req_from_editable(
req,
user_supplied=True,
isolated=options.isolated_mode,
use_pep517=options.use_pep517,
)
req_to_add.user_supplied = True
requirements.append(req_to_add)

# NOTE: options.require_hashes may be set if --require-hashes is True
Expand All @@ -338,9 +338,9 @@ def get_requirements(
req_to_add = install_req_from_parsed_requirement(
parsed_req,
isolated=options.isolated_mode,
use_pep517=options.use_pep517
use_pep517=options.use_pep517,
user_supplied=True,
)
req_to_add.user_supplied = True
requirements.append(req_to_add)

# If any requirement has hash options, enable hash checking.
Expand Down
20 changes: 16 additions & 4 deletions src/pip/_internal/req/constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,8 @@ def install_req_from_editable(
use_pep517=None, # type: Optional[bool]
isolated=False, # type: bool
options=None, # type: Optional[Dict[str, Any]]
constraint=False # type: bool
constraint=False, # type: bool
user_supplied=False, # type: bool
):
# type: (...) -> InstallRequirement

Expand All @@ -231,6 +232,7 @@ def install_req_from_editable(
return InstallRequirement(
parts.requirement,
comes_from=comes_from,
user_supplied=user_supplied,
editable=True,
link=parts.link,
constraint=constraint,
Expand Down Expand Up @@ -385,6 +387,7 @@ def install_req_from_line(
options=None, # type: Optional[Dict[str, Any]]
constraint=False, # type: bool
line_source=None, # type: Optional[str]
user_supplied=False, # type: bool
):
# type: (...) -> InstallRequirement
"""Creates an InstallRequirement from a name, which might be a
Expand All @@ -403,14 +406,16 @@ def install_req_from_line(
hash_options=options.get("hashes", {}) if options else {},
constraint=constraint,
extras=parts.extras,
user_supplied=user_supplied,
)


def install_req_from_req_string(
req_string, # type: str
comes_from=None, # type: Optional[InstallRequirement]
isolated=False, # type: bool
use_pep517=None # type: Optional[bool]
use_pep517=None, # type: Optional[bool]
user_supplied=False, # type: bool
):
# type: (...) -> InstallRequirement
try:
Expand All @@ -432,14 +437,19 @@ def install_req_from_req_string(
)

return InstallRequirement(
req, comes_from, isolated=isolated, use_pep517=use_pep517
req,
comes_from,
isolated=isolated,
use_pep517=use_pep517,
user_supplied=user_supplied,
)


def install_req_from_parsed_requirement(
parsed_req, # type: ParsedRequirement
isolated=False, # type: bool
use_pep517=None # type: Optional[bool]
use_pep517=None, # type: Optional[bool]
user_supplied=False, # type: bool
):
# type: (...) -> InstallRequirement
if parsed_req.is_editable:
Expand All @@ -449,6 +459,7 @@ def install_req_from_parsed_requirement(
use_pep517=use_pep517,
constraint=parsed_req.constraint,
isolated=isolated,
user_supplied=user_supplied,
)

else:
Expand All @@ -460,5 +471,6 @@ def install_req_from_parsed_requirement(
options=parsed_req.options,
constraint=parsed_req.constraint,
line_source=parsed_req.line_source,
user_supplied=user_supplied,
)
return req
5 changes: 3 additions & 2 deletions src/pip/_internal/req/req_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ def __init__(
global_options=None, # type: Optional[List[str]]
hash_options=None, # type: Optional[Dict[str, List[str]]]
constraint=False, # type: bool
extras=() # type: Iterable[str]
extras=(), # type: Iterable[str]
user_supplied=False, # type: bool
):
# type: (...) -> None
assert req is None or isinstance(req, Requirement), req
Expand Down Expand Up @@ -174,7 +175,7 @@ def __init__(
# User supplied requirement are explicitly requested for installation
# by the user via CLI arguments or requirements files, as opposed to,
# e.g. dependencies, extras or constraints.
self.user_supplied = False
self.user_supplied = user_supplied

# Set by the legacy resolver when the requirement has been downloaded
# TODO: This introduces a strong coupling between the resolver and the
Expand Down
3 changes: 3 additions & 0 deletions src/pip/_internal/resolution/resolvelib/candidates.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def make_install_req_from_link(link, parent):
line = link.url
ireq = install_req_from_line(
line,
user_supplied=parent.user_supplied,
comes_from=parent.comes_from,
use_pep517=parent.use_pep517,
isolated=parent.isolated,
Expand All @@ -68,6 +69,7 @@ def make_install_req_from_editable(link, parent):
assert parent.editable, "parent not editable"
return install_req_from_editable(
link.url,
user_supplied=parent.user_supplied,
comes_from=parent.comes_from,
use_pep517=parent.use_pep517,
isolated=parent.isolated,
Expand All @@ -91,6 +93,7 @@ def make_install_req_from_dist(dist, parent):
line = "{}=={}".format(project_name, dist.parsed_version)
ireq = install_req_from_line(
line,
user_supplied=parent.user_supplied,
comes_from=parent.comes_from,
use_pep517=parent.use_pep517,
isolated=parent.isolated,
Expand Down

0 comments on commit 8f7ef08

Please sign in to comment.