3

I have aflake8:check todo pre-commit hook, which I want to ignore for now.

I can ignore everything if I git commit --no-verify but I do want all other hooks to run

I also can edit my .pre-commit-hooks.yaml to remove the relevant hook, but I do want it. Just not now...

Is it possible to skip this hook check just for this commit / push?


My config .pre-commit-config.yaml:

default_language_version:
    python: python3.6
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
  rev: v4.1.0 # 4.2.0 drops python<3.7
  hooks:
  - id: check-added-large-files
  - id: check-case-conflict
  - id: check-docstring-first
  - id: check-executables-have-shebangs
  - id: check-toml
  - id: check-merge-conflict
  - id: check-yaml
  - id: debug-statements
  - id: end-of-file-fixer
  - id: mixed-line-ending
  - id: sort-simple-yaml
  - id: trailing-whitespace
- repo: local
  hooks:
  - id: todo
    name: Check TODO
    language: pygrep
    args: [-i]
    entry: TODO
    types: [text]
    exclude: ^(.pre-commit-config.yaml|.github/workflows/test.yml)$
- repo: https://gitlab.com/pycqa/flake8
  rev: 3.9.2
  hooks:
  - id: flake8
    # P103 - disallows "{}" in strings
    # E203 - ":" with whitespace before it
    # E501 - line length (black will handle most of the issues, and what it can't - should be ingored)
    args: ["-j8", "--ignore=E203,E501,P103"]
    additional_dependencies:
    - flake8-broken-line
    - flake8-bugbear
    - flake8-comprehensions
    - flake8-debugger
    - flake8-string-format
- repo: https://github.com/PyCQA/isort
  rev: 5.10.1
  hooks:
  - id: isort
    args: ["--profile", "black"] # solves conflicts between black and isort
- repo: https://github.com/psf/black
  hooks:
  - id: black
  rev: 22.3.0
CIsForCookies
  • 12,097
  • 11
  • 59
  • 124
  • 1
    Git itself has no special tooling for this. Environment variables (e.g., SKIP=... git commit) are simply passed through to whatever program(s) you have chosen to use as your pre-commit hook(s). It is up to those programs to look for and use any environment variables you might wish to use. So your question is really "what programs have which variables for controlling how they use flake8" and that's not a *Git* question at all. It's probably best tagged with [tag:flake8]. – torek May 12 '22 at 21:48

1 Answers1

6

That's actually the exact case described in the docs:

Not all hooks are perfect so sometimes you may need to skip execution of one or more hooks. pre-commit solves this by querying a SKIP environment variable. The SKIP environment variable is a comma separated list of hook ids. This allows you to skip a single hook instead of --no-verifying the entire commit.

$ SKIP=flake8 git commit -m "foo"
Dominik Stańczak
  • 2,046
  • 15
  • 27
  • Wouldn't that skip the entire flake8? I only want to skip one subhook on it, something like `SKIP=flake8.check_todo` – CIsForCookies May 12 '22 at 14:58
  • 1
    Ooooooooooooooooh. Darn. Yeah, it probably would - I completely missed that. Could you post your pre-commit config yaml file? – Dominik Stańczak May 12 '22 at 17:22
  • @CIsForCookies Having seen your config file, I guess I don't understand why you have a separate `todo` hook (which you could skip with `SKIP=todo`) and some sort of invisible (at least, judging by the config) flake8 sub-check. Wouldn't these achieve the same thing, anyway? I guess I'd sidestep the issue by disabling any TODO checks in the flake8 hook and letting the `todo` hook do it. – Dominik Stańczak May 13 '22 at 09:48
  • 1
    afaict there's no flake8 todo plugin configured so I suspect OP is confused – anthony sottile May 13 '22 at 09:57
  • Oh... So sorry. Indeed there was a small blunder here. But the question still stands - just with another example - how to disable only one part of flake8? – CIsForCookies May 13 '22 at 14:57
  • The only way I can imagine that working is by environment variables, and https://github.com/PyCQA/flake8/search?q=env flake8 doesn't really seem to use them. That seems to be a no go. – Dominik Stańczak May 13 '22 at 18:50