diff --git a/conda_smithy/linter/hints.py b/conda_smithy/linter/hints.py index 21c99a1a7..290e39d2b 100644 --- a/conda_smithy/linter/hints.py +++ b/conda_smithy/linter/hints.py @@ -246,15 +246,33 @@ def hint_noarch_python_use_python_min( ): if noarch_value == "python" and not outputs_section: hint = "" - for section_name, syntax, reqs in [ - ("host", "python {{ python_min }}", host_reqs), - ("run", "python >={{ python_min }}", run_reqs), - ("test.requires", "python {{ python_min }}", test_reqs), + for section_name, syntax, report_syntax, reqs in [ + ( + "host", + r"python\s+{{ python_min }}", + "python {{ python_min }}", + host_reqs, + ), + ( + "run", + r"python\s+>={{ python_min }}", + "python >={{ python_min }}", + run_reqs, + ), + ( + "test.requires", + r"python\s+{{ python_min }}", + "python {{ python_min }}", + test_reqs, + ), ]: if recipe_version == 1: syntax = syntax.replace( "{{ python_min }}", "${{ python_min }}" ) + report_syntax = report_syntax.replace( + "{{ python_min }}", "${{ python_min }}" + ) test_syntax = syntax else: test_syntax = syntax.replace("{{ python_min }}", "9999") @@ -263,12 +281,12 @@ def hint_noarch_python_use_python_min( if ( req.strip().split()[0] == "python" and req != "python" - and test_syntax in req + and re.search(test_syntax, req) ): break else: hint += ( - f"\n - For the `{section_name}` section of the recipe, you should usually use `{syntax}` " + f"\n - For the `{section_name}` section of the recipe, you should usually use `{report_syntax}` " f"for the `python` entry." ) diff --git a/news/2151-hint-less-spaces.rst b/news/2151-hint-less-spaces.rst new file mode 100644 index 000000000..f18eda1af --- /dev/null +++ b/news/2151-hint-less-spaces.rst @@ -0,0 +1,23 @@ +**Added:** + +* + +**Changed:** + +* Changed ``noarch-python`` hint to not require exactly one space between python and the Jinja2 expression. (#2151) + +**Deprecated:** + +* + +**Removed:** + +* + +**Fixed:** + +* + +**Security:** + +* diff --git a/tests/test_lint_recipe.py b/tests/test_lint_recipe.py index eb12e9ffd..eaeb13bd5 100644 --- a/tests/test_lint_recipe.py +++ b/tests/test_lint_recipe.py @@ -3200,6 +3200,30 @@ def test_hint_pip_no_build_backend( ), [], ), + ( + textwrap.dedent( + """ + {% set python_min = '3.7' %} + + package: + name: python + + build: + noarch: python + + requirements: + host: + - python {{ python_min }} + run: + - python >={{ python_min }} + + test: + requires: + - python {{ python_min }} + """ + ), + [], + ), ], ) def test_hint_noarch_python_use_python_min(