rattler-build icon indicating copy to clipboard operation
rattler-build copied to clipboard

variant is undefined when trying to evaluate it even though it's set in variant config

Open pavelzw opened this issue 1 year ago • 9 comments

# 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
    ╰────

pavelzw avatar Jul 25 '24 08:07 pavelzw

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)

wolfv avatar Aug 01 '24 12:08 wolfv

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.

wolfv avatar Aug 01 '24 13:08 wolfv

I thought string concatenation in (mini)jinja used ~ not +

jaimergp avatar Aug 07 '24 07:08 jaimergp

I think both work? But this is also the same problem as #1011 :)

wolfv avatar Aug 07 '24 07:08 wolfv

Although ~ seems to convert the elements to strings, so it might deal with undefined better.

wolfv avatar Aug 07 '24 07:08 wolfv

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 avatar Aug 07 '24 08:08 pavelzw

@pavelzw you could try using ~.

wolfv avatar Aug 07 '24 11:08 wolfv

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 ~ 😃

pavelzw avatar Aug 07 '24 12:08 pavelzw

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)

wolfv avatar Aug 07 '24 12:08 wolfv

This was fixed a while ago.

wolfv avatar May 02 '25 16:05 wolfv