-
Notifications
You must be signed in to change notification settings - Fork 249
Add JSON schemas for pyrefly.toml and pyproject.toml validation #2100
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
base: main
Are you sure you want to change the base?
Conversation
|
Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at [email protected]. Thanks! |
connernilsen
left a comment
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.
Hey @Prathamesh-tech-eng, thanks for working on this!
I have a few recommendations for changes, and an additional followup to make sure this is integrated into Schemastore as well.
For the followup, can we:
- make a PR to schemastore to add our
pyrefly.jsonthere. - update their
pyproject.tomlto have atoolentry for Pyrefly. - Add some tests like the ones for
pyproject.toml? Doesn't need to be a ton, but just some stuff to verify what we're doing is generally correct.
schemas/pyrefly.json
Outdated
| "errors": { | ||
| "description": "Error configuration overrides for matched files.", | ||
| "type": "object", | ||
| "additionalProperties": { | ||
| "type": "boolean" | ||
| } | ||
| }, | ||
| "replace-imports-with-any": { | ||
| "description": "Module glob patterns to replace with typing.Any for matched files.", | ||
| "type": "array", | ||
| "items": { | ||
| "type": "string" | ||
| } | ||
| }, | ||
| "untyped-def-behavior": { | ||
| "description": "Override untyped function behavior for matched files.", | ||
| "type": "string", | ||
| "enum": ["check-and-infer-return-type", "check-and-infer-return-any", "skip-and-infer-return-any"] | ||
| }, | ||
| "ignore-errors-in-generated-code": { | ||
| "description": "Override generated code error handling for matched files.", | ||
| "type": "boolean" | ||
| } | ||
| } |
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'm not sure if this is possible, so if you struggle to find a way to do this, don't worry about it.
Could we pull this out into a subschema and do two things with it?
- flatten the subschema into the top-level object
- reuse that sub-schema here
This would help us avoid redefining definitions in multiple places, which means we won't have to remember to update multiple things if there are changes to the config base object.
Again, not sure if flattening is possible, but it would be awesome if it works!
| @@ -0,0 +1,277 @@ | |||
| { | |||
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.
If you look at how the pyproject.toml in schemastore works, we might be able to get away with just the pyrefly.json config below and reference it in a pyproject definition.
When we merge into schemastore, I'd like to follow those examples, so this file will be redundant.
| "description": "The Python version to use for type checking. Format: <major>[.<minor>[.<micro>]]", | ||
| "type": "string", | ||
| "default": "3.13.0", | ||
| "pattern": "^\\d+(\\.\\d+)?(\\.\\d+)?$" |
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.
Awesome validation!
| { | ||
| "if": { | ||
| "properties": { | ||
| "type": {"const": "buck"} | ||
| } | ||
| }, | ||
| "then": { | ||
| "properties": { | ||
| "isolation-dir": true, | ||
| "extras": true | ||
| } | ||
| } | ||
| }, | ||
| { | ||
| "if": { | ||
| "properties": { | ||
| "type": {"const": "custom"} | ||
| } | ||
| }, | ||
| "then": { | ||
| "required": ["command"], | ||
| "properties": { | ||
| "command": true, | ||
| "repo_root": true | ||
| } | ||
| } | ||
| } |
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.
Is it possible to set not conditions here for the custom-only fields when using the buck type, and vice versa for custom with buck-only fields?
It might be possible to do a subschema for the buck and custom fields, specify both subschemas in the field definitions, and just list the subschemas here to simplify the conditions.
schemas/pyrefly.json
Outdated
| "isolation-dir": true, | ||
| "extras": true | ||
| } |
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.
Just to double check, these aren't required fields, right? Just fields that are allowed with the buck type?
schemas/pyrefly.json
Outdated
| "required": ["command"], | ||
| "properties": { | ||
| "command": true, | ||
| "repo_root": true |
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.
Repo root should be for all types, not just custom
- Extract configBase into reusable subschema - Flatten configBase properties into top-level schema - Reuse configBase in sub-config via - Fix build-system: move repo_root to all types, add not conditions - Simplify pyproject-tool-pyrefly.json to reference pyrefly.json - All tests passing
|
@connernilsen I've addressed all the feedback! Here is a summary of the changes:
Moved repo_root: It is now a top-level property inside build-system, accessible to both buck and custom types (addressing your comment about it being for all types). Added strict not conditions: If type: "buck", the schema explicitly forbids command. If type: "custom", the schema requires command but forbids isolation-dir and extras. Clarified optional fields: isolation-dir and extras are defined as properties but not required (answering your question about them).
Once this is approved, I'll proceed with opening the PR to SchemaStore. |
Description:
This PR adds JSON schemas (
pyrefly.jsonandpyproject-tool-pyrefly.json) to enable editor support (auto-completion, validation, and documentation) for Pyrefly configuration files inpyrefly.tomlandpyproject.toml.Fixes #536
Notes:
crates/pyrefly_config/src/config.rsand andcrates/pyrefly_config/src/base.rsproject-includes) as defined by the Serde structs.schemas/directory