Skip to content

Instantly share code, notes, and snippets.

@Andrew-Chen-Wang
Created August 6, 2020 01:53
Show Gist options
  • Save Andrew-Chen-Wang/7f2606b0623ae125673629a1e931c91a to your computer and use it in GitHub Desktop.
Save Andrew-Chen-Wang/7f2606b0623ae125673629a1e931c91a to your computer and use it in GitHub Desktop.
My pre-commit Python template
exclude: 'docs|node_modules|.git|.tox'
default_stages: [commit]
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: master
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- repo: https://github.com/psf/black
rev: 19.10b0
hooks:
- id: black
- repo: https://github.com/timothycrosley/isort
rev: 4.3.21
hooks:
- id: isort
args: ['--settings-path=setup.cfg', '-rc']

Usage:

  • pip install pre-commit
  • Copy and paste the file. Note, it will only pick up on yaml, not yml.
  • Install the pre-commit by doing pre-commit install
  • Test run: pre-commit run --all-files
  • Actual usage is when you commit. If errored, then re-add files: git add .

I'm using isort v4.3.21 because it does proper linting like flake8 in that, if you were to have some long import line, then the parenthesis would wrap the imports vertically. v5 isort just wraps the imports until it hits the line length max again (unless I'm missing a configuration).

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