Skip to content

Commit

Permalink
A constraint is not a top level requirement
Browse files Browse the repository at this point in the history
  • Loading branch information
sbidoul committed Apr 12, 2020
1 parent b114a52 commit 8bc9185
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/pip/_internal/cli/req_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ def get_requirements(
parsed_req,
isolated=options.isolated_mode,
)
req_to_add.is_direct = True
req_to_add.is_direct = False
requirement_set.add_requirement(req_to_add)

for req in args:
Expand Down
9 changes: 6 additions & 3 deletions src/pip/_internal/req/req_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,8 @@ def add_requirement(
)

# This next bit is really a sanity check.
assert install_req.is_direct == (parent_req_name is None), (
"a direct req shouldn't have a parent and also, "
"a non direct req should have a parent"
assert not install_req.is_direct or parent_req_name is None, (
"a direct req shouldn't have a parent"
)

# Unnamed requirements are scanned again and the requirement won't be
Expand Down Expand Up @@ -167,6 +166,10 @@ def add_requirement(
# If we're now installing a constraint, mark the existing
# object for real installation.
existing_req.constraint = False
# If we're now installing a top level requirement, mark the existing
# object as top level.
if install_req.is_direct:
existing_req.is_direct = True
existing_req.extras = tuple(sorted(
set(existing_req.extras) | set(install_req.extras)
))
Expand Down
2 changes: 1 addition & 1 deletion src/pip/_internal/resolution/legacy/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def _is_upgrade_allowed(self, req):
return True
else:
assert self.upgrade_strategy == "only-if-needed"
return req.is_direct
return req.is_direct or req.constraint

def _set_req_to_reinstall(self, req):
# type: (InstallRequirement) -> None
Expand Down

0 comments on commit 8bc9185

Please sign in to comment.