Skip to content

Workflow: recommend pre-commit for code checks #23616

Closed
@TomAugspurger

Description

@TomAugspurger

pre-commit is a library for running pre-commit hooks (actually does more that just pre-commit). Adding additional code checks is likely to annoy first-time contributors (isort); we can use tools to avoid that.

I've been using this .pre-commit-config.yaml

repos:
    - repo: https://github.com/pre-commit/pre-commit-hooks
      rev: 2dbaced6501ea775d9e5a7677c49627899a17756
      hooks:
          - id: flake8
            language: python_venv
    - repo: https://github.com/pre-commit/mirrors-isort
      rev: f35773e46d096de5c45365f1a47eeeef36fc83ed
      hooks:
          - id: isort
            language: python_venv

With that in the root of my directory, every time I git commit, those code checks are run.

Suppose I have an out-of-order import, and go to commit my changes

bash-4.4$ git add .
bash-4.4$ git commit -m 'fixup'
Flake8...................................................................Passed
isort....................................................................Failed
hookid: isort

Files were modified by this hook. Additional output:

Fixing /Users/taugspurger/sandbox/pandas/pandas/core/arrays/array_.py

The hook modified the file in place. I can check the status / diff from HEAD

bash-4.4$ git status
On branch pd.array
Your branch is up to date with 'origin/pd.array'.

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        modified:   pandas/core/arrays/array_.py

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   pandas/core/arrays/array_.py

add them, and commit again

bash-4.4$ git add .
bash-4.4$ git commit -m 'fixup'
Flake8...................................................................Passed
isort....................................................................Passed
[pd.array 5fcf609f3] fixup
 1 file changed, 4 insertions(+)

before pushing.


What are people's thoughts. I think we can distribute a .pre-commit-config.yaml with the git repo. If pre-commit isn't installed, I assume nothing will happen.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Code StyleCode style, linting, code_checksNeeds DiscussionRequires discussion from core team before further action

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions