Skip to content

Add support for pcre / scripts / system hooks definition in .pre-commit-config.yaml #219

Closed

Description

@Lucas-C

Everything is in the title :)

Rationale: a pre-commit user shouldn't have to setup a git repository to configure a pre-commit check that can be defined in 5 lines or less.

Example: taken the from do_not_commit hook:

- id: do_not_commit
  name: Block if "DO NOT COMMIT" is found
  entry: DO NOT COMMIT
  language: pcre
  files: ^(.*)$

Suggested solutions:

  1. Allow for pcre / scripts / system hooks definition in .pre-commit-config.yaml
  2. Allow for the repo field in .pre-commit-config.yaml to point to a subfolder (of the git repo configured with pre-commit) that contains a hooks.yaml .
    This currently crashes because pre-commit expect to find git repository in the folder point by repo.

Activity

  1. asottile commented on May 1, 2015

    @asottile
    Member

    I think this is along similar lines of this: #173

    And is kind-of possible: https://github.com/Yelp/venv-update/blob/a5960acab7101a1e70c57945b2038fef9d005aed/.pre-commit-config.yaml#L15-L22

    I'd certainly like to make this easier though :)

  2. Lucas-C commented on May 1, 2015

    @Lucas-C
    ContributorAuthor

    Yes ! The Yelp/venv-update example is exactly what I wanted !
    If you support this, maybe mention it in the docs ?
    Although maybe allowing a repo: local value would be cleaner than having to point it to an existing dummy github repo.

  3. asottile commented on May 1, 2015

    @asottile
    Member

    Yeah that way works currently, I wouldn't call it supported yet since it's kinda clunky and I want a more straightforward way of doing that. That method is unlikely to break though. I imagine the actual implementation will be similar

  4. Lucas-C commented on May 1, 2015

    @Lucas-C
    ContributorAuthor

    Ok. Then you can resolve this ticket if you want to track this feature elsewhere.
    And thank you for your detailed answers !

  5. Lucas-C commented on May 5, 2015

    @Lucas-C
    ContributorAuthor

    I went on and hacked around it: what do you think of the solution described in #223 ?

  6. added a commit that references this issue on May 8, 2015
  7. asottile commented on May 8, 2015

    @asottile
    Member

    I'm going to clarify here since I think I'm a bit confused :)

    I'd like to make @bukzor's config work when it changes from:

    -   repo: git://github.com/bukzor/pre-commit-system-hook.git
        sha: 64a3e3f0d11f74ccd0498ea3149c8e177dd9989c
        hooks:
        -   id: system
            name: PyLint
            entry: python -m pylint.__main__
            language: system
            files: \.py$

    to

    -   repo: pre-commit-locally-configured
        hooks:
        -   id: pylint
            name: PyLint
            entry: python -m pylint.__main__
            language: system
            files: \.py$

    I think (but I might be a bit off!) that all we would need to change to support this is:

    • Change the config schema to allow for missing sha in the case the repo is our special value
    • In the case that our repo is the special value, the repository is a special list which contains "all hooks" (that is to say that anything we configure in our config will match a hook in this special repo)
    • Allow the current code which merges the config dict on top of the manifest dict to continue to work (might need it in another place as well)

    Does this sound right? (mostly wanted to just get a checklist together so it's clear what the plan is here :D)

  8. Lucas-C commented on May 8, 2015

    @Lucas-C
    ContributorAuthor

    Sounds alright, + adding some tests :)
    I won't have time to craft the commit today, but I plan to submit the pull request over the week-end.

  9. bukzor commented on May 8, 2015

    @bukzor

    Repo: null makes sense to me.
    Just don't validate the sha for language: system.

    Also: can we put system-style hooks at the top level? It doesn't actually
    make sense to nest then under a repo at all.

    Just ideas. If it makes things a mess, disregard.

    --phone is hard.
    On May 7, 2015 6:17 PM, "Anthony Sottile" notifications@github.com wrote:

    I'm going to clarify here since I think I'm a bit confused :)

    I'd like to make @bukzor https://github.com/bukzor's config work when
    it changes from:

    • repo: git://github.com/bukzor/pre-commit-system-hook.git
      sha: 64a3e3f0d11f74ccd0498ea3149c8e177dd9989c
      hooks:
    • id: system
      name: PyLint
      entry: python -m pylint.main
      language: system
      files: .py$

    to

    • repo: pre-commit-locally-configured
      hooks:
    • id: pylint
      name: PyLint
      entry: python -m pylint.main
      language: system
      files: .py$

    I think (but I might be a bit off!) that all we would need to change to
    support this is:

    • Change the config schema to allow for missing sha in the case the
      repo is our special value
    • In the case that our repo is the special value, the repository is a
      special list which contains "all hooks" (that is to say that anything we
      configure in our config will match a hook in this special repo)
    • Allow the current code which merges the config dict on top of the
      manifest dict to continue to work (might need it in another place as well)

    Does this sound right? (mostly wanted to just get a checklist together so
    it's clear what the plan is here :D)

    —
    Reply to this email directly or view it on GitHub
    #219 (comment)
    .

  10. Lucas-C commented on May 8, 2015

    @Lucas-C
    ContributorAuthor

    Repo: null makes sense to me.

    Sounds nice & simple, but null / None is often a design smell: it is often better to use an "Optional" construct, a NullObject or the SpecialCase pattern. I'll stick to the magic string constant.

    can we put system-style hooks at the top level?

    I don't understand what you meant here. I complete agree it doesn't make sense to put them in a repo, but why put them at the YAML config file hierarchy root ? I don't quite see what change to the plan @asottile detailed you are suggesting there. Could you further explain ?

  11. asottile commented on May 8, 2015

    @asottile
    Member

    Also: can we put system-style hooks at the top level?

    @bukzor this would entail a breaking change to the config file, I don't really want to do that at this time.

    EDIT: null also seems fine to me as well

  12. bukzor commented on May 9, 2015

    @bukzor

    Is fine. It probably doesn't make sense for the list to be heterogeneous.

    --phone is hard.
    On May 8, 2015 9:54 AM, "Anthony Sottile" notifications@github.com wrote:

    Also: can we put system-style hooks at the top level?
    @bukzor https://github.com/bukzor this would entail a breaking change
    to the config file, I don't really want to do that at this time.

    —
    Reply to this email directly or view it on GitHub
    #219 (comment)
    .

  13. added a commit that references this issue on Mar 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions