Skip to content

Configuration v2 #414

Closed
Closed

Description

@asottile

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:

There's also auxiliary issues:

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 (previously hooks.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

  1. Lucas-C commented on Sep 28, 2016

    @Lucas-C
    Contributor

    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 ConfigParser instead ?

    Alternatively, have you considered commentjson or something similar ?

  2. asottile commented on Sep 28, 2016

    @asottile
    MemberAuthor

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

  3. asottile commented on Sep 28, 2016

    @asottile
    MemberAuthor

    Also trying to piggyback the configuration implementation while changing the format to minimize the number of breaking versions necessary to roll this out :)

  4. Lucas-C commented on Sep 29, 2016

    @Lucas-C
    Contributor

    To clarify a little bit my point of view:

    • while I totally agree that sometime domain-specific languages are the answer, they come with a huge cost. In the case of pre-commit configuration, IMHO simplicity is more important than keeping the verbosity low (aka "better stupid JSON than a dedicated custom perfectly-fitting language" aka KISS & YAGNI)
    • I'm only discussing the choice of a new configuration language here, to replace YAML. Half of the issues you're mentioning in this issue (top-level structure & namespacing) could be solved by reorganizing the config/manifest structure without switching to another language.
    • about ConfigParser, there are various solutions to handle lists. But round tripping remains to be added.
    • commentjson has 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 dumbconf spec ?

  5. asottile commented on Sep 29, 2016

    @asottile
    MemberAuthor

    configparser

    • While you can hack lists onto the side with additional parsing layers after initial parsing it doesn't handle the situation we'd want (map containing a list of maps which contains lists)
    • In order to add roundtripping to configparser the parser would have to be mostly rewritten
    • configparser is stdlib, it would be difficult (impossible?) to convince the upstream to take such a patch. Similar suggestions have been made for the ast module and were rejected. Even if they did take the patch, we wouldn't be able to use it until python3.7 at the earliest.
    • would have to implement the parser
    • would likely have to maintain a fork

    commentjson

    • I'd argue it has no implementation. They regex out comments and have several, bugs that indicate they desperately need a real parser.
    • It doesn't look maintained or well maintained (for instance doesn't support python3)
    • would have to implement the parser

    dumbconf

    • The intent is to create a general purpose language, not a domain specific one
    • For the most part, it is a strict subset of yaml, without the unnecessary complexity. It aims to be stupid simple.
    • If something like commentjson is where we want to go, dumbconf could be made even simpler and not attempt to support yaml constructs. This would mean dropping bare words, the weird indented lists, and the automatically keyed maps. dumbconf would then be a postcard json-superset config language. If people are ok with that, I'd be completely happy.
    • If you have issues with the spec, open issues on the project.
  6. Lucas-C commented on Sep 30, 2016

    @Lucas-C
    Contributor

    Thanks for your answers.
    My personnal preference goes to a new implementation of commentjson, or else a dead-simple dumbconf.

  7. asottile commented on Oct 7, 2016

    @asottile
    MemberAuthor

    There is not formal definition of CSON, only an informal note in one project's readme. Informally, CSON is a JSON, but with a Coffeescript syntax. Sadly Coffescript has no format grammar either; it instead has a canonical implementation.

    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 :/

  8. bpicolo commented on Jan 12, 2017

    @bpicolo

    Which part of requirements does https://github.com/toml-lang/toml fail on, out of curiosity? No version that doesnt strip comments?

  9. asottile commented on Jan 12, 2017

    @asottile
    MemberAuthor

    It doesn't have a round trip editable parsing mode

  10. asottile commented on Aug 23, 2017

    @asottile
    MemberAuthor

    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:

    repos:
        # a list of repositories, the same as before

    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?

  11. pradyunsg commented on Sep 15, 2019

    @pradyunsg

    It doesn't have a round trip editable parsing mode

    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 :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions