diff options
| author | Ian Stapleton Cordasco <graffatcolmingov@gmail.com> | 2018-10-26 15:05:06 -0500 |
|---|---|---|
| committer | Ian Stapleton Cordasco <graffatcolmingov@gmail.com> | 2018-10-27 08:01:14 -0500 |
| commit | e09a22a416b61f242feb90d8a536286713d0ab7e (patch) | |
| tree | 8b8cf3740141788547749902c0b2eb0c3bbc1c85 /src/flake8/utils.py | |
| parent | 1433a008b30cb97af2c28709daf763ae872c5bf9 (diff) | |
| download | flake8-e09a22a416b61f242feb90d8a536286713d0ab7e.tar.gz | |
Refactor to support the per-file-ignores
Most of the problems with our logic were due to not having the same
logic as our exclude parameter. This refactors that out into a separate
function so we can confidently achieve that.
Diffstat (limited to 'src/flake8/utils.py')
| -rw-r--r-- | src/flake8/utils.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/flake8/utils.py b/src/flake8/utils.py index e77998d..68627af 100644 --- a/src/flake8/utils.py +++ b/src/flake8/utils.py @@ -336,6 +336,38 @@ def parameters_for(plugin): return parameters +def matches_filename(path, patterns, log_message, logger): + """Use fnmatch to discern if a path exists in patterns. + + :param str path: + The path to the file under question + :param patterns: + The patterns to match the path against. + :type patterns: + list[str] + :param str log_message: + The message used for logging purposes. + :returns: + True if path matches patterns, False otherwise + :rtype: + bool + """ + if not patterns: + return False + basename = os.path.basename(path) + if fnmatch(basename, patterns): + logger.debug(log_message, {"path": basename, "whether": ""}) + return True + + absolute_path = os.path.abspath(path) + match = fnmatch(absolute_path, patterns) + logger.debug( + log_message, + {"path": absolute_path, "whether": "" if match else "not "}, + ) + return match + + def get_python_version(): """Find and format the python implementation and version. |
