Usage needlessly complicated
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 8.3k
- Forks
- 836
- Avg merge
- 5d 3h
- Merged PRs (30d)
- 1
Description
Is your feature request related to a problem? Please describe.
When setting up Bandit the usage is needlessly complicated. This is made even worse when I want to use things like pre-commit or otherwise get colleagues to use the same tools, as the configuration files are a mess.
-
There is no example that I can find for the
-cconfig file. I tried to use the only format documented, the INI format, and it complained about some document start not being found, which sounds like it expects XML. I see no examples of XML configuration. -
The INI format config is supposed to be loaded by default from
.bandit, it's not. I need to add--ini .banditor I get the completely false error messageNo targets found in CLI or ini files, exiting... considering it sayspath to a .bandit file that supplies command line arguments, AND the error claims to "not find" ini files, this should clearly be loaded by default. -
The INI format configuration is not well documented, just some handwavy "comma separated list of blah" instead of showing actual examples for most of the usage, and it fails to specify that it does not support comments at the end of lines.
E.g. this causes an error:
[bandit]
skips: B101 # Assertion used
- The INI format configuration does not support proper glob expressions nor does it support the
-rargument, causing really stupid looking configuration and significant astonishment at the difficulties to get it to work.
This causes an error
[bandit]
targets: **/*.py
Files skipped (1):
**/*.py (Invalid argument)
This does nothing:
[bandit]
exclude: **/tests
This also fails to work, because directories cannot be excluded:
[bandit]
exclude: tests,*/tests,*/*/tests,*/*/*/tests,... for as many levels as you guess your app will need
This also fails because the spaces are not trimmed around the ,
[bandit]
exclude: tests/*, */tests/*, */*/tests/*, */*/*/tests/*, ... for as many levels as you guess your app will need
This seems to work though, if your code is e.g. in app directory and IF used with bandit --ini .bandit -r:
[bandit]
include: app
exclude: app/tests/*,app/*/tests/*,app/*/*/tests/*,app/*/*/*/tests/*,... for as many levels as you guess your app will need
- Configuration is not handled well when used with other tools. I want to automatically run this with
pre-commit, but Bandit ignores theexcludefrom the INI file even with the explicitly set--ini .banditarg, I imagine becausepre-commitgives it a list of files as arguments, so I have to re-do the exclude in.pre-commit-config.yaml.
- repo: https://github.com/PyCQA/bandit
rev: 'master'
hooks:
- id: bandit
args: ['--ini', '.bandit', '-r']
exclude: >
(?x)^(
.*/tests/.*
)$
You should be able to tell by now why this just feels wrong on so many levels and is at the very least needlessly complicated.
Describe the solution you'd like
bandit . -rshould be the default operation, with something like--no-recurseto override the recursion.banditconfiguration (and I really hope soonpyproject.tomlconfiguration) should be read automatically-cconfiguration example file should be in the repo's README, and the--inishould be properly documented as well.banditand other configuration should be respected regardless of ifbanditgets a list of filenames as arguments or not, though of course it should be possible to override configuration when necessary .. the expectation is thattargets: appwith-randapp/file.pyas argument have the same effect with the same configuration.banditand other configuration formats should be fully capable of making the tool run properly by default without requiring constant manual edits, i.e. they should support the recursion (if1.is implemented less important), and they should support proper globs both fortargetsandexclude- Configuration parsing should support common usage, such as spaces around separators, and comments at end of lines
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the README's configuration and usage documentation, then inspect the .bandit and .pre-commit-config.yaml examples described in the issue. Compare current --ini, -c, and -r behavior with the six requested changes, including automatic configuration loading, recursive targets, glob exclusions, and common INI syntax. Done means the documented configuration works consistently for direct and pre-commit file arguments.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- cli, tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100