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

Warn if parsed and raw outputs mismatch #5601

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
12 changes: 11 additions & 1 deletion conda_build/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -2228,6 +2228,15 @@ def extract_single_output_text(
if not outputs:
outputs = [{"name": self.name()}]

if len(output_matches) != len(outputs):
# See https://github.com/conda/conda-build/issues/5571
utils.get_logger(__name__).warning(
"Number of parsed outputs does not match detected raw metadata blocks. "
"Identified output block may be wrong! "
"If you are using Jinja conditionals to include or exclude outputs, "
"consider using `skip: true # [condition]` instead."
)

try:
if output_type:
output_tuples = [
Expand All @@ -2250,7 +2259,8 @@ def extract_single_output_text(
except ValueError:
if not self.path and self.meta.get("extra", {}).get("parent_recipe"):
utils.get_logger(__name__).warning(
f"Didn't match any output in raw metadata. Target value was: {output_name}"
"Didn't match any output in raw metadata. Target value was: %s",
output_name,
)
output = ""
else:
Expand Down
19 changes: 19 additions & 0 deletions news/5601-warn-mismatches
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
### Enhancements

* <news item>

### Bug fixes

* Warn about parsed and raw output block mismatches. This can cause issues with custom build strings, among others. The recommendation is to avoid Jinja flow control to build the output list. Use `skip: true` as necessary. (#5571 via #5601)

### Deprecations

* <news item>

### Docs

* <news item>

### Other

* <news item>
60 changes: 60 additions & 0 deletions tests/test-recipes/metadata/_jinja_outputs/meta.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package:
name: test_jinja_outputs
version: 1.0

outputs:
- name: output1
build:
script: echo "weeee"
noarch: generic
requirements:
build:
- zlib
host:
- jpeg
run:
- bzip2

test:
requires:
- xz
commands:
- echo "steve"

{% if false %}
- name: output2
build:
script: echo "weeee"
noarch: generic
requirements:
build:
- zlib
host:
- jpeg
run:
- bzip2

test:
requires:
- xz
commands:
- echo "steve"
{% endif %}

- name: output3
build:
script: echo "weeee"
noarch: generic
requirements:
build:
- zlib
host:
- jpeg
run:
- bzip2

test:
requires:
- xz
commands:
- echo "steve"
16 changes: 16 additions & 0 deletions tests/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -708,3 +708,19 @@ def test_parse_until_resolved_missing_jinja_in_spec(
)
else:
print("did not parse OK!")


def test_extract_single_output_text_with_jinja_is_broken():
"""
Given a recipe with three outputs 1, 2, and 3, where 2 is guarded by a falsy Jinja-if,
MetaData.extract_single_output_text() returns 2 when asked for 3.

This is a bug that should be fixed.
"""
metadata = MetaData(os.path.join(metadata_dir, "_jinja_outputs"))
output = metadata.extract_single_output_text(
"output3", getattr(metadata, "type", None)
)
# We of course want to obtain output3, but the buggy behaviour gave us output2.
assert "output3" not in output
assert "output2" in output
Loading