Last active
December 6, 2021 15:06
-
-
Save guilatrova/c1483789aced7dc9af94472ab3cedb67 to your computer and use it in GitHub Desktop.
Base Python Config: pre-commit hooks and pyproject.toml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| repos: | |
| - repo: https://github.com/pre-commit/pre-commit-hooks | |
| rev: v3.4.0 | |
| hooks: | |
| - id: end-of-file-fixer | |
| - id: trailing-whitespace | |
| - repo: https://github.com/psf/black | |
| rev: 21.11b1 | |
| hooks: | |
| - id: black | |
| - repo: https://gitlab.com/pycqa/flake8 | |
| rev: 4.0.1 | |
| hooks: | |
| - id: flake8 | |
| exclude: samples/ | |
| - repo: https://github.com/timothycrosley/isort | |
| rev: 5.10.1 | |
| hooks: | |
| - id: isort | |
| - repo: https://github.com/pre-commit/mirrors-mypy | |
| rev: v0.910 | |
| hooks: | |
| - id: mypy | |
| additional_dependencies: [types-toml==0.1.3] | |
| - repo: https://github.com/guilatrova/tryceratops | |
| rev: v1.0.0 | |
| hooks: | |
| - id: tryceratops |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [tool.poetry] | |
| ... | |
| packages = [ | |
| { include = "PACKAGE_NAME", from = "src" }, | |
| ] | |
| [tool.black] | |
| line-length = 120 | |
| [tool.isort] | |
| profile = "black" | |
| line_length = 120 | |
| extra_standard_library = ["pytest"] | |
| [tool.mypy] | |
| ignore_missing_imports = true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [flake8] | |
| max-line-length=120 | |
| extend-ignore=E203 | |
| exclude= | |
| __init__.py |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Pre-commit config
This template uses the following linters:
pyproject.tomlline lengthI don't have strong opinions about line length, but 88 is often too short. The challenge is to keep all linters "agree" with each other, so the above model ensures it's 120 as default and makes it obvious for you to replace it with any other number you prefer.
packagesWhen testing a CLI or related package that I need to import globally, it's useful to add this section to make poetry install your package. (Similar to
pip install -e .).extra_standard_libraryI feel
pytestis often part of the standard python lib (it's not), so it makes me comfortable to keep it at the top when sorting.ignore_missing_importsWhen this flag is disable
mypycan get really noisy.setup.cfgThe only purpose of this file is because flake8 still doesn't support
pyproject.toml.