From 5fb44c1213cd7a11bdb1cf5b4144b6c6218a223c Mon Sep 17 00:00:00 2001 From: Christian Berendt Date: Wed, 13 Aug 2014 15:12:49 +0200 Subject: [PATCH] Add parameter --ignore-path to ignore files/directories If the path is a file the file will not be checked for style issues. If the path is a directory all files inside this directory or subdirectories will not be checked for style issues. Change-Id: Ic40f798fb65804844e545de72263c44a8a603a40 --- doc8/main.py | 8 +++++++- doc8/utils.py | 11 +++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/doc8/main.py b/doc8/main.py index 5486233..28dd41e 100644 --- a/doc8/main.py +++ b/doc8/main.py @@ -144,6 +144,8 @@ def main(): help="ignore the given errors code/codes", type=split_set_type, default=[]) + parser.add_argument("--ignore-path", action="append", default=[], + help="ignore the given directory or file") parser.add_argument("--max-line-length", action="store", metavar="int", type=int, help="maximum allowed line" @@ -164,8 +166,12 @@ def main(): args['extension'] = list(FILE_PATTERNS) files = collections.deque() + ignored_paths = [] + for path in args.pop('ignore_path', []): + ignored_paths.append(os.path.normpath(path)) for filename in utils.find_files(args.pop('paths', []), - args.pop('extension', [])): + args.pop('extension', []), + ignored_paths): files.append(file_parser.parse(filename)) ignoreables = frozenset(args.pop('ignore', [])) diff --git a/doc8/utils.py b/doc8/utils.py index 0a8587d..c508523 100644 --- a/doc8/utils.py +++ b/doc8/utils.py @@ -17,22 +17,29 @@ import os -def find_files(paths, extensions): +def find_files(paths, extensions, ignored_paths): extensions = set(extensions) def extension_matches(path): _base, ext = os.path.splitext(path) return ext in extensions + def path_ignored(path): + return os.path.normpath(path) in ignored_paths + for path in paths: + if path_ignored(path): + continue if os.path.isfile(path): if extension_matches(path): yield path elif os.path.isdir(path): for root, dirnames, filenames in os.walk(path): + if path_ignored(root): + continue for filename in filenames: path = os.path.join(root, filename) - if extension_matches(path): + if extension_matches(path) and not path_ignored(path): yield path else: raise IOError('Invalid path: %s' % path)