Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix false positive when v1 recipe name is non-context variable #2248

Merged
merged 2 commits into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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