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

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

Closed
ytausch opened this issue Mar 18, 2024 · 4 comments · Fixed by #1877
Closed

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

ytausch opened this issue Mar 18, 2024 · 4 comments · Fixed by #1877
Labels

Comments

@ytausch
Copy link
Contributor

ytausch commented Mar 18, 2024

(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).

noarch_platforms: Optional[List[Platforms]] = Field(
default_factory=lambda: ["linux_64"],
description=cleandoc(
"""
Platforms on which to build noarch packages. The preferred default is a
single build on `linux_64`.
```yaml
noarch_platforms: linux_64
```

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

@ytausch ytausch changed the title conda-forge.yml Pydantic Model: Single Values instead of conda-forge.yml Pydantic Model: Single Values instead of Lists Mar 18, 2024
@beckermr
Copy link
Member

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
Copy link
Contributor Author

ytausch commented Mar 18, 2024

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

config["noarch_platforms"] = conda_build.utils.ensure_list(
config["noarch_platforms"]
)

It's also valid for remote_ci_setup:

remote_ci_setup_ = conda_build.utils.ensure_list(remote_ci_setup)

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

@beckermr
Copy link
Member

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

@jaimergp
Copy link
Member

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]].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants