Content-Length: 223955 | pFad | http://github.com/pre-commit/pre-commit/issues/3474

B8 Define used hooks in `pyproject.toml` on top of `.pre-commit-config.yaml` · Issue #3474 · pre-commit/pre-commit · GitHub
Skip to content

Define used hooks in pyproject.toml on top of .pre-commit-config.yaml #3474

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
saroad2 opened this issue May 30, 2025 · 1 comment
Closed

Comments

@saroad2
Copy link

saroad2 commented May 30, 2025

search you tried in the issue tracker

pyproject, config

describe your actual problem

TL;DR

It would be nice if a user could define the hooks they want to use in a repo in pyproject.toml instead of .pre-commit-config.yaml.

The Core Idea

At the moment, in order to define which hooks are going to be used in a specific repo, one needs to define a .pre-commit-config.yaml file and define the hooks there.

Most python tools support defining their config in both their own unique configration file and in a project pyproject.toml file. For example:

  1. You can define the mypy config in both a mypy.ini file and pyproject.toml
  2. You can define the coverage config in both .coverage file and pyproject.toml
  3. etc.

It would be nice if pre-commit could support this ability as well.

Proposed Solution

pre-commit will try to read config initially from .pre-commit.config..yaml. If this file is missing, it will search for a pyproject.toml. If this file exists, it will be read the config from a [tool.pre-commit] section.

In this way, the following .pre-commit-config.yaml file:

repos:
-   repo: https://github.com/asottile/pyupgrade
    rev: v3.20.0
    hooks:
    -   id: pyupgrade
        args: [--py39-plus]
-   repo: https://github.com/hhatto/autopep8
    rev: v2.3.2
    hooks:
    -   id: autopep8
-   repo: https://github.com/PyCQA/flake8
    rev: 7.2.0
    hooks:
    -   id: flake8

Will look like this in a pyproject.toml:

[[tool.pre-commit.repos]]
repo = "https://github.com/asottile/pyupgrade"
rev = "v3.20.0"
hooks = [{id = "pyupgrade", args = ["--py39-plus"]}]

[[tool.pre-commit.repos]]
repo = "https://github.com/hhatto/autopep8"
rev = "v2.3.2"
hooks = [{id = "autopep8"}]

[[tool.pre-commit.repos]]
repo = "https://github.com/PyCQA/flake8"
rev = "7.2.0"
hooks = [{id = "flake8"}]

I think it will be beneficial for pre-commit to provide .pyproject.toml support as part of its capabilities.

Please let me know what you think.

pre-commit --version

latest

@asottile
Copy link
Member

search the issue tracker next time

@pre-commit pre-commit locked as off-topic and limited conversation to collaborators May 30, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

2 participants








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/pre-commit/pre-commit/issues/3474

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy