summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2014-10-23 19:35:54 +0000
committerGerrit Code Review <review@openstack.org>2014-10-23 19:35:54 +0000
commit00a13a3239fd6102774870c8d32ed005d3d46b82 (patch)
tree72f221d8d4259d2d73cba5bfddf3d45a240f4f8a
parent5a4341727ef0440f5c1575263a38e6b44a7dedea (diff)
parent04a710c687a7cb2da2b2a6bbd86c20aa32d1dc60 (diff)
Merge "Allow overriding file encoding"
-rw-r--r--README.rst5
-rw-r--r--doc8/main.py15
-rw-r--r--doc8/tests/test_checks.py16
3 files changed, 35 insertions, 1 deletions
diff --git a/README.rst b/README.rst
index 8b71665..c34d10a 100644
--- a/README.rst
+++ b/README.rst
@@ -60,6 +60,10 @@ Command line usage
60 --default-extension extension 60 --default-extension extension
61 Default file extension to use when a file is found 61 Default file extension to use when a file is found
62 without a file extension. 62 without a file extension.
63 --file-encoding encoding
64 Override encoding to use when attempting to determine
65 an input files text encoding (providing this avoids
66 using `chardet` to automatically detect encoding/s)
63 --max-line-length int 67 --max-line-length int
64 maximum allowed line length (default: 79) 68 maximum allowed line length (default: 79)
65 -e extension, --extension extension 69 -e extension, --extension extension
@@ -111,6 +115,7 @@ Option Overrides Merges
111``ignore-path`` No Yes 115``ignore-path`` No Yes
112``ignore`` No Yes 116``ignore`` No Yes
113``max-line-length`` Yes No 117``max-line-length`` Yes No
118``file-encoding`` Yes No
114``sphinx`` Yes No 119``sphinx`` Yes No
115===================== =========== ======== 120===================== =========== ========
116 121
diff --git a/doc8/main.py b/doc8/main.py
index 7de933a..4c35b02 100644
--- a/doc8/main.py
+++ b/doc8/main.py
@@ -111,6 +111,10 @@ def extract_config(args):
111 except (configparser.NoSectionError, configparser.NoOptionError): 111 except (configparser.NoSectionError, configparser.NoOptionError):
112 pass 112 pass
113 try: 113 try:
114 cfg['file_encoding'] = parser.get("doc8", "file-encoding")
115 except (configparser.NoSectionError, configparser.NoOptionError):
116 pass
117 try:
114 cfg['default_extension'] = parser.get("doc8", "default-extension") 118 cfg['default_extension'] = parser.get("doc8", "default-extension")
115 except (configparser.NoSectionError, configparser.NoOptionError): 119 except (configparser.NoSectionError, configparser.NoOptionError):
116 pass 120 pass
@@ -162,6 +166,7 @@ def scan(cfg):
162 file_iter = utils.find_files(cfg.get('paths', []), 166 file_iter = utils.find_files(cfg.get('paths', []),
163 cfg.get('extension', []), ignored_paths) 167 cfg.get('extension', []), ignored_paths)
164 default_extension = cfg.get('default_extension') 168 default_extension = cfg.get('default_extension')
169 file_encoding = cfg.get('file_encoding')
165 for filename, ignoreable in file_iter: 170 for filename, ignoreable in file_iter:
166 if ignoreable: 171 if ignoreable:
167 files_ignored += 1 172 files_ignored += 1
@@ -169,7 +174,8 @@ def scan(cfg):
169 print(" Ignoring '%s'" % (filename)) 174 print(" Ignoring '%s'" % (filename))
170 else: 175 else:
171 f = file_parser.parse(filename, 176 f = file_parser.parse(filename,
172 default_extension=default_extension) 177 default_extension=default_extension,
178 encoding=file_encoding)
173 files.append(f) 179 files.append(f)
174 if cfg.get('verbose'): 180 if cfg.get('verbose'):
175 print(" Selecting '%s'" % (filename)) 181 print(" Selecting '%s'" % (filename))
@@ -277,6 +283,13 @@ def main():
277 " found without a file extension.", 283 " found without a file extension.",
278 default='', dest='default_extension', 284 default='', dest='default_extension',
279 metavar='extension') 285 metavar='extension')
286 parser.add_argument("--file-encoding", action="store",
287 help="Override encoding to use when attempting"
288 " to determine an input files text encoding "
289 "(providing this avoids using `chardet` to"
290 " automatically detect encoding/s)",
291 default='', dest='file_encoding',
292 metavar='encoding')
280 parser.add_argument("--max-line-length", action="store", metavar="int", 293 parser.add_argument("--max-line-length", action="store", metavar="int",
281 type=int, 294 type=int,
282 help="Maximum allowed line" 295 help="Maximum allowed line"
diff --git a/doc8/tests/test_checks.py b/doc8/tests/test_checks.py
index 0a88794..1e0171b 100644
--- a/doc8/tests/test_checks.py
+++ b/doc8/tests/test_checks.py
@@ -89,6 +89,22 @@ test
89 (line, code, msg) = errors[0] 89 (line, code, msg) = errors[0]
90 self.assertIn(code, check.REPORTS) 90 self.assertIn(code, check.REPORTS)
91 91
92 def test_correct_length(self):
93 conf = {
94 'max_line_length': 79,
95 'allow_long_titles': True,
96 }
97 with tempfile.NamedTemporaryFile(suffix='.rst') as fh:
98 fh.write(b'known exploit in the wild, for example'
99 ' \xe2\x80\x93 the time'
100 ' between advance notification')
101 fh.flush()
102
103 parsed_file = parser.ParsedFile(fh.name, encoding='utf-8')
104 check = checks.CheckMaxLineLength(conf)
105 errors = list(check.report_iter(parsed_file))
106 self.assertEqual(0, len(errors))
107
92 def test_unsplittable_length(self): 108 def test_unsplittable_length(self):
93 content = """ 109 content = """
94=== 110===