-
-
Notifications
You must be signed in to change notification settings - Fork 184
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
Hint about extra fields in conda-forge.yml #1920
base: main
Are you sure you want to change the base?
Conversation
conda_smithy/lint_recipe.py
Outdated
@@ -1,6 +1,11 @@ | |||
# -*- coding: utf-8 -*- | |||
|
|||
from collections.abc import Sequence, Mapping | |||
from typing import List | |||
|
|||
from pydantic import BaseModel |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@isuruf Let's continue the discussion about adding pydantic here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By the way: pydantic
is already listed as a project dependency in environment.yml
Edit: This comment does not contribute to the discussion, my mistake.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For clarity pydantic
is a development-only dependency. So that only affects development, not installation. We generate a JSON schema for runtime use. For context, it was added in PR: #1756
Is it possible to use jsonschema
for this case too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand that pydantic is not currently a part of https://github.com/conda-forge/conda-smithy-feedstock/blob/main/recipe/meta.yaml dependencies.
I am not aware of a good way of doing this with jsonschema
.
Also, I want to repeat my argument:
I would like and strongly propose to keep pydantic here. Pydantic provides an elegant way to find additional fields that are not part of the schema (see my implementation) - and also, I think the pydantic model should be used in more parts of the smithy code anyway since it provides a type-safe way to access fields.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is adding pydantic
as a new dependency so bad?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is adding pydantic as a new dependency so bad?
Please see my comment on the other thread.
I am not aware of a good way of doing this with jsonschema.
This is easy. Load the json schema and see if "additionalProperties": false
is there for the attribute.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see my comment on the other thread.
@isuruf I just scrolled through every comment you left at my conda-smithy PRs but could not find an answer to my question. You said:
This adds a new dependency pydantic on users. Previously it was only a dev dependency. Is it possible to remove this?
and
I strongly disagree. This PR use pydantic to check for which fields to hint about. If we can't do that using the json schema we are essentially making a distinction between pydantic model and json schema.
I do not see how this explains why we want to avoid pydantic
as a dependency. To your latter comment, I replied:
What do you mean with "distinction"? The pydantic model should be equivalent to the JSON schema anyway - if it's not, we have a bug.
This is easy. Load the json schema and see if "additionalProperties": false is there for the attribute.
This requires us to have a separate JSON schema that actually has additionalProperties
set to false for the fields we want to warn about since we have agreed to allow additional properties in the main schema. Is this what you propose?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@isuruf I would really really like to solve this debate as I want this PR to get merged.
Note: The signature of We had a discussion about deprecation in #1906 |
What is the status of this PR? @conda-forge/core @isuruf |
036d3df
to
155b56e
Compare
@isuruf There are still some open discussions about pydantic |
don't warn for AzureRunnerSettings and CondaBuildConfig
155b56e
to
8a429ed
Compare
@isuruf You did not reply here since almost 2 months although I pinged you multiple times. Is there anything I need to do? Fine of course if you're currently busy, I'll wait here. |
aca42c0
to
1a129f6
Compare
1a129f6
to
bfc6a4b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue here is requiring pydantic at run time IIRC. We need to resolve this sticking point before we can merge.
What exactly is the reason that we don't want to have pydantic as a runtime dependency? |
I thought I made my reasons clear in #1900. Let me know if you need more clarification. |
Looking at that PR, the only relevant-looking thread I see is
So the sticking point is not having a runtime dependence on |
No, the main point is that I want the json schema to be complete.
|
How do you imagine we encode the fact that additional fields are forbidden in the json schema? AFAICT json has no way to specify that, so whatever we do, we'd have to introduce a marker-field that says "this JSON schema cannot be extended". Which is what this PR is doing with To me saying "json schema needs to be complete" thus becomes equivalent to "we shouldn't lint on unknown fields", which I strongly disagree with. |
|
So the issue is just the choice of default? I.e. whether we need to add It'd be completely fine for me to opt into |
Yes, but with a |
I don't care personally. I was trying to make sure more discussion was had since others had objected. |
I appreciate this PR is going forward!
The problem with combining these 3 requirements is that we cannot partially validate a JSON schema with However, if we don't want to emit a Doing it like this also preserves the following invariant: "All If I understand correctly, the reason why you are not happy with the current solution is that you want to forbid extra fields in the JSON schema - which I also understand because, for example, IDE support. Because of the two reasons I mentioned above (we need
The strict Pydantic model (which is dynamically accessible via the added method) exactly reflects what is present in the JSON schema. And the non-strict (original) Pydantic model poses the minimum schema every feedstock satisfies. What do you think? |
That sounds good. It wouldn't require a run time dependence on pydantic right? |
I don't understand that problem yet. How does |
If absolutely necessary, we could avoid the runtime dependency by generating a strict and a non-strict JSON schema. The non-strict schema would allow extra fields while the strict schema wouldn't. If the non-strict schema passes and the strict schema fails, we know the issue lies in the extra fields. However, we probably couldn't format the lint messages as nicely as we currently can. And there will be compromises if a file violates the non-strict JSON schema, and on top of that, has extra fields since we cannot really detect that with a JSON-schema-only approach. This is why I propose keeping pydantic as a runtime dependency to have a more elegant way of extracting extra fields.
Hopefully, this clarified a bit? :) |
Thank you for the elaboration, though it's the second time where you build a longer argument and I already stumble on one of the first assumptions/statements.
How does it become useless? The fact that it cannot seems irrelevant to me because it shouldn't ignore additionalProperties / extra fields (and we turn them into lints or hints). |
Good that we are discussing this here then!
Counter-question: How do you want to differentiate between schema violations that turn into a lint vs. violations that turn into a hint? |
Counter-counter-question: Is the extra complexity that's necessary to make that distinction actually worth it, or should we just lint on any violation, including otherwise benign extra fields? I haven't been involved in this discussion as long as you and Isuru, but so far my impression is that a simpler approach would be clearly preferable, and so what if wrong fields get lints instead if hints? 🤷♂️ |
I'm totally in for classifying extra fields as lints instead of hints. This is also what I initially proposed a few months ago in #1865 :D |
I understand the sentiment, but given all the overengineered complexity that flows from it, this requirement must be put in question. New platforms get added extremely rarely, while we can do smithy releases as often as we want, so it's really not an unreasonable ask to make a smithy update for rolling out a new platform. |
I absolutely agree. |
Even more than that: all the platform-related values get populated with >>> from conda.base.constants import KNOWN_SUBDIRS
>>> [subdir.replace("-", "_") for subdir in KNOWN_SUBDIRS if "-" in subdir]
['emscripten_wasm32', 'wasi_wasm32', 'freebsd_64', 'linux_32', 'linux_64', 'linux_aarch64', 'linux_armv6l', 'linux_armv7l', 'linux_ppc64', 'linux_ppc64le', 'linux_riscv64', 'linux_s390x', 'osx_64', 'osx_arm64', 'win_32', 'win_64', 'win_arm64', 'zos_z'] so all conda-build-supported platforms are already part of the schema information, and won't need further changes to smithy even if we start rolling out a new platform in conda-forge. |
Checklist
news
entryThis PR contains the functional changes of #1900, to be merged separately. See also parts of the discussion there.
TLDR:
recipe-lint
now hints about additional fields as compared with the Pydantic schema.