rattler-build
rattler-build copied to clipboard
variant is undefined when trying to evaluate it even though it's set in variant config
# yaml-language-server: $schema=https://raw.githubusercontent.com/prefix-dev/recipe-format/main/schema.json
context:
name: my-package
recipe:
name: ${{ name }}
version: '1.0.0'
outputs:
- package:
name: ${{ name + '-' + variant }}
variant:
- a
- b
❯ rattler-build build -r recipe/recipe.yaml -m recipe/variants.yaml
╭─ Finding outputs from recipe
│
╰─────────────────── (took 0 seconds)
Error: × Failed to parse recipe
Error: × Parsing: failed to render Jinja expression: invalid operation: tried to use + operator on unsupported types string and undefined (in <string>:1)
╭─[12:13]
11 │ - package:
12 │ name: ${{ name + '-' + variant }}
· ─────────────┬─────────────
· ╰── invalid operation: tried to use + operator on unsupported types string and undefined
╰────
There is one (semi-working) workaround:
name: ${{ name }}-${{ variant }}
But then it's still missing when printing the variant config:
╭─ Finding outputs from recipe
│ Found 2 variants
│ Build variant: my-package--1.0.0-hcdbb9e0_0
│
│ ╭─────────────────┬───────────╮
│ │ Variant ┆ Version │
│ ╞═════════════════╪═══════════╡
│ │ target_platform ┆ osx-arm64 │
│ │ variant ┆ a │
│ ╰─────────────────┴───────────╯
│ Build variant: my-package--1.0.0-h89e5c08_0
│
│ ╭─────────────────┬───────────╮
│ │ Variant ┆ Version │
│ ╞═════════════════╪═══════════╡
│ │ target_platform ┆ osx-arm64 │
│ │ variant ┆ b │
│ ╰─────────────────┴───────────╯
│
╰─────────────────── (took 0 seconds)
I think we should already load the variant and inject it here:
https://github.com/prefix-dev/rattler-build/blob/main/src/variant_config.rs#L396
Because the used_vars are discovered correctly.
I thought string concatenation in (mini)jinja used ~ not +
I think both work? But this is also the same problem as #1011 :)
Although ~ seems to convert the elements to strings, so it might deal with undefined better.
There is one (semi-working) workaround:
name: ${{ name }}-${{ variant }}
I experienced this in pin_subpackage, so unfortunately this doesn't fix it for me
@pavelzw you could try using ~.
Yes, ~ seems to work 🤔
(Although 'foo' + 'bar' also works while var + 'bar' doesn't)
Feel free to close this issue if you think we should just use ~ 😃
Yeah, I think ~ casts (even an undefined value) to a string. While + needs both values to be of matching types.
I do want to fix this issue (also to close #1011)
This was fixed a while ago.