Skip to content

Commit a226f65

Browse files
committed
A constraint is not a top level requirement
1 parent c9a4457 commit a226f65

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

src/pip/_internal/cli/req_command.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ def get_requirements(
310310
parsed_req,
311311
isolated=options.isolated_mode,
312312
)
313-
req_to_add.is_direct = True
313+
req_to_add.is_direct = False
314314
requirements.append(req_to_add)
315315

316316
for req in args:

src/pip/_internal/req/req_set.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,8 @@ def add_requirement(
107107
)
108108

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

115114
# Unnamed requirements are scanned again and the requirement won't be
@@ -165,6 +164,10 @@ def add_requirement(
165164
# If we're now installing a constraint, mark the existing
166165
# object for real installation.
167166
existing_req.constraint = False
167+
# If we're now installing a top level requirement, mark the existing
168+
# object as top level.
169+
if install_req.is_direct:
170+
existing_req.is_direct = True
168171
existing_req.extras = tuple(sorted(
169172
set(existing_req.extras) | set(install_req.extras)
170173
))

src/pip/_internal/resolution/legacy/resolver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ def _is_upgrade_allowed(self, req):
195195
return True
196196
else:
197197
assert self.upgrade_strategy == "only-if-needed"
198-
return req.is_direct
198+
return req.is_direct or req.constraint
199199

200200
def _set_req_to_reinstall(self, req):
201201
# type: (InstallRequirement) -> None

0 commit comments

Comments
 (0)