Skip to main content

pyproject-pre-commit

test test coverage

pre-commit hooks for python projects. prek also works as well (current default depends on prek).

.pre-commit-hooks.yaml provides pre-defined ids which you just need to add these ids to your .pre-commit-config.yaml.

By installing pyproject-pre-commit package, all necessary tools are installed as dependencies.

Requirement

  • Python >= 3.9.0

Usage

Install pyproject-pre-commit

Using uv:

$ uv add --group dev pyproject-pre-commit

Using poetry:

$ poetry add --dev pyproject-pre-commit

Using pip:

$ pip install pyproject-pre-commit

This will install pyproject-pre-commit and

    "prek>=0.3.2",
    "ruff>=0.15.0",
    "ty>=0.0.15",
    "numpydoc>=1.11.0",
    "shellcheck-py>=0.9.0.5",
    "mdformat>=0.7.22",
    "mdformat-pyproject>=0.0.1",
    "mdformat-ruff>=0.1.3",
    "mdformat-beautysh>=0.1.1",
    "mdformat-config>=0.2.1",
    "mdformat-gofmt>=0.0.2",
    "mdformat-rustfmt>=0.0.3",
    "mdformat-footnote>=0.1.1",
    "mdformat-frontmatter>=2.0.1",
    "mdformat-gfm>=0.3.5",
    "mdformat-tables>=1.0.0",
    "mdformat-web>=0.2.0",
    "mdformat-toc>=0.3.0",
    "validate-pyproject[all]>=0.22",

Optional dependencies

if you want to install pre-commit, do:

$ uv add --dev pyproject-pre-commit[pre-commit]

If you want to use black/autoflake/autopep8/flake8/isort/bandit for linting/formatting, do:

$ uv add --dev pyproject-pre-commit[black]

If you need mypy, do:

$ uv add --dev pyproject-pre-commit[mypy]

If you wish to install all, do:

$ uv add --dev pyproject-pre-commit[all]

Prepare .pre-commit-config.yaml

Add https://github.com/rcmdnk/pyproject-pre-commit to your .pre-commit-config.yaml, like:

repos:
  - repo: https://github.com/rcmdnk/pyproject-pre-commit
    rev: v0.6.0
    hooks:
      - id: ruff-lint-diff
      - id: ruff-lint
      - id: ruff-format-diff
      - id: ruff-format
      - id: ty
      - id: numpydoc-validation
      - id: shellcheck
      - id: mdformat-check
      - id: mdformat
      - id: actionlint
      - id: validate-pyproject

By using pyproject-pre-commit, you can simplify your .pre-commit-config.yaml that you need only repo of https://github.com/rcmdnk/pyproject-pre-commit.

These hooks uses local installation of tools, so pre-commit will use tools installed in your working environment.

This can be made by ppc command:

$ ppc pre-commit > .pre-commit-config.yaml

[!NOTE] If you are using poetry, run poetry run ppc ... or run after poetry shell.

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.

To use black, flake8, isort and mypy, instead of ruff/ty, add following hooks:

repos:
  - repo: https://github.com/rcmdnk/pyproject-pre-commit
    rev: v0.6.0
    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: numpydoc-validation
      - id: shellcheck
      - id: mdformat-check
      - id: mdformat
      - id: actionlint
      - id: validate-pyproject

This can be made by ppc command:

$ ppc pre-commit --black --mypy > .pre-commit-config.yaml

Run prek/pre-commit

prek command is installed as dependencies of pyproject-pre-commit package.

After installing pyproject-pre-commit package, you can run prek command.

First, install pre-commit hooks by:

$ prek install

then you can run pre-commit by:

$ prek run -a

[!NOTE] If you are using uv, run uv run pre-commit ...

If you want to use pre-commit command, install pyproject-pre-commit[pre-commit] and use pre-commit command.

Available ids

You can find ids in .pre-commit-hooks.yaml.

There are ids for following tools:

All tools are installed as dependencies of pyproject-pre-commit 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 with -diff or --check which show the results before modifying files. You can see the differences after formatting if you place these ids before ids w/o --diff or --check.

Options for tools

You can set options in pyproject.toml for all tools above.

For flake8, flake8-pyproject allows to read options from pyproject.toml

About 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.

pyproject.toml

You can set options in pyproject.toml for all tools.

Example options can be made by ppc command:

$ ppc --pyproject >> pyproject.toml

or

$ ppc --pyproject --black --mypy >> pyproject.toml

You may want to modify after adding these configurations.

Metadata

Release files for pyproject-pre-commit 0.6.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyproject-pre-commit 0.6.1
File Size Uploaded
pyproject_pre_commit-0.6.1.tar.gz 125.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyproject-pre-commit 0.6.1
File Interpreter ABI Platform
pyproject_pre_commit-0.6.1-py3-none-any.whl Python 3 none any Details

Total release size: 137.5 kB

Release files / pyproject_pre_commit-0.6.1.tar.gz

Download URL pyproject_pre_commit-0.6.1.tar.gz
Size 125.7 kB
Tags Source
SHA-256 checksum
How to use checksums
363605b84aafae999709609d2fb2bc957133dd2fa6ba434d871490dc7efc40ed
BLAKE2b-256 checksum
How to use checksums
24862aee32fb94f2ca600dec054a33a3e06e014d5d7dd1e635d53d4ea579bee5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / pyproject_pre_commit-0.6.1-py3-none-any.whl

Download URL pyproject_pre_commit-0.6.1-py3-none-any.whl
Size 11.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
23853baebd3e8e334549c6e63f117a4d42ec10c6d8e8565695d9559a2437b2bd
BLAKE2b-256 checksum
How to use checksums
62b6c9c942bcc7b5a1b61c3eda62a875630d528171cf495fb5d077258499c2b2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

This release

0.6.1 This release

2 release files

0.6.0

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.3

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.6

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.24

2 release files

0.0.23

2 release files

0.0.22

2 release files

0.0.21

2 release files

0.0.20

2 release files

0.0.19

2 release files

0.0.18

2 release files

0.0.16

2 release files

0.0.15

2 release files

0.0.14

2 release files

0.0.12

2 release files

0.0.11

2 release files

0.0.10

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page