prefix-dev / rattler-build

rattler-build is a universal package builder for Windows, macOS and Linux
https://prefix-dev.github.io/rattler-build
BSD 3-Clause "New" or "Revised" License
185 stars 38 forks source link

Either allow context vars to be lists or throw better errors #971

Open vyasr opened 1 month ago

vyasr commented 1 month ago

Currently variables in the context section of the recipe cannot be lists. If a Jinja filter produces a list (e.g. the string split filter) and that value is stored to a variable, it ends up being stringified. This leads to surprising errors downstream, such as if you attempt to index into the result or collapse it back into a scalar object (e.g. via the join filter on a split string) and it is treated as a string. Ideally the context would support list variables, but it should at least provide better error messages for debugging by not silently converting the list to a string but instead failing to assign it. The current behavior can lead to very unexpected errors. For instance, continuing the example from above, if we do something like this

context:
    x: "one.two.three"
    y: ${{ x | split(".") }}
    z: ${{ y | join(".") }}

The value of z will not be one.two.three but instead [.".o.n.e.".,. .".t.w.o.".,. .".t.h.r.e.e.".] since y is the string ["one", "two", "three"], not a list of three elements.