Conversation
|
Seems fast enough.. against my local conda-forge feedstocks: time pixi r conda-recipe-v2-schema --work-dir=build/.cache/crs $(ls ../feedstocks/*/recipe/recipe.yaml)
# ... a lot of "is not valid under any of"
!!! 8 findings in 293 recipes
real 0m3.029s
user 0m2.896s
sys 0m0.095s |
Hofer-Julian
left a comment
There was a problem hiding this comment.
Nice idea. I had a few comments
conda_recipe_v2_schema/cli.py
Outdated
| if SCHEMA.exists(): | ||
| schema = yaml.safe_load(SCHEMA.read_text(encoding="utf-8")) | ||
| else: | ||
| schema = Recipe.json_schema() | ||
| if not schema: | ||
| msg = "could not retrieve the schema" | ||
| raise RuntimeError(msg) |
There was a problem hiding this comment.
I don't get this logic. Why would I not always use the class from the pydantic model?
There was a problem hiding this comment.
not always use the class
Because the pydantic model is an intermediate that isn't published anywhere, while the JSON schema is already in use by many tools, if only via rawgithubusercontent or whtatever URLs.
There was a problem hiding this comment.
Then I don't understand what you would like us to do with this script :)
I assumed the point of it is that you check out this repo and run it as a Pixi task
conda_recipe_v2_schema/cli.py
Outdated
| try: | ||
| model_cls = ComplexRecipe if "outputs" in recipe else SimpleRecipe | ||
| model_cls(**recipe) | ||
| except Exception as err: |
There was a problem hiding this comment.
Why not only catch Pydantic exceptions here?
There was a problem hiding this comment.
Welp, I don't care to know much about the pydantic exception API and what it might throw today, or change on a patch release tomorrow. In this context of a tiny dev tool that exists to help write schema, I'd rather not have to try/catch anything, and get back a list of errors (a la Validator.iter_errors), and do the "normal thing" of exploding on uncaught exceptions.
There was a problem hiding this comment.
in general, i'm wondering whether a tool that just does this for all yaml/json files would be more helpful. you could check at https://www.schemastore.org/ whether the filename recipe.yaml has a json schema and compare it against that. this would be more general than the conda-forge use case and i can imagine me using it in more places than only recipe.yaml
There was a problem hiding this comment.
best check before building, maybe such a tool already exists somewhere
There was a problem hiding this comment.
Yeah, I agree. If this is a general JSON schema validator, then this repo is probably not the right place for it
There was a problem hiding this comment.
yeah, sure schema everywhere, hooray!
again, as mentioned, the intent here is to make it easier for contributors to this repo to describe reproducible schema issues and their fixes.
schemastore
while useful, schemastore is... kinda bad on many levels (privacy, accuracy).
general
yeah, there are a lot of related tools (see also #29)... but YAML is weird enough across implementations (see: executable !!tags, lack of correct anchor support, etc.) that the finer points of being valid data sometimes is missed. Anyhow, all those tools don't know about pydantic (for good reasons) much less this repo's pydantic.
the conda-forge use case
i'll wager there are more github.com/conda-forge/.../recipe.yaml than anywhere else public, so doesn't seem like much of a stretch.
Thanks for maintaining this!
This adds a CLI
conda-recipe-v2-schemawith two subcommands, and its dependencies under a[cli]extra, and some tests.generatethe schema JSON (but without thePYTHONPATH-like side-effects of-m)validate(conda-forge) recipes while working on the schemaIt uses the JSON schema and pydantic to try to get the most helpful results: not that the pydantic errors are all that much better, but the schema by itself doesn't help sometimes, and could point to some better schema conventions (e.g.
if/theninstead ofoneOfcan be good for more understandable errors).My test case (as a prelude to another PR for
#/tests/*/python/python_version/if):Details