From 52af204534a9e11fbafebba8e138023f511d7f06 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Wed, 20 Nov 2024 13:20:17 -0800 Subject: [PATCH 1/4] allow multiple spaces in python_min syntax --- conda_smithy/linter/hints.py | 8 ++++---- tests/test_lint_recipe.py | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/conda_smithy/linter/hints.py b/conda_smithy/linter/hints.py index 21c99a1a7..f427c09aa 100644 --- a/conda_smithy/linter/hints.py +++ b/conda_smithy/linter/hints.py @@ -247,9 +247,9 @@ 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), + ("host", r"python\s+{{ python_min }}", host_reqs), + ("run", r"python\s+>={{ python_min }}", run_reqs), + ("test.requires", r"python\s+{{ python_min }}", test_reqs), ]: if recipe_version == 1: syntax = syntax.replace( @@ -263,7 +263,7 @@ 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: 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( From d00c6b657aae38bfe551e3f383448aa527bc8251 Mon Sep 17 00:00:00 2001 From: "Matthew R. Becker" Date: Thu, 21 Nov 2024 03:39:18 -0600 Subject: [PATCH 2/4] Update hints.py --- conda_smithy/linter/hints.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/conda_smithy/linter/hints.py b/conda_smithy/linter/hints.py index f427c09aa..060c55291 100644 --- a/conda_smithy/linter/hints.py +++ b/conda_smithy/linter/hints.py @@ -247,9 +247,9 @@ def hint_noarch_python_use_python_min( if noarch_value == "python" and not outputs_section: hint = "" for section_name, syntax, reqs in [ - ("host", r"python\s+{{ python_min }}", host_reqs), - ("run", r"python\s+>={{ python_min }}", run_reqs), - ("test.requires", r"python\s+{{ python_min }}", test_reqs), + ("host", r"python\s+\{\{ python_min \}\}", host_reqs), + ("run", r"python\s+>=\{\{ python_min \}\}", run_reqs), + ("test.requires", r"python\s+\{\{ python_min \}\}", test_reqs), ]: if recipe_version == 1: syntax = syntax.replace( From d1a6d606d5ebb32200ab2043496ef07f99bc5e53 Mon Sep 17 00:00:00 2001 From: beckermr Date: Thu, 21 Nov 2024 03:58:50 -0600 Subject: [PATCH 3/4] fix: report not the regex --- conda_smithy/linter/hints.py | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/conda_smithy/linter/hints.py b/conda_smithy/linter/hints.py index 060c55291..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", r"python\s+\{\{ python_min \}\}", host_reqs), - ("run", r"python\s+>=\{\{ python_min \}\}", run_reqs), - ("test.requires", r"python\s+\{\{ 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") @@ -268,7 +286,7 @@ def hint_noarch_python_use_python_min( 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." ) From 5881b09c73bdcf25aaadf6fca605040263700cdf Mon Sep 17 00:00:00 2001 From: beckermr Date: Thu, 21 Nov 2024 04:00:15 -0600 Subject: [PATCH 4/4] doc: add news --- news/2151-hint-less-spaces.rst | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 news/2151-hint-less-spaces.rst 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:** + +*