pants: Bandit plugin used by flake8 can't read the config from the bandit's config
Describe the bug
flake8-bandit isn’t able to read the config used by bandit itself. I suppose this is just not about this particular plugin but any such plugin which flake8 uses.
Pants version 2.10.0
OS macOS
Additional info https://pantsbuild.slack.com/archives/C046T6T9U/p1650639627749519
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 16 (16 by maintainers)
Commits related to this issue
- Add `[flake8].extra_files` to allow configuring plugins like Bandit (#16470) Adds a new option for passing config files used by`flake8` plugin. Fixes https://github.com/pantsbuild/pants/issues/152... — committed to pantsbuild/pants by ShantanuKumar 2 years ago
- Add `[flake8].extra_files` to allow configuring plugins like Bandit (#16470) Adds a new option for passing config files used by`flake8` plugin. Fixes https://github.com/pantsbuild/pants/issues/152... — committed to cczona/pants by ShantanuKumar 2 years ago
Yeah but I feel like based on different plugins, this can be quite varied. E.g. if it’sflake8-bandit, the glob could be[".bandit"]. If it’sflake8-pydocstyle, it could be[".pydocstyle"]. I don’t see a clear glob pattern here.EDIT: Sorry, I understand now you mean
flake8_subsystem.extra_filesHey @ShantanuKumar sorry for the delay! Was moving apartments and OOO.
extra_filestobandit/subsystem.py, which will beadvanced=Trueand typeFileListOptionGet(Digest, PathGlobs())here for theextra_files. Error if the globs are not matched, similar to second snippet. Include the digest in theMergeDigestshttps://github.com/pantsbuild/pants/blob/40e17902092a9b7414473f99bf32e3f3c84e5921/src/python/pants/backend/python/lint/bandit/rules.py#L52-L68
https://github.com/pantsbuild/pants/blob/40e17902092a9b7414473f99bf32e3f3c84e5921/src/python/pants/core/util_rules/config_files.py#L64-L71
I think we likely want to add a test to
bandit/rules_integration_test.py, although tests do have a downside with slower CI and more code, so it’s a tradeoff. I wonder if you can modify a current test liketest_3rdparty_pluginto test both things in the same test. Otherwise, a dedicated test is probably worth it.Cool. So then in your case, this would look like:
or
That second one is much clearer in my opinion. And maybe we make this even more generic? That option tells pants to find that file on your local file system and include it in the sandbox.
Wdyt?
They say that using
.banditshould work. This is how my.banditlooks like