Skip to content

Commit

Permalink
Merge pull request #2248 from mgorny/recipe-name-var-false-positive
Browse files Browse the repository at this point in the history
  • Loading branch information
beckermr authored Feb 25, 2025
2 parents b447e74 + e74b135 commit fcd784c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
5 changes: 5 additions & 0 deletions conda_smithy/linter/conda_recipe_v1_linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
23 changes: 23 additions & 0 deletions news/2248-v1-recipe-name-var.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
**Added:**

* <news item>

**Changed:**

* <news item>

**Deprecated:**

* <news item>

**Removed:**

* <news item>

**Fixed:**

* Fixed a false positive when a v1 recipe name refers to a variable from ``conda_build_config.yaml`` (#2248).

**Security:**

* <news item>
14 changes: 6 additions & 8 deletions tests/test_lint_recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fcd784c

Please sign in to comment.