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

Hint about extra fields in conda-forge.yml #1920

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

ytausch
Copy link
Contributor

@ytausch ytausch commented May 3, 2024

Checklist

  • Added a news entry

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

@@ -1,6 +1,11 @@
# -*- coding: utf-8 -*-

from collections.abc import Sequence, Mapping
from typing import List

from pydantic import BaseModel
Copy link
Contributor Author

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.

Copy link
Contributor Author

@ytausch ytausch May 3, 2024

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.

Copy link
Member

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?

Copy link
Contributor Author

@ytausch ytausch May 5, 2024

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.

Copy link
Contributor Author

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?

Copy link
Member

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.

Copy link
Contributor Author

@ytausch ytausch May 13, 2024

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?

Copy link
Contributor Author

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.

@ytausch
Copy link
Contributor Author

ytausch commented May 5, 2024

Note: The signature of lintify_forge_yaml changed but makes a lot more sense now since not all lints or hints must be JSON validation-related. Formally, this would require a deprecation process but I want to raise the question of who actually uses this method.

We had a discussion about deprecation in #1906

@ytausch
Copy link
Contributor Author

ytausch commented May 10, 2024

What is the status of this PR? @conda-forge/core @isuruf

@ytausch
Copy link
Contributor Author

ytausch commented May 27, 2024

@isuruf

@ytausch
Copy link
Contributor Author

ytausch commented Jun 7, 2024

@isuruf There are still some open discussions about pydantic

@ytausch ytausch requested a review from isuruf June 7, 2024 12:43
@ytausch
Copy link
Contributor Author

ytausch commented Jul 10, 2024

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

@ytausch ytausch mentioned this pull request Jul 26, 2024
@h-vetinari
Copy link
Member

Sorry for the very long delay here @ytausch! I stumbled over this due to #2152 and would be very interested to help you unblock this work, as it's necessary for a lint I'd like to add (#2155).

CC @beckermr

Copy link
Member

@beckermr beckermr left a 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.

@ytausch
Copy link
Contributor Author

ytausch commented Nov 21, 2024

What exactly is the reason that we don't want to have pydantic as a runtime dependency?

@isuruf
Copy link
Member

isuruf commented Nov 21, 2024

I thought I made my reasons clear in #1900. Let me know if you need more clarification.

@h-vetinari
Copy link
Member

@isuruf: 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

@isuruf: This adds a new dependency pydantic on users. Previously it was only a dev dependency. Is it possible to remove this?

@ytausch: 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.

@isuruf: 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.

@ytausch: 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. I am not aware of a good way of doing this with JSON schema.

@ytausch: @isuruf Let's continue this in #1920.

So the sticking point is not having a runtime dependence on pydantic? Why is that an issue? I don't care much, but I've found that #2155 without this PR doesn't actually work. I definitely think fixing linting on wrong distro-values is more important than whether we depend on pydantic, but I'd also be happy if there's a fix for #2152/#2155 that works without the runtime dependence.

@isuruf
Copy link
Member

isuruf commented Nov 21, 2024

So the sticking point is not having a runtime dependence on pydantic?

No, the main point is that I want the json schema to be complete.

If we can't do that using the json schema we are essentially making a distinction between pydantic model and json schema.

@h-vetinari
Copy link
Member

h-vetinari commented Nov 21, 2024

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 "additionalProperties" AFAIU (naming can be bikeshod of course, e.g. __no_extend / __closed, etc.).

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.

@isuruf
Copy link
Member

isuruf commented Nov 21, 2024

How do you imagine we encode the fact that additional fields are forbidden in the json schema?

additionalProperties: false

@h-vetinari
Copy link
Member

So the issue is just the choice of default? I.e. whether we need to add "additionalProperties": false to non-extensible schemas, or whether - as this PR seems to be doing - set "additionalProperties": true (?!) and build on that?

It'd be completely fine for me to opt into extra="forbid" with "additionalProperties": false; that would be a natural equivalence IMO. Is this what you had in mind?

@isuruf
Copy link
Member

isuruf commented Nov 21, 2024

It'd be completely fine for me to opt into extra="forbid" with "additionalProperties": false; that would be a natural equivalence IMO. Is this what you had in mind?

Yes, but with a hint in the linter instead of a lint.

@h-vetinari
Copy link
Member

@ytausch, now that we've elucidated Isuru's objection, do you think you'd be able to implement this request?

Also, @beckermr, in case you're still opposed to the runtime dependence on pydantic, could you explain the problem with that please?

@beckermr
Copy link
Member

I don't care personally. I was trying to make sure more discussion was had since others had objected.

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

Successfully merging this pull request may close these issues.

5 participants