question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using bump2version and pre-commit hooks

See original GitHub issue

Hi,

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:open
  • Created 4 years ago
  • Reactions:2
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

10reactions
cbowscommented, Feb 21, 2020

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 in setup.cfg in a python project. This means there are other sections, sometimes containing lines like these:

[flake8]
exclude =
	.git
	__pycache__

Bumpversion seems to add whitespace after exclude = which the fix-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)

3reactions
pzelnipcommented, Nov 1, 2021

Another workaround is to exclude setup.cfg from the hook in your .pre-commit.config.yaml file:

-   repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v4.0.1
    hooks:
      - id: trailing-whitespace
        exclude: setup.cfg

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 editing setup.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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found