Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions bandit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@

__author__ = metadata.metadata("bandit")["Author"]
__version__ = metadata.version("bandit")
# running bandit inside pre-commit we do not get a version here, workaround:
if __version__ == "0.0.0":
__version__ = "latest"
Comment on lines +21 to +23
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.