-
-
Notifications
You must be signed in to change notification settings - Fork 625
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
Bandit can't read config file when run in pre-commit #902
Comments
I was able to get part of the way there. - repo: https://github.com/PyCQA/bandit
rev: 1.7.4
hooks:
- id: bandit
args: ["-c", "pyproject.toml"] in my [tool.bandit]
exclude_dirs = ["tests"] but when I run pre-commit using: $ pre-commit run -a I get the following output: bandit...................................................................Failed
- hook id: bandit
- exit code: 2
[main] ERROR pyproject.toml : toml parser not available, reinstall with toml extra
[main] ERROR pyproject.toml : toml parser not available, reinstall with toml extra
I checked my venv and my standard python install (running on Ubuntu 20.04) and I get this: $ pip install toml
Requirement already satisfied: toml in <various-locations-tried>/site-packages (0.10.2) The problem is pre-commit is handling the installation of bandit by going to the git site and doing a pull. I cannot do |
@RNKuhns Sorted it! Make this your entry to - repo: https://github.com/PyCQA/bandit
rev: 1.7.4
hooks:
- id: bandit
args: ["-c", "pyproject.toml"]
additional_dependencies: [ "bandit[toml]" ] |
Awesome! Sorry for omitting the optional dependency part. But since I had switched to trying a different confit file type, i forgot to add it back. I had been just specifying to toml (and then tomli) in my additional dependencies as opposed to bandit[toml]. |
@matroscoe I confirmed this works. Maybe the bandit docs could be updated with the information? |
And what about the .bandit file? It cant read the configuration from that either inside .pre-commit-config.yaml It gives this error
for this .bandit file
|
@slidenerd afaik the |
For me this does not work unfortunately. 😕
Is there anything, I could be missing? E.g.
|
Describe the bug
When running bandit as a pre-commit hooks on pre-commit.ci or locally I am getting an error that says the Bandit hook can't read the pyproject.toml file. I've also tried this with other bandit config file approaches (bandit.yaml) and received the same error message.
Specifically, I'm getting an error message that says: [main] ERROR pyproject.toml : Could not read config file.
However, when I run bandit from the command line it appears to work (e.g. bandit . -r -c pyproject.toml).
Also note that I'll cross-post this on the pre-commit repository so they are aware too.
Reproduction steps
Expected behavior
Bandit should be able to find its configuration files within a pre-commit environment.
Ideally you would not need to tell Bandit where to look for the config file. Instead Bandit would just look in areas (from preferred files down to less preferred ones) like many linters do.
Bandit version
1.7.4 (Default)
Python version
3.9
Additional context
No response
The text was updated successfully, but these errors were encountered: