pre-commit hooks for python projects using pyproject.toml.
Project description
pyproject-pre-commit
pre-commit hooks for python projects using pyproject.toml.
.pre-commit-hooks.yaml provides pre-defined ids which you just need to add these ids to your .pre-commit-config.yaml.
Requirement
- Python 3.11, 3.10, 3.9, 3.8
- Poetry (For development)
Installation
If your project uses poetry, do:
$ poetry add --group dev pyproject-pre-commit
Otherwise, install by pip:
$ pip install pyproject-pre-commit
The repository features
If you install this package, several linters/formatters will be installed, too.
This repository has following hooks for pre-commit:
- For Python
- black-diff: Just show Black result.
- black: Black: The uncompromising Python code formatter.
- blacken-docs: Run
black
on python code blocks in documentation files. - autoflake-diff: Just show autoflake result.
- autoflake: autoflake removes unused imports and unused variables from Python code.
- autopep8-diff: Just show autopep8.
- autopep8: autopep8 automatically formats Python code to conform to the PEP 8 style guide.
- isort-diff: Just show isort result.
- isort: isort your imports, so you don't have to.
- flake8:
flake8
is a command-line utility for enforcing style consistency across Python projects. - bandit: Bandit is a tool for finding common security issues in Python code.
- mypy: Mypy is a static type checker for Python.
- For Shell script
- shellcheck: ShellCheck - A shell script static analysis tool
- For Markdown
- mdformat-check: Just show mdformat result.
- mdformat: CommonMark compliant Markdown formatter.
- with following plugins:
All tools are installed as dependencies of this package.
shellcheck and mdformat are given in addition to python tools as they can be managed by pip and most projects have README.md and some have shell scripts.
For tools which can format files, there are additional ids ids with -diff
or --check
which just show the results and not modify files.
You can see the difference after formatting if you place these ids before ids w/o --diff
or --check
.
You can set options in pyproject.toml for all tools above:
- flake8: flake8-pyproject allows to read options from pyproject.toml
- bandit: There is a plugin for the flake8, but plugin version does not read options from pyproject.toml even with pyproject.toml. Therefore, use bandit directly and give
-c pyproject.toml
option in the hooks.
.pre-commit-config.yaml
Prepare .pre-commit-config.yaml like:
repos:
- repo: https://github.com/rcmdnk/pyproject-pre-commit
rev: v0.1.1
hooks:
- id: black-diff
- id: black
- id: blacken-docs
- id: autoflake-diff
- id: autoflake
- id: autopep8-diff
- id: autopep8
- id: isort-diff
- id: isort
- id: flake8
- id: bandit
- id: mypy
- id: shellcheck
- id: mdformat-check
- id: mdformat
This can be made by ppc
command:
$ ppc --pre-commit > .pre-commit-config.yaml
If you already have it, add hooks w/o repos:
by
$ ppc --pre-commit |grep -v "^repos:" >> .pre-commit-config.yaml
You may want to modify after adding these configurations.
pyproject.toml
You can set options in pyproject.toml for all tools.
Example options can be made by ppc
command:
$ ppc --pyproject >> pyproject.toml
You may want to modify after adding these configurations.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for pyproject_pre_commit-0.1.8.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 83b0cb5353cd6ea4cf4e42a8b300897cae8932d24c0379f320d9e474ded12918 |
|
MD5 | 988815007b9d37fdc44ecca7302b47ca |
|
BLAKE2b-256 | ebb26e2738a7265b83baf7ac30e6cae998ca1157687ae4dfa3999960442e0a46 |
Hashes for pyproject_pre_commit-0.1.8-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 732ce6bf4fec32d194872a0922c66b9a3b74e34a731709a2177a4f073c72ff00 |
|
MD5 | ece2ca50a9171022f1c9c26175220055 |
|
BLAKE2b-256 | d8b9b5c2d8661a86b8aa6ba71295ddf2e01bb2b0df9bc4bf21592c60a245a8e6 |