taplo
taplo copied to clipboard
Version Key Is Required in `pyproject.toml`
It seems that the taplo cli will fail to validate schemas for pyproject.toml when the version is not specified despite the version not being required by the jsonschema specification.
You can reproduce with a pyproject.toml file like below:
[project]
name = "deployment_handler"
requires-python = ">=3.9"
This works.
[project]
name = "deployment_handler"
version = "1.0.0"
requires-python = ">=3.9"
It seems that taplo may be associating the pyproject file to another schema when version is not specified.
Running
RUST_LOG=taplo=debug taplo check pyproject.toml --default-schema-catalog
confirmed it uses the correct schema (https://json.schemastore.org/pyproject.json).
The upstream validator also succeeds, it's probably a TOML->JSON conversion issue somewhere.
@tamasfe this seems to be caused by
let msg = err.error.to_string();
at taplo/crates/taplo-cli/src/printing.rs:125.
Since err.error is a jsonschema::ValidationError, it doesnt seem reasonable to do anything but patch with a more friendly explanation. That error instance is a
ValidationError {
instance: Object {
"name": String("hello"),
},
kind: OneOfNotValid,
instance_path: JSONPointer(
[
Property(
"project",
),
],
),
schema_path: JSONPointer(
[
Keyword(
"properties",
),
Property(
"project",
),
Keyword(
"oneOf",
),
],
),
},
but a string representation is unhelpful. Edit for clarity: the pyprojects schema requires one of ["dynamic", "version"] keys to be defined along with the "name" key. However, the error message doesnt provide that information (and the error struct too!)
I'll try to reproduce and investigate this when I'll get computer access in a few weeks. Thanks for the debugging!
I was able to reproduce the original error, which for the record is:
{"name":"deployment_handler","requires-python":">=3.9"} is not valid under any of the given schemas
I'm not sure what alternative behavior from taplo you would expect. I would argue that this is the job of jsonschema to produce a readable error message (ValidationError implements Display which is what taplo uses). It looks like you already fixed the message for OneOfNotValid errors in https://github.com/Stranger6667/jsonschema-rs/pull/430 a few days after your message, so I guess you reached a similar conclusion as I do?
So I would suggest bumping jsonschema version from 0.16.0 to the next release (the one after 0.17.0) to benefit from your fix. Does this sound good to you?
Yup, the conclusion was exactly that, so i was just waiting for the 0.18 to suggest bumping :)
please bump, 0.17.1 incorporates the needed changes
Thanks, I've created #428.
Version 0.8.1 has been released.