Using bump2version and pre-commit hooks
See original GitHub issueHi,
I have been using bump2version for a while. Thank you for maintaining it. Most recently, I added pre-commit hooks to my workflow. Now, my bumpversion commands are always failing since I think it interferes with the pre-commit hooks.
I am using bumpversion’s --no-commit
flag for now and then commit manually. Is there a way to make them both work together ?
Here’s my bumpversion config:
[bumpversion]
current_version = 1.0.0
commit = True
tag = True
And here’s my pre commit hook config:
repos:
- repo: git://github.com/pre-commit/pre-commit-hooks
rev: v1.4.0
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace
- id: check-case-conflict
- id: check-merge-conflict
- id: check-yaml
args: ['--unsafe']
- id: detect-private-key
- id: forbid-new-submodules
- id: check-json
- id: pretty-format-json
- id: check-added-large-files
- id: flake8
- repo: git://github.com/CuriousLearner/pre-commit-python-sorter
sha: 5294cde9d51cff119af537e987c30c320e9fbe2f
hooks:
- id: python-import-sorter
args: ['--silent-overwrite']
- repo: https://github.com/psf/black
rev: stable
hooks:
- id: black
Let me know if you need more information from me.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:9 (1 by maintainers)
Top Results From Across the Web
Supported hooks - pre-commit
reorder-python-imports - This hook reorders imports in python files. ... blacken-docs - Run `black` on python code blocks in documentation files ...
Read more >Developing — pyhf 0.5.4 documentation - Read the Docs
Then setup the Git pre-commit hook for Black by running. pre-commit install ... create a new release with bump2version and then deploy the...
Read more >Integrate Commitizen in python projects — Git commits syntax ...
In this article I would like to talk about a very good tool to manage some elements of python (not only) projects to...
Read more >bump2version vs pre-commit - compare differences and reviews ...
A framework for managing and maintaining multi-language pre-commit hooks. ... This is inspired in bump2version but with a much simpler approach.
Read more >Contributing to SoaM - GitLab
We use pre-commit to run several code scans and hooks like linters and formatters, ... You can use bump2version minor to increase the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Maybe some more info since I also have problems with pre-commit hooks and bumpversion.
More specifically my problem is connected to the
fix-trailing-whitespace
hook. I configure bumpversion insetup.cfg
in a python project. This means there are other sections, sometimes containing lines like these:Bumpversion seems to add whitespace after
exclude =
which thefix-trailing-whitespace
doesn’t like. This causes an error since the pre-commit hooks obviously fail (bumpversion adds whitespace, hooks remove whitespace)Maybe the original author has similar problems.
Edit: The version I am using is
bumpversion: v1.0.0 (using Python v3.6.9)
Another workaround is to exclude
setup.cfg
from the hook in your.pre-commit.config.yaml
file:But yeah, this isn’t ideal, and it would be nice if bumpversion didn’t modify any lines it doesn’t need to. Even without the hook, if I edit
setup.cfg
manually my editor is currently configured to trim trailing whitespace, so that means the diff on a commit where I’m editingsetup.cfg
is a bit noisier because of the extra whitespace. What’s worse is if I trim the whitespace manually, the next time bumpversion processes the file it’ll put the spaces back which adds diff noise to the bumpversion commit.