Skip to main content

pre-commit hooks for python projects using pyproject.toml.

Project description

pyproject-pre-commit

test test coverage

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:

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyproject_pre_commit-0.1.2.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyproject_pre_commit-0.1.2-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file pyproject_pre_commit-0.1.2.tar.gz.

File metadata

  • Download URL: pyproject_pre_commit-0.1.2.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.10.13 Linux/6.2.0-1016-azure

File hashes

Hashes for pyproject_pre_commit-0.1.2.tar.gz
Algorithm Hash digest
SHA256 2fe493b1c90f843b67e6d3beb736ffdf060c79d11494eba7c983882f6bc2f7c8
MD5 d11732872bb9663936eee548b24d096c
BLAKE2b-256 a52ffa64802e0011acb4437ddd069fde5f0e7aacdf1a57f6ecd62ed428b5c4d3

See more details on using hashes here.

File details

Details for the file pyproject_pre_commit-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: pyproject_pre_commit-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 9.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.10.13 Linux/6.2.0-1016-azure

File hashes

Hashes for pyproject_pre_commit-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b428558e3bd0d1b01dabc4e861ccb8bef8fcc4771081102f44f30e5fa2058104
MD5 52af612bc9bce54595f09eaed844759d
BLAKE2b-256 cb17bb57fb5c662f85eeb31ccff6e639e51b1f8d4d0b73492874188ac6cbfd4d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page