From a143087b6df5bdb6e2c6bfc25339fe0d862d7d92 Mon Sep 17 00:00:00 2001 From: khanhdq Date: Fri, 19 Aug 2022 05:46:22 +0900 Subject: [PATCH 1/4] Add more test for get_constraints_from_deps --- tests/unit/test_utils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.py index 27a7806700..9c99f0ad09 100644 --- a/tests/unit/test_utils.py +++ b/tests/unit/test_utils.py @@ -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): From 625c79081d192107ca3cf73b30a1795281b8e5a4 Mon Sep 17 00:00:00 2001 From: khanhdq Date: Fri, 19 Aug 2022 05:52:15 +0900 Subject: [PATCH 2/4] Convert Requirement to InstallRequirement before checking constraint. --- pipenv/utils/dependencies.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pipenv/utils/dependencies.py b/pipenv/utils/dependencies.py index 70b4c31531..7b0785f28c 100644 --- a/pipenv/utils/dependencies.py +++ b/pipenv/utils/dependencies.py @@ -287,7 +287,8 @@ def get_constraints_from_deps(deps): 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 + ireq = dep.as_ireq() + return ireq.name and not ireq.editable and not ireq.extras constraints = [] for dep_name, dep in deps.items(): From bbad8be6bf2d54f6220e8405c91f81ac32165761 Mon Sep 17 00:00:00 2001 From: khanhdq Date: Fri, 19 Aug 2022 06:43:26 +0900 Subject: [PATCH 3/4] Use pip's check_invalid_constraint_type. --- pipenv/utils/dependencies.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pipenv/utils/dependencies.py b/pipenv/utils/dependencies.py index 7b0785f28c..183a19203a 100644 --- a/pipenv/utils/dependencies.py +++ b/pipenv/utils/dependencies.py @@ -282,13 +282,14 @@ 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. - ireq = dep.as_ireq() - return ireq.name and not ireq.editable and not ireq.extras + problem = check_invalid_constraint_type(dep.as_ireq()) + return not problem constraints = [] for dep_name, dep in deps.items(): From 568ab5558f769b92a8de8e330fe5055d22ae7513 Mon Sep 17 00:00:00 2001 From: khanhdq Date: Fri, 19 Aug 2022 07:13:16 +0900 Subject: [PATCH 4/4] Remove is_constrant. --- pipenv/utils/dependencies.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/pipenv/utils/dependencies.py b/pipenv/utils/dependencies.py index 183a19203a..2cf1af441b 100644 --- a/pipenv/utils/dependencies.py +++ b/pipenv/utils/dependencies.py @@ -287,14 +287,11 @@ def get_constraints_from_deps(deps): ) from pipenv.vendor.requirementslib.models.requirements import Requirement - def is_constraint(dep): - problem = check_invalid_constraint_type(dep.as_ireq()) - return not problem - 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