Prek is a Rust-based reimplementation of the `pre-commit` framework, designed to manage Git hooks with dramatically improved performance and efficiency. It offers a faster, dependency-free alternative that is largely compatible with existing `.pre-commit-config.yaml` files, while also introducing new features like `prek.toml` configuration and built-in monorepo support. The project maintains an active development pace with frequent releases.
pip install prekNo compatibility data collected yet for this library.
This quickstart demonstrates how to install prek, generate a default configuration, set up the Git hooks, and trigger them with a commit. Prek will automatically use `.pre-commit-config.yaml` (or `prek.toml`) and manage hook environments.
Consider using `prek.toml` for new projects or converting existing `.pre-commit-config.yaml` files with `prek util yaml-to-toml`.
Review `files` and `exclude` patterns. Leverage the `glob` mapping for simpler glob-based filtering where appropriate, or ensure existing regex patterns are still valid and correctly escaped.
Check the `prek` documentation's 'Language Support' section for specific language compatibility before migrating projects with diverse hook languages. Report any missing support to the project.
Regularly run `prek cache gc` to manage disk space and remove stale cached resources.
When invoking external commands like `prek sample-config` from a Python script, ensure they are executed through `subprocess.run()` (e.g., `subprocess.run(['prek', 'sample-config'], stdout=open('.pre-commit-config.yaml', 'w'))`) or `os.system()` (e.g., `os.system('prek sample-config > .pre-commit-config.yaml')`).Ensure `prek` commands are executed in a shell (e.g., a `.sh` script) or through Python's `subprocess` module (e.g., `subprocess.run(['prek', 'sample-config'], stdout=open('.pre-commit-config.yaml', 'w'))`) when integrating into Python scripts.Ensure that every repository entry in your `.pre-commit-config.yaml` file includes a `rev` field specifying a valid Git revision (e.g., a tag, branch name, or commit hash). Example: `repos: - repo: https://github.com/pre-commit/pre-commit-hooks hooks: [{ id: trailing-whitespace }] rev: v4.5.0`.Ensure `prek` is correctly installed via your chosen method (e.g., `pip install prek`, `brew install prek`, `cargo install prek`, or a standalone installer) and verify that its installation directory (e.g., `~/.cargo/bin` for Cargo, or the Python environment's bin directory for `pip`) is included in your system's PATH. Restart your terminal after installation to refresh the PATH.
Identify which `prek` executable is being called (e.g., by checking `which prek` or the specific Python environment path) and ensure it is updated to the required version using its respective package manager (e.g., `pip install --upgrade prek` in the correct virtual environment, or `brew upgrade prek`). Verify the version with `prek --version` in the problematic environment.
First, ensure hooks are installed by running `prek install`. Verify that the `.pre-commit-config.yaml` or `prek.toml` configuration file is present and valid. Check the permissions of the hook files in your `.git/hooks/` directory, ensuring they are executable (e.g., `chmod +x .git/hooks/pre-commit`). If issues persist, try reinstalling hooks with `prek install --overwrite` or checking specific hook configurations within your config file.