pre-commit
pre-commit.com
pre-commit
Here's an example configuration with a few local hooks: - repo: local hooks: - id: pylint name: pylint entry: pylint language: unsupported types: [python] require_serial: true - id: check-x name: Check X entry: ./bin/check-x.sh language: unsupported_script files: \.x$ - id: scss-lint name: scss-lint entry: scss-lint language: ruby language_version: 2.1.5 types: [scss] additional_dependencies: ['scss_lint:0.52.0']
How to run a local python file
Hi, I am sorry if this is obvious but I am trying to run a simple python file for our project using pre-commit. Essentially I want a git prehook to create a csv file every time it gets committed. S... More on github.com
What are your favourite pre-commit hooks and why?
You may fancy me mad, but this is my standard python pre-commit stack: end-of-file-fixer trailing-whitespace fix-byte-order-marker mixed-line-ending name-tests-test no-commit-to-branch autoflake args: [ "--in-place", "--remove-unused-variables", "--remove-all-unused-imports" ] isort black cspell doc8 args: [ "--max-line-length", "112", "--file-encoding", "utf-8" ] flake8 additional_dependencies: [ flake8-pytest-style, flake8-bugbear, flake8-comprehensions, flake8-print, darglint ] bandit pylint More on reddit.com
pre commit.com - Should I install `pre-commit` into a python virtual environment or python global environment? - Stack Overflow
When I have a new python package ... with python -m venv .venv. I activate the venv using .venv\Scripts\activate. When working on the package I install package dependencies such as numpy with (.venv) C:\...\my_package> pip install numpy. I am trying to figure out how I should install the pre-commit package so ... More on stackoverflow.com
Using pre-commit hooks makes software development life easier
I find pre-commits very useful for the reason you mentioned in your other reply: failing fast (or shift left) philosophies. If there is a linting issue, it should be spotted before any CI is triggered. I use pre-commit when working with python with black (auto format), isort (for import sorting), flake8 (linting), and sometimes mypy for type checking. I disagree with the other comment about having save hooks on the ide because I save on every line change even if the change at that point would break everything. So it wouldn't make sense to perform any of the checks I perform with the pre-commit at that point. It's just a useful tool to use, it means CI runners aren't wasting time or compute resources failing jobs for things that could have been spotted before the commit was pushed. Yeah you can bypass, but that's why I will have the lint checks on the CI job too, it just means these checks are less likely to fail. More on reddit.com
Videos
04:45
Boost Your Python Code Quality: Pre-commit Tutorial (UV & Ruff) ...
12:23
Pre-Commit: Enforce coding best-practices - YouTube
04:52
How to Run a Python Script Upon Commit Using a Pre-Commit Hook ...
08:36
1. Pre-commit Hooks for Python Projects. - YouTube
29:19
Pre Commit Hooks EXPLAINED | Easy Way Clean Repo! GitHub & PyCharm ...
01:10:03
Pre-commit Hooks for Python Devs - Talk Python to Me Ep.482 - YouTube
PyPI
pypi.org › project › pre-commit
pre-commit · PyPI
» pip install pre-commit
DEV Community
dev.to › techishdeep › maximize-your-python-efficiency-with-pre-commit-a-complete-but-concise-guide-39a5
The Power of Pre-Commit for Python Developers: Tips and Best Practices - DEV Community
May 1, 2023 - We have already seen an example of how to write a pre-commit hook configuration. Now, let's delve deeper into it. Firstly, let's take another look at the sample configuration. repos: - repo: https://github.com/PyCQA/flake8 rev: 3.9.2 hooks: - id: flake8 name: flake8 types: [python] args: - --max-line-length=88 - --ignore=E203,E501,W503
GitHub
github.com › pre-commit › pre-commit
GitHub - pre-commit/pre-commit: A framework for managing and maintaining multi-language pre-commit hooks. · GitHub
Starred by 15.2K users
Forked by 961 users
Languages Python 97.4% | R 2.0% | Shell 0.5% | Dockerfile 0.1% | Lua 0.0% | Ruby 0.0%
GitHub
github.com › pre-commit › pre-commit › issues › 1245
How to run a local python file · Issue #1245 · pre-commit/pre-commit
December 18, 2019 - Hi, I am sorry if this is obvious but I am trying to run a simple python file for our project using pre-commit. Essentially I want a git prehook to create a csv file every time it gets committed. So this prehook has nothing to do with th...
Author drummerboy2543
Reddit
reddit.com › r/python › what are your favourite pre-commit hooks and why?
r/Python on Reddit: What are your favourite pre-commit hooks and why?
April 24, 2024 -
Just getting started with pre-commit and I think it's awesome. Looking to find out what other code automation tools people are using. Let me know what works for you and why. Thanks!
Top answer 1 of 24
65
black Particularly useful on projects with multiple collaborators because everyone’s code will be formatted identically.
2 of 24
53
You may fancy me mad, but this is my standard python pre-commit stack: end-of-file-fixer trailing-whitespace fix-byte-order-marker mixed-line-ending name-tests-test no-commit-to-branch autoflake args: [ "--in-place", "--remove-unused-variables", "--remove-all-unused-imports" ] isort black cspell doc8 args: [ "--max-line-length", "112", "--file-encoding", "utf-8" ] flake8 additional_dependencies: [ flake8-pytest-style, flake8-bugbear, flake8-comprehensions, flake8-print, darglint ] bandit pylint
Poetry
python-poetry.org › docs › pre-commit-hooks
pre-commit hooks | Documentation | Poetry - Python dependency management and packaging made easy
A .pre-commit-config.yaml example for a monorepo setup or if the pyproject.toml file is not in the root directory:
Towards Data Science
towardsdatascience.com › home › latest › custom pre-commit hooks for safer code changes
Custom pre-commit hooks for safer code changes | Towards Data Science
January 22, 2025 - The preferred way of working with pre-commit hooks is through the pre-commit Python library. We can set it up with the following steps: Create a git repository for your project with git init · Install the pre-commit library with pip install pre-commit · Add a .pre-commit-config.yaml to your repository. Here’s an example:
Talk Python To Me
talkpython.fm › episodes › show › 482 › pre-commit-hooks-for-python-devs
Episode #482 - Pre-commit Hooks for Python Devs | Talk Python To Me Podcast
October 24, 2024 - Stefanie’s focus on automated code quality checks led her to develop and share various pre-commit hooks, including a specialized one for NumPy docstrings and another for stripping EXIF metadata from images. Check out our course Up and Running with Git: While you don’t need deep Python expertise to use pre-commit hooks, having basic Git and Python knowledge will help you configure them effectively.
Gitlab
gdevops.gitlab.io › tuto_git › tools › pre-commit › pre-commit.html
pre-commit : a Python framework for managing and ...
March 2, 2023 - This User ID will be used as a unique identifier while storing and accessing your preferences for future.
Stefanie Molin
stefaniemolin.com › articles › devx › pre-commit › setup-guide
How to Set Up Pre-Commit Hooks | Stefanie Molin
December 7, 2025 - The pre-commit hooks that we will use in this tutorial run checks on configuration files (like YAML and TOML) and Python files. To make it easier to follow along, I have created a small GitHub template repository at stefmolin/pre-commit-example with a Python package skeleton for a dummy package called example, but you can also use a Python project of your own.
GitHooks
githooks.com
Learn how to improve your Git skills
git-pre-commit-hook - Hook that blocks bad commits. Useful for Python-development.
Python for Data Science
python4data.science › en › latest › productive › git › advanced › hooks › ci.html
pre-commit in CI pipelines - Python for Data Science
March 2, 2025 - Alternative configuration as a GitHub workflow, for example: name: pre-commit on: pull_request: push: branches: [main] jobs: pre-commit: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 - uses: actions/cache@v4 with: path: ~/.cache/pre-commit key: pre-commit|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }} - uses: pre-commit/action@v3.0.1 ·