From 13eb511eeed05371342e3e47f14570b7d8990021 Mon Sep 17 00:00:00 2001 From: "Jens W. Klein" Date: Thu, 23 Oct 2025 16:59:41 +0200 Subject: [PATCH] Fix: Handle override_keys and ignore_keys in requirements process_line() now correctly comments out packages in override_keys and ignore_keys for both requirements and constraints files. Previously, these settings only applied to constraints files (variety="c"). Now they work for requirements files (variety="r") as well. Changes: - Remove variety=="c" condition from override_keys and ignore_keys checks - Add different message for override_keys in requirements: "-> mxdev disabled (version override)" vs "-> mxdev disabled (override)" - Add tests for requirements with override_keys and ignore_keys Tests: - Added test_process_line_package_in_override_keys - Added test_process_line_package_in_ignore_keys - All 176 tests pass --- CHANGES.md | 2 ++ src/mxdev/processing.py | 9 ++++++--- tests/test_processing.py | 30 ++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 3d69a5b..da42873 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,8 @@ ## 5.0.0 (unreleased) +- Fix: `process_line()` now correctly comments out packages in `override_keys` and `ignore_keys` for both requirements and constraints files. Previously, these settings only applied to constraints files (variety="c"). Now they work for requirements files (variety="r") as well, with the message "-> mxdev disabled (version override)" for override_keys in requirements. + [jensens] - **Breaking**: support for Python 3.8 and 3.9. Minimum required version is now Python 3.10. [jensens] - **Breaking**: Modernize type hints to use Python 3.10+ syntax (PEP 604: `X | Y` instead of `Union[X, Y]`) diff --git a/src/mxdev/processing.py b/src/mxdev/processing.py index 8855c7d..d6031d0 100644 --- a/src/mxdev/processing.py +++ b/src/mxdev/processing.py @@ -58,9 +58,12 @@ def process_line( parsed_name_lower = parsed.name.lower() if parsed_name_lower in [k.lower() for k in package_keys]: line = f"# {line.strip()} -> mxdev disabled (source)\n" - if variety == "c" and parsed_name_lower in [k.lower() for k in override_keys]: - line = f"# {line.strip()} -> mxdev disabled (override)\n" - if variety == "c" and parsed_name_lower in [k.lower() for k in ignore_keys]: + if parsed_name_lower in [k.lower() for k in override_keys]: + if variety == "c": + line = f"# {line.strip()} -> mxdev disabled (override)\n" + else: + line = f"# {line.strip()} -> mxdev disabled (version override)\n" + if parsed_name_lower in [k.lower() for k in ignore_keys]: line = f"# {line.strip()} -> mxdev disabled (ignore)\n" if variety == "c": return [], [line] diff --git a/tests/test_processing.py b/tests/test_processing.py index b470302..2d985de 100644 --- a/tests/test_processing.py +++ b/tests/test_processing.py @@ -61,6 +61,36 @@ def test_process_line_constraint_in_ignore_keys(): assert "# ignored.package==1.0.0 -> mxdev disabled (ignore)" in constraints[0] +def test_process_line_package_in_override_keys(): + """Test process_line comments out packages in override_keys.""" + from mxdev.processing import process_line + + requirements, constraints = process_line( + "my.package==1.0.0", + package_keys=[], + override_keys=["my.package"], + ignore_keys=[], + variety="r", + ) + assert requirements == ["# my.package==1.0.0 -> mxdev disabled (version override)\n"] + assert constraints == [] + + +def test_process_line_package_in_ignore_keys(): + """Test process_line comments out packages in ignore_keys.""" + from mxdev.processing import process_line + + requirements, constraints = process_line( + "my.package==1.0.0", + package_keys=[], + override_keys=[], + ignore_keys=["my.package"], + variety="r", + ) + assert requirements == ["# my.package==1.0.0 -> mxdev disabled (ignore)\n"] + assert constraints == [] + + def test_process_line_constraint(): """Test process_line with constraint variety.""" from mxdev.processing import process_line