[Python] With pre-commit, how to use some hooks before commit and others before push

Discussão em 'Python' iniciado por Stack, Março 1, 2025.

  1. Stack

    Stack Membro Participativo

    Some hooks can take a while to run, and I would like to run those before I push, but not before each particular commit (for example, pylint can be a bit slow).

    I've seen the following:


    But it's still not clear to be how I'm supposed to set this up.

    Here is what I have tried:

    default_stages: [commit]
    repos:
    - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v3.1.0
    hooks:
    - id: end-of-file-fixer
    - id: trailing-whitespace
    - repo: https://github.com/psf/black
    rev: 19.10b0
    hooks:
    - id: black
    stages: [push]


    From that I'm expecting the first couple of hooks to run before a commit (which they do), but I'm expecting black to run before pushing, which it doesn't.

    To test that I have created the following file:

    """This is a docstring."""

    print('this should be formatted')


    Which is certainly not being formatted by black.

    Continue reading...

Compartilhe esta Página