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

[ci] validate pyproject file by json schema #6813

Merged
merged 9 commits into from
Feb 9, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,8 @@ repos:
- id: typos
args: ["--force-exclude"]
exclude: (\.gitignore$)|(^\.editorconfig$)
- repo: https://github.com/henryiii/validate-pyproject-schema-store
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've read the docs of both projects, and want to be sure I understand... is the main benefit of validate-pyproject-schema-store over validate-pyproject that it explicitly is tied to version of the pyproject.toml schema?

That's the impression I got from https://github.com/henryiii/validate-pyproject-schema-store/tree/main?tab=readme-ov-file#direct-usage

This also has the benefit that the version will be pinned and updated by pre-commit automatically.

Or is it that by vendoring the schema file, you avoid a network call out to the internet every time pre-commit runs?

Given that we always build with the latest pip, build, and scikit-build-core here, and that CI runs with total access to the internet and very rare network interruptions, I think we want to always keep up with the latest pyproject.toml schema. And so think it would be better to use validate-pyproject and ensure every CI run gets the latest pyproject.toml schema.

What do you think? Did I misunderstand?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initially I thought that it's good idea to pin the schema version and have a tight control over its updates. But I don't mind having the latest version always. Especially given that our dependabot doesn't update pre-commit hooks. I'll switch to validate-pyproject.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I just checked with [tool.ruff.lint.select] = [..., "non-existing"] deep intentional error. And validate-pyproject validated successfully that file while validate-pyproject-schema-store failed with the following error:

Validate pyproject.toml..................................................Failed
- hook id: validate-pyproject
- exit code: 1
Error:  `tool.ruff.lint` cannot be validated by any definition:

Given this difference in behavior of these two tools, do you still want to replace validate-pyproject-schema-store with validate-pyproject?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh interesting. I still don't really understand the difference between these tools but... seeing the things validate-pyproject-schema-store is catching, I'm ok with trying it. Thanks for considering and testing validate-pyproject.

Let's merge this as-is.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBH, me too. I thought that validate-pyproject-schema-store is just a something like a caching wrapper for schemas, but seems that differences are bigger than I thought. OK, at least I can see all partial schemas here in the repo: https://github.com/henryiii/validate-pyproject-schema-store/tree/main/src/validate_pyproject_schema_store/resources and it makes me feel that all sections of the file are really validated.

Copy link
Collaborator Author

@StrikerRUS StrikerRUS Feb 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, seems that behavior is documented:

According to PEP 518, tools can define their own configuration inside pyproject.toml by using custom subtables under tool.
In validate-pyproject, schemas for these subtables can be specified via Plugins. The following subtables are defined by built-in plugins (i.e. plugins that are included in the default distribution of validate-pyproject):
https://validate-pyproject.readthedocs.io/en/latest/schemas.html#tool-table

And I can see only tool.setuptools table right after that passage.

UPD: More strong evidence:

Since different tools allow different configurations, it would be impractical to try to create schemas for all of them inside the same project. Instead, validate-pyproject allows Plugins to provide extra JSON Schemas, against which tool subtables can be checked.
https://validate-pyproject.readthedocs.io/en/latest/dev-guide.html#how-it-works

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok, that explains it! Then yes, this makes me even more confident in using validate-pyproject-schema-store.

rev: 2025.02.03
hooks:
- id: validate-pyproject
files: python-package/pyproject.toml$
Loading