Registry / testing / pre-commit

pre-commit

JSON →
library4.6.2pypypi✓ verified 27d ago

A framework for managing and maintaining multi-language pre-commit hooks. Current version: 4.5.1. Released on December 16, 2025. Maintained with regular updates.

pip install pre-commit
INSTALL
IMPORT
SIG · PRE-COMMIT
P
pre-commit
testingpythonv4.6.2
Install
3.1s avg
Import
Disk
30MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v4.6.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 31.4MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 3.1s · import 0.000s · 33MB
30MB installed
● package 30MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

pre_commit
import pre_commit
Ensure correct import path to avoid ImportError.

A script to install pre-commit, set up a configuration file with the Black formatter, install git hooks, and run them against all files.

import os # Install pre-commit os.system('pip install pre-commit') # Create a configuration file with open('.pre-commit-config.yaml', 'w') as f: f.write('repos:\n - repo: https://github.com/pre-commit/mirrors-black\n rev: v22.10.0\n hooks:\n - id: black\n') # Install the git hook scripts os.system('pre-commit install') # Run hooks against all files os.system('pre-commit run --all-files')
pre-commit --version
Debug
Known issues
breakingEditable installs may break due to changes in `__editable__` and `__path_hook__` attributes.
fix
Use non-editable installations or adjust tooling to handle new attributes.
affects: >=4.0.0
gotchaEnsure that the `virtualenv` package is installed to create isolated environments for hooks.
fix
Install `virtualenv` using `pip install virtualenv`.
affects: All
breakingPre-commit hooks require Git to be installed on the system and the command must be run within a valid Git repository.
fix
Ensure Git is installed and configured on the system where pre-commit is run, and execute pre-commit commands from within a directory that is part of a Git repository.
affects: All
breakingpre-commit hooks require Git to be installed and the command to be run within a Git repository. Failure to meet these conditions results in a 'git failed' error.
fix
Ensure that Git is installed in the environment and that the 'pre-commit' command is executed inside a Git repository.
affects: All
Errors
Common errors & fixes
pre-commit: command not found
The `pre-commit` executable is not found in your system's PATH, often because it was installed in a virtual environment that is not currently active, or it was never installed globally or in the active environment.
fix
Activate your virtual environment (if using one) or ensure `pre-commit` is installed and its executable is discoverable. For Python virtual environments, use `source venv/bin/activate` (Linux/macOS) or `.\venv\Scripts\activate` (Windows) before running `pre-commit`. If not installed, run `pip install pre-commit`.
An unexpected error has occurred: InvalidConfigError: ==> File .pre-commit-config.yaml
The `.pre-commit-config.yaml` file contains syntax errors (e.g., incorrect indentation, invalid mapping values, or missing required keys) preventing `pre-commit` from parsing it correctly, or the file does not exist where expected.
fix
Carefully check your `.pre-commit-config.yaml` for YAML syntax errors, especially indentation. Ensure the file is named `.pre-commit-config.yaml` and is located at the root of your repository. Use a YAML linter or validator to identify specific issues. Example of a common error: `mapping values are not allowed in this context`.
fatal: cannot run .git/hooks/pre-commit: No such file or directory
The Git pre-commit hook script, which `pre-commit` installs, either does not exist at the expected path (`.git/hooks/pre-commit`), has incorrect file permissions, or is referencing a non-existent internal script (e.g., from a removed Node.js `pre-commit` package).
fix
Run `pre-commit install` to reinstall the Git hook script. Ensure the script at `.git/hooks/pre-commit` has executable permissions (`chmod +x .git/hooks/pre-commit`). If the error persists and you previously used a different hook system (like Node.js `pre-commit`), manually remove the old hook file from `.git/hooks/pre-commit`.
CalledProcessError: command: ('python', '-mpip', 'install', '.') return code: 1 expected return code: 0 stdout: Executable 'python' not found
A hook defined in your `.pre-commit-config.yaml` requires an executable (like `python`, `node`, etc.) that `pre-commit` cannot find in the isolated environment it sets up for that hook, or on the system's PATH.
fix
For Python hooks, ensure `default_language_version: python: python3` (or a specific version like `python3.X`) is set in your `.pre-commit-config.yaml`. For other languages, ensure the required tools are installed and accessible by `pre-commit`'s environment. For local hooks (`language: system`), verify the executable is in your system's PATH.
pre-commit: We've failed to pass the specified git pre-commit hooks as the <hook_id> hook returned an exit code (1).
One of your configured pre-commit hooks failed its checks (e.g., a linter found issues, a formatter detected unformatted code, or tests failed), causing it to exit with a non-zero status code.
fix
Review the output in your terminal to see which specific hook failed and the reasons for its failure. Correct the issues reported by the hook (e.g., fix linting errors, format the code, resolve test failures) and then attempt to commit again. If you temporarily need to bypass the hooks, use `git commit --no-verify` (not recommended for general use).
Upgrade
Version history
4.6.2latest on PyPI · released Aug 10, 2026
Audit
Dependencies
virtualenvrequiredRequired for creating isolated environments for hooks.
Agent activity
9 hits · last 30 days
node
8
Resources
pre-commit — pip install pre-commit · libregistry