Skip to content
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

Interpret wildcards in the file exclusion list #450

Merged
merged 5 commits into from Apr 12, 2019
Merged

Interpret wildcards in the file exclusion list #450

merged 5 commits into from Apr 12, 2019

Conversation

thilp
Copy link
Contributor

@thilp thilp commented Feb 6, 2019

Fix #345.

Hello,

This PR changes _is_file_included so that it also uses fnmatch on the excluded_path_strings argument, allowing that list to contain wildcards.

Rationale:

My projects use Codacy, which in turn relies on Bandit. However, they also have test files mixed with source files, the only difference being that their name is prefixed with test_. The result is that Bandit (and therefore Codacy) is unusable on these projects, because they report hundreds of irrelevant “Use of assert detected”. I figured it would be easier (and safer) to add this feature than deactivate Bandit altogether.

I'm very new to the project so I may have made errors. Please point them out! I would really like to see this feature integrated soon in this nice tool.

Copy link
Member

@ericwb ericwb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also update the README which states:

-x EXCLUDED_PATHS, --exclude EXCLUDED_PATHS
                        comma-separated list of paths to exclude from scan
                        (note that these are in addition to the excluded paths
                        provided in the config file)
exclude_dirs - sections of the path, that if matched, will be excluded from scanning
exclude: comma separated list of excluded paths

And also the man page for the CLI.

thilp and others added 5 commits March 4, 2019 11:07
This allows to specify wildcards in the excluded files list, which in
turns makes it possible to use Bandit in projects where test files are
not in a separate repository, but have just a name prefixed with test_
(as is common with Pytest).
@thilp
Copy link
Contributor Author

thilp commented Apr 8, 2019

@ericwb Thanks, what do you think about it now?

Copy link
Member

@ericwb ericwb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ericwb ericwb merged commit fb18e17 into PyCQA:master Apr 12, 2019
@eterna2
Copy link

eterna2 commented Apr 16, 2019

@ericwb Are u planning a release soon? Cuz I need this feature quite badly as my tests are in the same folders as my sources.

@azrdev
Copy link

azrdev commented Nov 10, 2020

@thilp when using --recursive the whole path is fnmatched against the glob_list, therefore an --exclude_dir expression test_*.py doesn't matches and excludes (py)test files in subdirectories, for that */test_*.py is needed.

I find this rather unintuitive, was it intended?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Exclude file pattern in config file
4 participants