diff options
| author | Ian Stapleton Cordasco <graffatcolmingov@gmail.com> | 2018-10-29 15:37:11 +0000 |
|---|---|---|
| committer | Ian Stapleton Cordasco <graffatcolmingov@gmail.com> | 2018-10-29 15:37:11 +0000 |
| commit | 4439ea202526b50154d287f3e581222a4c86d782 (patch) | |
| tree | dc0f8312d2dce3a276822947c9391a64ae7e9c8a /src/flake8/utils.py | |
| parent | 732a466ee8eec06d195ec70081e53ec187b5b114 (diff) | |
| parent | 6ae2295bfeea68c11a7d13282a9bfde1a553449b (diff) | |
| download | flake8-4439ea202526b50154d287f3e581222a4c86d782.tar.gz | |
Merge branch 'per-file-style-guide' into 'master'
Add support for per-file ignores in config
Closes #156
See merge request pycqa/flake8!259
Diffstat (limited to 'src/flake8/utils.py')
| -rw-r--r-- | src/flake8/utils.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/flake8/utils.py b/src/flake8/utils.py index a837577..68627af 100644 --- a/src/flake8/utils.py +++ b/src/flake8/utils.py @@ -11,6 +11,7 @@ import tokenize DIFF_HUNK_REGEXP = re.compile(r"^@@ -\d+(?:,\d+)? \+(\d+)(?:,(\d+))? @@.*$") COMMA_SEPARATED_LIST_RE = re.compile(r"[,\s]") +NEWLINE_SEPARATED_LIST_RE = re.compile(r"[\s]") LOCAL_PLUGIN_LIST_RE = re.compile(r"[,\t\n\r\f\v]") @@ -335,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. |
