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

Avoid undefined jinja errors for skipped recipes #5458

Merged
merged 7 commits into from
Sep 4, 2024
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
4 changes: 4 additions & 0 deletions conda_build/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -1338,6 +1338,10 @@ def parse_until_resolved(
)
self.final = final

if self.skip():
self.final = True
return

# recursively parse again so long as each iteration has fewer undefined jinja variables
undefined_jinja_vars = ()
while set(undefined_jinja_vars) != set(self.undefined_jinja_vars):
Expand Down
19 changes: 19 additions & 0 deletions news/5458-avoid-undefined-jinja-in-skipped
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
### Enhancements

* <news item>

### Bug fixes

* Allow undefined jinja variables when a particular metadata block evaluates as skipped. (#5458)

### Deprecations

* <news item>

### Docs

* <news item>

### Other

* <news item>
24 changes: 24 additions & 0 deletions tests/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -623,3 +623,27 @@ def test_parse_until_resolved(testing_metadata: MetaData, tmp_path: Path) -> Non
match=("Failed to render jinja template"),
):
testing_metadata.parse_until_resolved()


def test_parse_until_resolved_skip_avoids_undefined_jinja(
testing_metadata: MetaData, tmp_path: Path
) -> None:
(recipe := tmp_path / (name := "meta.yaml")).write_text(
"""
package:
name: dummy
version: {{version}}
build:
skip: True
"""
)
testing_metadata._meta_path = recipe
testing_metadata._meta_name = name

# because skip is True, we should not error out here - so no exception should be raised
try:
testing_metadata.parse_until_resolved()
except CondaBuildUserError:
pytest.fail(
"Undefined variable caused error, even though this build is skipped"
)
Loading