From 1652fe6aabe8de3ec1f01dc54d1adb6c376bd119 Mon Sep 17 00:00:00 2001 From: shouzy <82171453+realshouzy@users.noreply.github.com> Date: Tue, 11 Jun 2024 19:17:45 +0200 Subject: [PATCH] Consider inline comments when parsing constraints files --- pip_manage/pip_review.py | 2 +- tests/pip_review_test.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/pip_manage/pip_review.py b/pip_manage/pip_review.py index 96ff1b4a..7a3e2d53 100755 --- a/pip_manage/pip_review.py +++ b/pip_manage/pip_review.py @@ -179,7 +179,7 @@ def _set_constraints_of_outdated_pkgs( for line in file.read_text(encoding="utf-8").splitlines(): if line.lstrip().startswith("#"): continue - pkg_name, _, constraint_version = line.partition("==") + pkg_name, _, constraint_version = line.partition("#")[0].partition("==") for pkg in outdated: if pkg.name == pkg_name.strip(): pkg.constraints.add(constraint_version.strip()) diff --git a/tests/pip_review_test.py b/tests/pip_review_test.py index 77519065..cfffbee2 100755 --- a/tests/pip_review_test.py +++ b/tests/pip_review_test.py @@ -285,6 +285,7 @@ def test_get_constraints_files_with_named_args_and_dont_ignore_constraints_env_v ("constraints", "expected"), [ ("test2==1.9.9.9", {"1.9.9.9"}), + ("test2==1.9.9.9 # test", {"1.9.9.9"}), ("test2==1.9.9.9\n#test", {"1.9.9.9"}), (" test2 == 1.9.9.9 ", {"1.9.9.9"}), ],