From 01e46acec7b7a1e9e7a166c191a341ac0cdec0a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Date: Tue, 25 Feb 2025 17:09:49 +0100 Subject: [PATCH 1/2] Fix false positive when v1 recipe name is non-context variable Skip checking v1 recipe name if it contains unresolved variables, in order to fix false positives when a variable from `conda_build_config.yaml` is used. Iterating over all possible variants and verifying the resulting package names is unlikely to be worth the extra complexity. This also roughly matches the linter behavior for v0 recipes, where `{{ var_name }}` is converted into `var_name`, and therefore is never properly linted anyway. Fixes #2224 --- conda_smithy/linter/conda_recipe_v1_linter.py | 5 +++++ tests/test_lint_recipe.py | 14 ++++++-------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/conda_smithy/linter/conda_recipe_v1_linter.py b/conda_smithy/linter/conda_recipe_v1_linter.py index 53be7cc1c..c07c760d4 100644 --- a/conda_smithy/linter/conda_recipe_v1_linter.py +++ b/conda_smithy/linter/conda_recipe_v1_linter.py @@ -134,6 +134,11 @@ def lint_recipe_name( lints: list[str], ) -> None: name = get_recipe_name(recipe_content) + # Avoid false positives if the recipe is using variables + # from conda_build_config.yaml. + # https://github.com/conda-forge/conda-smithy/issues/2224 + if "${{" in name: + return lint_msg = _lint_recipe_name(name) if lint_msg: diff --git a/tests/test_lint_recipe.py b/tests/test_lint_recipe.py index ef8264e8a..2a95b3ba6 100644 --- a/tests/test_lint_recipe.py +++ b/tests/test_lint_recipe.py @@ -1793,22 +1793,20 @@ def test_recipe_v1_recipe_name(self): lints, _ = linter.lintify_meta_yaml( meta_with_context, recipe_version=1 ) - expected_message = ( - "Recipe name has invalid characters. only lowercase alpha, " - "numeric, underscores, hyphens and dots allowed" - ) self.assertIn(expected_message, lints) meta_with_context = {"recipe": {"name": "mp++"}, "outputs": []} # noqa lints, _ = linter.lintify_meta_yaml( meta_with_context, recipe_version=1 ) - expected_message = ( - "Recipe name has invalid characters. only lowercase alpha, " - "numeric, underscores, hyphens and dots allowed" - ) self.assertIn(expected_message, lints) + # variable may be defined e.g. in conda_build_config.yaml + # https://github.com/conda-forge/conda-smithy/issues/2224 + meta = {"package": {"name": "${{ variant_name }}"}} + lints, _ = linter.lintify_meta_yaml(meta, recipe_version=1) + self.assertNotIn(expected_message, lints) + def test_end_empty_line(self): bad_contents = [ # No empty lines at the end of the file From e74b135be953cfe97d45ebc039a4baec23d281d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Date: Tue, 25 Feb 2025 17:15:35 +0100 Subject: [PATCH 2/2] Add a news entry --- news/2248-v1-recipe-name-var.rst | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 news/2248-v1-recipe-name-var.rst diff --git a/news/2248-v1-recipe-name-var.rst b/news/2248-v1-recipe-name-var.rst new file mode 100644 index 000000000..222647d5e --- /dev/null +++ b/news/2248-v1-recipe-name-var.rst @@ -0,0 +1,23 @@ +**Added:** + +* + +**Changed:** + +* + +**Deprecated:** + +* + +**Removed:** + +* + +**Fixed:** + +* Fixed a false positive when a v1 recipe name refers to a variable from ``conda_build_config.yaml`` (#2248). + +**Security:** + +*