Repository navigation
Description
A bit of an RFC
Issues
There's some "problems" with the current configuration and I'd like to address those in a backwards incompatible way (probably through a migration period where both formats are allowed).
There's two primary issues I'd like to address with the current configuration format:
- The top level is currently a list, making it difficult to add repository-level configuration: Feature request : add a "fail fast" configuration entry #240 Global configuration of files / exclude #281 (as well as other things I'd like such as repository-level interpreter version)
- The configuration is not scriptably rewriteable: autoupdate is awesome except it gobbles comments and reformats lists :/ #210
There's also auxiliary issues:
- yaml is not maintained
- yaml has some security issues Redesigning as pure Python distribution #396
hooks.yamlisn't well namespaced
Proposal
A new configuration language
I shopped around for configuration languages which fit the criteria above, notably:
- Provides a non-C implementation
- Supports comments + maps + lists
- Supports round-trip rewritability
- Has a python implementaiton
And did not find anything. Given that, I've started speccing and implementing a configuration language with those design goals in mind. It also aims to be significantly simpler than yaml (the spec may not fit on a postcard like json, but it's also not 70+ pages like yaml).
New filenames
The names of the files will need to change for two reasons:
- The configuration will no longer be yaml
- hooks.yaml is not a namespaced-enough name
Proposing:
.pre-commit-config- describes the consumer configuration (previously.pre-commit-config.yaml).pre-commit-manifest- describes the repository configuration (previouslyhooks.yaml)
New configuration structure
The new configuration structure will be a top-level mapping type to allow repository-wide configuration. This map will have a hooks key which will contain the current configuration.
hooks: [
...,
]This will allow for top-level configuration which will apply to all hooks (such as global excludes, interpreter versions, etc.)
Migration
- The new configuration will be introduced.
- In that release and the next two releases (or the next 3 months, whichever comes sooner), pre-commit will load both configuration formats but issue warnings for the legacy format.
- After the migration period, the old configuration format will be purged.
The "officially" maintained repositories (pre-commit/pre-commit-hooks as well as the mirrors-* repositories) will force-push tags for the lastest $n versions and provide both configuration formats for those tags. Going forward, pre-commit/pre-commit-mirror-maker will only produce the new configuration format.
To assist in migration (though the formats should be relatively easy to manually migrate) a tool will be created pre-commit-migrate which will attempt to take the legacy format and produce new configuration files. Given yaml's lack of rewritability this will likely reformat lists and drop comments, but for the last time!
Thoughts?
Activity
Lucas-C commentedon Sep 28, 2016
I don't want to look too pessimistic, but it looks really ambitious to me to define a new configuration format just for this use case. That means a lot more complexity indirectly added to the project, and giving to the end user a less user-friendly experience ("what ? another language to learn ?").
Given your criterias, "good old .ini files" could do the job here. Why not contributing to the whole community and adding support for comments round trip into Python
ConfigParserinstead ?Alternatively, have you considered
commentjsonor something similar ?asottile commentedon Sep 28, 2016
I'm going to assume you're addressing just yaml and not the other reasons for changing the configuration -- those are the stronger reasons for changing it and I figure we should just change them all at once.
If you peek at the configuration format, it mostly aims to be a subset of yaml. From the spec I've laid out, the current examples (and checked in configuration in this and the official repositories) would already parse in the new language.
configparser isn't sufficient both because it cannot be round tripped and because it does not support maps + lists (it is a 1-level configuration).
commentjson suffers from being more verbose than most people would like (otherwise I would just use json with
"//": "this is a comment"like we do for our npm packages). It also suffers from not being round trippable (their parser simply regexes out comments and calls the json parser).asottile commentedon Sep 28, 2016
Also trying to piggyback the configuration implementation while changing the format to minimize the number of breaking versions necessary to roll this out :)
Lucas-C commentedon Sep 29, 2016
To clarify a little bit my point of view:
pre-commitconfiguration, IMHO simplicity is more important than keeping the verbosity low (aka "better stupid JSON than a dedicated custom perfectly-fitting language" aka KISS & YAGNI)ConfigParser, there are various solutions to handle lists. But round tripping remains to be added.commentjsonhas a fairly simple implementation. It looks to me more interesting to contribute to this project or take inspiration from it in order to build a lib than handle round trippable JSON with comments, instead of creating yet-another-language.Finally, is there a place to discuss
dumbconfspec ?asottile commentedon Sep 29, 2016
configparser
astmodule and were rejected. Even if they did take the patch, we wouldn't be able to use it until python3.7 at the earliest.commentjson
dumbconf
Lucas-C commentedon Sep 30, 2016
Thanks for your answers.
My personnal preference goes to a new implementation of commentjson, or else a dead-simple dumbconf.
Lucas-C commentedon Oct 7, 2016
What about CSON ?
asottile commentedon Oct 7, 2016
I also rather dislike coffeescript on being too loose and magical
They also don't seem to have round trip parsers which would require significant modifications :/
bpicolo commentedon Jan 12, 2017
Which part of requirements does https://github.com/toml-lang/toml fail on, out of curiosity? No version that doesnt strip comments?
asottile commentedon Jan 12, 2017
It doesn't have a round trip editable parsing mode
asottile commentedon Aug 23, 2017
With #210 "resolved", switching configuration languages is less of a concern.
I think instead this should focus on redesigning the top level, here's my thoughts on this:
.pre-commit-hooks.yaml (the remote metadata)
I think at least for now this can largely remain the same -- I don't think there's any pressing need to change the structure away from its current state -- moving it from a top-level list to a top-level map is more of a "nice to have".
.pre-commit-config.yaml (the local configuration)
The top level list structure makes it difficult to add more features to pre-commit. I'm proposing changing it to a map. At first the proposal is just the following:
a migration tool
Some sort of tool (external to pre-commit itself?) would be crafted which would automatically change the old format configuration to the new format configuration. Eventually warnings would be produced and then further off the old configuration would no longer be supported.
Beyond that, more of the desired features requiring top-level configuration can start to be implemented.
Thoughts on this?
pradyunsg commentedon Sep 15, 2019
I mean, it's not a language quirk FWIW -- it just didn't have a capable parser in Python at that time I think. We have tomlkit now: https://github.com/sdispater/tomlkit
I'm super late to this party so :(