diff --git a/conda_smithy/lint_recipe.py b/conda_smithy/lint_recipe.py index a443d6b4d..fe3a2be08 100644 --- a/conda_smithy/lint_recipe.py +++ b/conda_smithy/lint_recipe.py @@ -602,6 +602,7 @@ def run_conda_forge_specific( test_reqs, outputs_section, noarch_value, + recipe_version, hints, ) diff --git a/conda_smithy/linter/hints.py b/conda_smithy/linter/hints.py index 86e53475b..90d9ecf5a 100644 --- a/conda_smithy/linter/hints.py +++ b/conda_smithy/linter/hints.py @@ -235,7 +235,13 @@ def hint_pip_no_build_backend(host_or_build_section, package_name, hints): def hint_noarch_python_use_python_min( - host_reqs, run_reqs, test_reqs, outputs_section, noarch_value, hints + host_reqs, + run_reqs, + test_reqs, + outputs_section, + noarch_value, + recipe_version, + hints, ): if noarch_value == "python" and not outputs_section: for section_name, syntax, reqs in [ @@ -243,6 +249,11 @@ def hint_noarch_python_use_python_min( ("run", "python >={{ python_min }}", run_reqs), ("test.requires", "python ={{ python_min }}", test_reqs), ]: + if recipe_version == 1: + syntax = syntax.replace( + "{{ python_min }}", "${{ python_min }}" + ) + for req in reqs: if ( req.strip().split()[0] == "python" diff --git a/news/2119-fix-lint-noarch-python-v1.rst b/news/2119-fix-lint-noarch-python-v1.rst new file mode 100644 index 000000000..1b0ce1dd9 --- /dev/null +++ b/news/2119-fix-lint-noarch-python-v1.rst @@ -0,0 +1,23 @@ +**Added:** + +* + +**Changed:** + +* + +**Deprecated:** + +* + +**Removed:** + +* + +**Fixed:** + +* Fixed ``noarch: python`` hint for v1 recipes. (#2119) + +**Security:** + +* diff --git a/tests/test_lint_recipe.py b/tests/test_lint_recipe.py index 07ca3772a..2e74d1e6c 100644 --- a/tests/test_lint_recipe.py +++ b/tests/test_lint_recipe.py @@ -3190,5 +3190,93 @@ def test_hint_noarch_python_use_python_min( ) +@pytest.mark.parametrize( + "meta_str,expected_hints", + [ + ( + textwrap.dedent( + """ + package: + name: python + + requirements: + run: + - python + """ + ), + [], + ), + ( + textwrap.dedent( + """ + package: + name: python + + build: + noarch: python + + requirements: + run: + - python + """ + ), + [ + "python ${{ python_min }}.*", + "python >=${{ python_min }}", + "python =${{ python_min }}", + ], + ), + ( + textwrap.dedent( + """ + package: + name: python + + build: + noarch: python + + requirements: + host: + - python ${{ python_min }}.* + run: + - python >=${{ python_min }} + + tests: + - requirements: + run: + - python =${{ python_min }} + """ + ), + [], + ), + ], +) +def test_hint_noarch_python_use_python_min_v1( + meta_str, + expected_hints, +): + meta = get_yaml().load(meta_str) + lints = [] + hints = [] + linter.run_conda_forge_specific( + meta, + None, + lints, + hints, + recipe_version=1, + ) + + # make sure we have the expected hints + if expected_hints: + for expected_hint in expected_hints: + assert any(expected_hint in hint for hint in hints), hints + else: + assert all( + "noarch: python recipes should almost always follow the syntax in" + not in hint + for hint in hints + ) + + if __name__ == "__main__": unittest.main()