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

Allow and validate schema_version key in v1 recipes #2207

Merged
merged 4 commits into from
Jan 6, 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
8 changes: 8 additions & 0 deletions conda_smithy/lint_recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,14 @@ def lintify_meta_yaml(
recipe_name = "meta.yaml" if recipe_version == 0 else "recipe.yaml"
recipe_fname = os.path.join(recipe_dir or "", recipe_name)

if recipe_version == 1:
schema_version = meta.get("schema_version", 1)
if schema_version != 1:
lints.append(
f"Unsupported recipe.yaml schema version {schema_version}"
)
return lints, hints

sources_section = get_section(meta, "source", lints, recipe_version)
build_section = get_section(meta, "build", lints, recipe_version)
requirements_section = get_section(
Expand Down
2 changes: 2 additions & 0 deletions conda_smithy/linter/conda_recipe_v1_linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
REQUIREMENTS_ORDER = ["build", "host", "run"]

EXPECTED_SINGLE_OUTPUT_SECTION_ORDER = [
"schema_version",
"context",
"package",
"source",
Expand All @@ -26,6 +27,7 @@
]

EXPECTED_MULTIPLE_OUTPUT_SECTION_ORDER = [
"schema_version",
"context",
"recipe",
"source",
Expand Down
23 changes: 23 additions & 0 deletions news/schema_version.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
**Added:**

* Added validation for ``schema_version`` key. (#2207)

**Changed:**

* <news item>

**Deprecated:**

* <news item>

**Removed:**

* <news item>

**Fixed:**

* ``schema_version`` key no longer causes linting failures. (#2207)

**Security:**

* <news item>
2 changes: 2 additions & 0 deletions tests/recipes/v1_recipes/torchvision.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
schema_version: 1

context:
version: 0.20.1
build_number: 2
Expand Down
17 changes: 17 additions & 0 deletions tests/test_lint_recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -3865,5 +3865,22 @@ def test_lint_recipe_parses_v1_duplicate_keys():
), hints


def test_lint_recipe_v1_invalid_schema_version():
with tempfile.TemporaryDirectory() as tmpdir:
with open(os.path.join(tmpdir, "recipe.yaml"), "w") as f:
f.write(
textwrap.dedent(
"""
schema_version: 2

package:
name: blah
"""
)
)
lints, hints = linter.main(tmpdir, return_hints=True, conda_forge=True)
assert lints == ["Unsupported recipe.yaml schema version 2"]


if __name__ == "__main__":
unittest.main()
Loading