Skip to content

Commit

Permalink
Issue 5273 constraints are not recognized (#5274)
Browse files Browse the repository at this point in the history
* Add more test for get_constraints_from_deps
* Use pip's check_invalid_constraint_type.
  • Loading branch information
dqkqd authored Aug 18, 2022
1 parent 4c39314 commit 640612d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
11 changes: 5 additions & 6 deletions pipenv/utils/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,17 +282,16 @@ def convert_deps_to_pip(

def get_constraints_from_deps(deps):
"""Get contraints from Pipfile-formatted dependency"""
from pipenv.patched.pip._internal.req.req_install import (
check_invalid_constraint_type,
)
from pipenv.vendor.requirementslib.models.requirements import Requirement

def is_constraint(dep):
# https://pip.pypa.io/en/stable/user_guide/#constraints-files
# constraints must have a name, they cannot be editable, and they cannot specify extras.
return dep.name and not dep.editable and not dep.extras

constraints = []
for dep_name, dep in deps.items():
new_dep = Requirement.from_pipfile(dep_name, dep)
if is_constraint(new_dep):
problem = check_invalid_constraint_type(new_dep.as_ireq())
if not problem:
c = new_dep.as_line().strip()
constraints.append(c)
return constraints
Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ def test_convert_deps_to_pip_one_way(deps, expected):
({"requests": {"extras": ["security"]}}, []),
({"requests": {"extras": []}}, ["requests"]),
({"extras" : {}}, ["extras"]),
({"uvicorn[standard]" : {}}, [])
],
)
def test_get_constraints_from_deps(deps, expected):
Expand Down

0 comments on commit 640612d

Please sign in to comment.