conda-forge / conda-smithy

The tool for managing conda-forge feedstocks.
https://conda-forge.org/
BSD 3-Clause "New" or "Revised" License
147 stars 177 forks source link

`conda-forge.yml` Pydantic Model: Single Values instead of Lists #1869

Closed ytausch closed 5 months ago

ytausch commented 5 months ago

(Moved from #1865)

The conda-forge.yml schema contains fields like nooarch_platforms, remote_ci_setup that expect a list but some feedstocks just supply a single value, which is not supported by the model currently. Even our own documentation currently specifies a value that is not supported by the model (see below - Optional[List] does not support this).

https://github.com/conda-forge/conda-smithy/blob/85ddb5deabda9ab58ae6ec898e2a1e33393117b7/conda_smithy/schema.py#L710-L719

How to deal with this? One option would be to add a custom type that has a BeforeValidator converting single values to a list with only one item. I did a similar thing for the Pydantic models for cf-scripts:

https://github.com/ytausch/cf-scripts/blob/ea9cec3a988141e54d625169de60215bf3d8ff41/conda_forge_tick/models/common.py#L47-L58

The alternative would be to strictly support lists only and change the documentation and affected feedstocks.

@jaimergp

beckermr commented 5 months ago

What is in the model doesn't actually matter. You need to check the smithy source code to see if single values are allowed. If they are, then the model is wrong. The source code came first and is the source of truth on what is allowed for each field.

ytausch commented 5 months ago

conda-smithy supports single values for noarch_platforms. See the following snippet:

https://github.com/conda-forge/conda-smithy/blob/44acb937c50ce98adf1b50b01a6ab7bc577d2fb2/conda_smithy/configure_feedstock.py#L2107-L2109

It's also valid for remote_ci_setup: https://github.com/conda-forge/conda-smithy/blob/44acb937c50ce98adf1b50b01a6ab7bc577d2fb2/conda_smithy/configure_feedstock.py#L586

So this is actually an error in the model, which can be fixed like I proposed above.

beckermr commented 5 months ago

Great and thanks for tracking that down! Let's fix the model!

jaimergp commented 5 months ago

We can't use pydantic prevalidators because that's not used at runtime (we use jsonschema for the validation instead). What we can do is to turn the list[something] types into union[something, list[something]].