summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@yahoo-inc.com>2014-09-11 15:36:25 -0700
committerJoshua Harlow <harlowja@yahoo-inc.com>2014-09-17 17:56:45 -0700
commit3912dca0163488cc69301877df8bc7ea57ea2112 (patch)
tree2b3414900ed309ca7fcaa72f464472250bee02de
parentf2ec6f2550c12800bcc43c94ff9f709c43fc2272 (diff)
Allow a default_extension to be provided
When a file is found without an extension allow a CLI provided default_extension to be used in these cases so that files without extensions can be classified as known file extension types. Change-Id: I115ccc92ccd51a7018672b98b639ade30869f939
Notes
Notes (review): Verified+2: Jenkins Code-Review+2: Christian Berendt <berendt@b1-systems.de> Code-Review+2: Joshua Harlow <harlowja@yahoo-inc.com> Workflow+1: Joshua Harlow <harlowja@yahoo-inc.com> Submitted-by: Jenkins Submitted-at: Thu, 18 Sep 2014 17:43:07 +0000 Reviewed-on: https://review.openstack.org/120930 Project: stackforge/doc8 Branch: refs/heads/master
-rw-r--r--README.rst9
-rw-r--r--doc8/main.py14
-rw-r--r--doc8/parser.py10
3 files changed, 27 insertions, 6 deletions
diff --git a/README.rst b/README.rst
index b739b30..3df598e 100644
--- a/README.rst
+++ b/README.rst
@@ -27,8 +27,8 @@ Command line usage
27 $ doc8 -h 27 $ doc8 -h
28 28
29 usage: doc8 [-h] [--config path] [--allow-long-titles] [--ignore code] 29 usage: doc8 [-h] [--config path] [--allow-long-titles] [--ignore code]
30 [--no-sphinx] [--ignore-path path] [--max-line-length int] 30 [--no-sphinx] [--ignore-path path] [--default-extension extension]
31 [-e extension] [-v] 31 [--max-line-length int] [-e extension] [-v] [--version]
32 [path [path ...]] 32 [path [path ...]]
33 33
34 Check documentation for simple style requirements. 34 Check documentation for simple style requirements.
@@ -56,12 +56,16 @@ Command line usage
56 --no-sphinx do not ignore sphinx specific false positives 56 --no-sphinx do not ignore sphinx specific false positives
57 --ignore-path path ignore the given directory or file (globs are 57 --ignore-path path ignore the given directory or file (globs are
58 supported) 58 supported)
59 --default-extension extension
60 Default file extension to use when a file is found
61 without a file extension.
59 --max-line-length int 62 --max-line-length int
60 maximum allowed line length (default: 79) 63 maximum allowed line length (default: 79)
61 -e extension, --extension extension 64 -e extension, --extension extension
62 check file extensions of the given type (default: 65 check file extensions of the given type (default:
63 .rst, .txt) 66 .rst, .txt)
64 -v, --verbose run in verbose mode 67 -v, --verbose run in verbose mode
68 --version Show the version and exit.
65 69
66Ini file usage 70Ini file usage
67************** 71**************
@@ -101,6 +105,7 @@ of conflicts.
101Option Overrides Merges 105Option Overrides Merges
102===================== =========== ======== 106===================== =========== ========
103``allow-long-titles`` Yes No 107``allow-long-titles`` Yes No
108``default-extension`` Yes No
104``extension`` No Yes 109``extension`` No Yes
105``ignore-path`` No Yes 110``ignore-path`` No Yes
106``ignore`` No Yes 111``ignore`` No Yes
diff --git a/doc8/main.py b/doc8/main.py
index a029723..85228d8 100644
--- a/doc8/main.py
+++ b/doc8/main.py
@@ -110,6 +110,10 @@ def extract_config(args):
110 except (configparser.NoSectionError, configparser.NoOptionError): 110 except (configparser.NoSectionError, configparser.NoOptionError):
111 pass 111 pass
112 try: 112 try:
113 cfg['default_extension'] = parser.get("doc8", "default-extension")
114 except (configparser.NoSectionError, configparser.NoOptionError):
115 pass
116 try:
113 extensions = parser.get("doc8", "extensions") 117 extensions = parser.get("doc8", "extensions")
114 extensions = extensions.split(",") 118 extensions = extensions.split(",")
115 extensions = [s.strip() for s in extensions if s.strip()] 119 extensions = [s.strip() for s in extensions if s.strip()]
@@ -155,13 +159,16 @@ def scan(cfg):
155 files_ignored = 0 159 files_ignored = 0
156 file_iter = utils.find_files(cfg.get('paths', []), 160 file_iter = utils.find_files(cfg.get('paths', []),
157 cfg.get('extension', []), ignored_paths) 161 cfg.get('extension', []), ignored_paths)
162 default_extension = cfg.get('default_extension')
158 for filename, ignoreable in file_iter: 163 for filename, ignoreable in file_iter:
159 if ignoreable: 164 if ignoreable:
160 files_ignored += 1 165 files_ignored += 1
161 if cfg.get('verbose'): 166 if cfg.get('verbose'):
162 print(" Ignoring '%s'" % (filename)) 167 print(" Ignoring '%s'" % (filename))
163 else: 168 else:
164 files.append(file_parser.parse(filename)) 169 f = file_parser.parse(filename,
170 default_extension=default_extension)
171 files.append(f)
165 if cfg.get('verbose'): 172 if cfg.get('verbose'):
166 print(" Selecting '%s'" % (filename)) 173 print(" Selecting '%s'" % (filename))
167 return (files, files_ignored) 174 return (files, files_ignored)
@@ -263,6 +270,11 @@ def main():
263 parser.add_argument("--ignore-path", action="append", default=[], 270 parser.add_argument("--ignore-path", action="append", default=[],
264 help="Ignore the given directory or file (globs" 271 help="Ignore the given directory or file (globs"
265 " are supported).", metavar='path') 272 " are supported).", metavar='path')
273 parser.add_argument("--default-extension", action="store",
274 help="Default file extension to use when a file is"
275 " found without a file extension.",
276 default='', dest='default_extension',
277 metavar='extension')
266 parser.add_argument("--max-line-length", action="store", metavar="int", 278 parser.add_argument("--max-line-length", action="store", metavar="int",
267 type=int, 279 type=int,
268 help="Maximum allowed line" 280 help="Maximum allowed line"
diff --git a/doc8/parser.py b/doc8/parser.py
index 16d0304..2778af0 100644
--- a/doc8/parser.py
+++ b/doc8/parser.py
@@ -29,7 +29,7 @@ import six
29class ParsedFile(object): 29class ParsedFile(object):
30 FALLBACK_ENCODING = 'utf-8' 30 FALLBACK_ENCODING = 'utf-8'
31 31
32 def __init__(self, filename, encoding=None): 32 def __init__(self, filename, encoding=None, default_extension=''):
33 self._filename = filename 33 self._filename = filename
34 self._content = None 34 self._content = None
35 self._raw_content = None 35 self._raw_content = None
@@ -40,6 +40,8 @@ class ParsedFile(object):
40 self._has_read = False 40 self._has_read = False
41 self._extension = os.path.splitext(filename)[1] 41 self._extension = os.path.splitext(filename)[1]
42 self._read_lock = threading.Lock() 42 self._read_lock = threading.Lock()
43 if not self._extension:
44 self._extension = default_extension
43 45
44 @property 46 @property
45 def errors(self): 47 def errors(self):
@@ -129,7 +131,9 @@ class ParsedFile(object):
129 len(list(self.lines_iter()))) 131 len(list(self.lines_iter())))
130 132
131 133
132def parse(filename, encoding=None): 134def parse(filename, encoding=None, default_extension=''):
133 if not os.path.isfile(filename): 135 if not os.path.isfile(filename):
134 raise IOError(errno.ENOENT, 'File not found', filename) 136 raise IOError(errno.ENOENT, 'File not found', filename)
135 return ParsedFile(filename, encoding=encoding) 137 return ParsedFile(filename,
138 encoding=encoding,
139 default_extension=default_extension)