From f8edc696f41b6f2bead2fe35b17bad5d8ba0dda8 Mon Sep 17 00:00:00 2001 From: Ralf Gommers Date: Tue, 26 Nov 2024 13:02:35 +0100 Subject: [PATCH] Make the `python_min` linter check robust against if-else syntax (#2154) * Make the `python_min` linter check robust against if-else syntax In `noarch: python` recipes, the thing being checked here should always have `python` as a string and not in an `if:` block, so it should be safe to skip the check. Fixes the linter failing on rattler-build recipes with conditional requirements. * refactor+doc+test: use new util function, added news item, and added tests --------- Co-authored-by: Matthew R. Becker Co-authored-by: beckermr --- conda_smithy/linter/hints.py | 6 +++ news/2154-fix-python_min-v1-hint.rst | 23 +++++++++++ tests/test_lint_recipe.py | 60 ++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+) create mode 100644 news/2154-fix-python_min-v1-hint.rst diff --git a/conda_smithy/linter/hints.py b/conda_smithy/linter/hints.py index 290e39d2b..41cad5c40 100644 --- a/conda_smithy/linter/hints.py +++ b/conda_smithy/linter/hints.py @@ -11,6 +11,7 @@ from conda_smithy.linter.utils import ( VALID_PYTHON_BUILD_BACKENDS, find_local_config_file, + flatten_v1_if_else, is_selector_line, ) from conda_smithy.utils import get_yaml @@ -245,6 +246,11 @@ def hint_noarch_python_use_python_min( hints, ): if noarch_value == "python" and not outputs_section: + if recipe_version == 1: + host_reqs = flatten_v1_if_else(host_reqs) + run_reqs = flatten_v1_if_else(run_reqs) + test_reqs = flatten_v1_if_else(test_reqs) + hint = "" for section_name, syntax, report_syntax, reqs in [ ( diff --git a/news/2154-fix-python_min-v1-hint.rst b/news/2154-fix-python_min-v1-hint.rst new file mode 100644 index 000000000..d18135caa --- /dev/null +++ b/news/2154-fix-python_min-v1-hint.rst @@ -0,0 +1,23 @@ +**Added:** + +* + +**Changed:** + +* + +**Deprecated:** + +* + +**Removed:** + +* + +**Fixed:** + +* Fixed a bug where the ``python_min`` hint failed on v1 recipes. (#2154) + +**Security:** + +* diff --git a/tests/test_lint_recipe.py b/tests/test_lint_recipe.py index 9a8a04d12..4534fd7da 100644 --- a/tests/test_lint_recipe.py +++ b/tests/test_lint_recipe.py @@ -3358,6 +3358,66 @@ def test_hint_noarch_python_use_python_min( ), [], ), + ( + textwrap.dedent( + """ + package: + name: python + + requirements: + run: + - if: blah + then: python + else: python 3.7 + """ + ), + [], + ), + ( + textwrap.dedent( + """ + package: + name: python + + build: + noarch: python + + requirements: + run: + - if: blah + then: python + """ + ), + [ + "python ${{ python_min }}", + "python >=${{ python_min }}", + ], + ), + ( + textwrap.dedent( + """ + package: + name: python + + build: + noarch: python + + requirements: + host: + - if: blah + then: blahblah + else: python ${{ python_min }} + run: + - python >=${{ python_min }} + + tests: + - requirements: + run: + - python ${{ python_min }} + """ + ), + [], + ), ], ) def test_hint_noarch_python_use_python_min_v1(