Skip to content

fixed bug no version detected in pre-commit installation #1283

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

daniel-mohr
Copy link
Contributor

cf. #1280

Unfortunately, metadata.version("bandit") does not return a meaningful version (returning the string "0.0.0") when bandit is installed and used via pre-commit.

This PR provides a workaround to ensure bandit functions correctly within the pre-commit environment.

pre-commit does not seem to provide the right environment for version detection. The use of 'latest' ensures compatibility, even if this is more of a workaround than a perfect solution.

Comment on lines +22 to +24
# running bandit inside pre-commit we do not get a version here, workaround:
if __version__ == "0.0.0":
__version__ = "latest"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems a bit hacky. I'd rather we get to the root cause on why the semver doesn't get into pre-commit.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. This seems like a bug where this is hiding that bug rather than fixing it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My guess is this is a pbr problem. If we switched to a more modern build-system we might not have this bug at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is a workaround.

After init_repo follows pre-commit clone_strategy and does something like this:

p="$(mktemp -d --tmpdir "$HOME"/.cache/pre-commit/)"
cd "$p"
git init .
git init
git remote add origin https://github.com/PyCQA/bandit
git fetch origin 1.8.5 --depth=1
git checkout FETCH_HEAD

And the repo has no version info. Neither the working tree nor the .git contains the version. Tags were not fetched.

I think a clean solution here would be to define the version in setup.cfg or setup.py -- or with more modern build systems that would probably be pyproject.toml or so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants