Make pre-commit run Bandit hook using a single process #1029
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I would like you to consider this small change to the pre-commit manifest.
Currently pre-commit may run Bandit hook with multiple processes, which can lead to Bandit generating multiple reports from these runs. It's only a bit confusing when you run Bandit for the first time on a moderately large database and output report on the screen, but it's much worse if you're saving your report to, let's say, an HTML file. Then you would get a straight wrong report.
This is what happens, when I run the same Bandit command with pre-commit and without it on the same codebase:
(pre-commit)
(w/o pre-commit)
Each run just overwrites the report file, and in the end we're left with what happens to be the latest run result.
One can mitigate this problem by using the
-r
flag and setting pre-commitpass_filenames
option tofalse
, but this doesn't suit everyone (or should be at least documented).