[Python] Pre-commit finds local hooks even after deleting the hooks directory and clearing the...

Discussão em 'Python' iniciado por Stack, Janeiro 18, 2025.

  1. Stack

    Stack Membro Participativo

    I am using pre-commit to manage local hooks for my repository. Initially, I added a local repository containing my hooks and configured the .pre-commit-config.yaml file to reference these hooks. It worked perfectly both in my local environment and in the CI pipeline.

    snippet of code from .pre-commit-config.yaml. I have installed pre_commit_hooks as a local module, configed

    - repo: local
    hooks:
    - id: trailing-whitespace
    name: Trim trailing-whitespace
    language: python
    entry: python3 -m pre_commit_hooks.trailing_whitespace_fixer
    additional_dependencies: [pre_commit_hooks]


    However, I noticed a strange behavior:


    • If I delete the directory containing the hooks (the repository with the hooks files), pre-commit still runs the hooks successfully.


    • I tried clearing the cache using pre-commit clean and even manually deleted the cache folder (e.g., ~/.cache/pre-commit/), but the hooks still run without issues.

    I cannot figure out how pre-commit is able to find and execute the hooks after the source directory has been deleted.

    My questions:


    • How is pre-commit able to find and execute the hooks after the source directory is deleted?


    • How can I ensure pre-commit no longer runs the hooks if the source directory is deleted?

    I have tried:


    1. Cleared Pre-Commit Cache:

      • Ran pre-commit clean and manually removed the cache directory (e.g., ~/.cache/pre-commit).


      • Verified the cache directory was empty.

    2. Removed Git Hooks:
      • Checked .git/hooks/ for any residual scripts and deleted the pre-commit script.

    3. Verified Configuration:
      • Removed the .pre-commit-config.yaml file temporarily, and as expected, pre-commit failed to run.

    4. Inspected Pre-Commit’s Behavior:
      • Ran pre-commit run --verbose to trace execution but didn’t find useful information about where the hooks were being sourced from.

    Continue reading...

Compartilhe esta Página