35
35
import os
36
36
import sys
37
37
38
-
39
38
try :
40
39
# py3.11+
41
40
from tomllib import load as toml_load # type: ignore
45
44
46
45
from stevedore import extension
47
46
48
- from doc8 import checks
47
+ from doc8 import checks , utils , version
49
48
from doc8 import parser as file_parser
50
- from doc8 import utils
51
- from doc8 import version
52
49
53
50
FILE_PATTERNS = [".rst" , ".txt" ]
54
51
MAX_LINE_LENGTH = 79
@@ -158,7 +155,8 @@ def extract_config(args):
158
155
if not os .path .isfile (cfg_file ):
159
156
if args ["config" ]:
160
157
print (
161
- "Configuration file %s does not exist...ignoring" % (args ["config" ])
158
+ "Configuration file %s does not exist...ignoring"
159
+ % (args ["config" ]),
162
160
)
163
161
continue
164
162
if cfg_file .endswith ((".ini" , ".cfg" )):
@@ -180,7 +178,9 @@ def fetch_checks(cfg):
180
178
checks .CheckNewlineEndOfFile (cfg ),
181
179
]
182
180
mgr = extension .ExtensionManager (
183
- namespace = "doc8.extension.check" , invoke_on_load = True , invoke_args = (cfg .copy (),)
181
+ namespace = "doc8.extension.check" ,
182
+ invoke_on_load = True ,
183
+ invoke_args = (cfg .copy (),),
184
184
)
185
185
addons = []
186
186
for e in mgr :
@@ -194,7 +194,9 @@ def setup_logging(verbose):
194
194
else :
195
195
level = logging .ERROR
196
196
logging .basicConfig (
197
- level = level , format = "%(levelname)s: %(message)s" , stream = sys .stdout
197
+ level = level ,
198
+ format = "%(levelname)s: %(message)s" ,
199
+ stream = sys .stdout ,
198
200
)
199
201
200
202
@@ -205,7 +207,9 @@ def scan(cfg):
205
207
ignored_paths = cfg .get ("ignore_path" , [])
206
208
files_ignored = 0
207
209
file_iter = utils .find_files (
208
- cfg .get ("paths" , []), cfg .get ("extension" , []), ignored_paths
210
+ cfg .get ("paths" , []),
211
+ cfg .get ("extension" , []),
212
+ ignored_paths ,
209
213
)
210
214
default_extension = cfg .get ("default_extension" )
211
215
file_encoding = cfg .get ("file_encoding" )
@@ -216,7 +220,9 @@ def scan(cfg):
216
220
print (" Ignoring '%s'" % (filename ))
217
221
else :
218
222
f = file_parser .parse (
219
- filename , default_extension = default_extension , encoding = file_encoding
223
+ filename ,
224
+ default_extension = default_extension ,
225
+ encoding = file_encoding ,
220
226
)
221
227
files .append (f )
222
228
if cfg .get ("verbose" ):
@@ -253,7 +259,7 @@ def validate(cfg, files, result=None):
253
259
print (
254
260
" Skipping check '%s' since it does not"
255
261
" understand parsing a file with extension '%s'"
256
- % (check_name , f .extension )
262
+ % (check_name , f .extension ),
257
263
)
258
264
continue
259
265
try :
@@ -266,7 +272,7 @@ def validate(cfg, files, result=None):
266
272
if cfg .get ("verbose" ):
267
273
print (
268
274
" Skipping check '%s', determined to only"
269
- " check ignoreable codes" % check_name
275
+ " check ignoreable codes" % check_name ,
270
276
)
271
277
continue
272
278
if cfg .get ("verbose" ):
@@ -279,13 +285,11 @@ def validate(cfg, files, result=None):
279
285
line_num = "?"
280
286
if cfg .get ("verbose" ):
281
287
print (
282
- " - {}:{}: {} {}" .format (
283
- f .filename , line_num , code , message
284
- )
288
+ f" - { f .filename } :{ line_num } : { code } { message } " ,
285
289
)
286
290
elif not result .capture :
287
291
print (
288
- "{ }:{}: {} {}" . format ( f . filename , line_num , code , message )
292
+ f" { f . filename } :{ line_num } : { code } { message } " ,
289
293
)
290
294
result .error (check_name , f .filename , line_num , code , message )
291
295
error_counts [check_name ] += 1
@@ -297,18 +301,16 @@ def validate(cfg, files, result=None):
297
301
if cfg .get ("verbose" ):
298
302
print (
299
303
" - %s:%s: %s %s"
300
- % (f .filename , line_num , code , message )
304
+ % (f .filename , line_num , code , message ),
301
305
)
302
306
elif not result .capture :
303
307
print (
304
- "{}:{}: {} {}" .format (
305
- f .filename , line_num , code , message
306
- )
308
+ f"{ f .filename } :{ line_num } : { code } { message } " ,
307
309
)
308
310
result .error (check_name , f .filename , line_num , code , message )
309
311
error_counts [check_name ] += 1
310
312
else :
311
- raise TypeError ("Unknown check type: {}, {}" . format ( type (c ), c ) )
313
+ raise TypeError (f "Unknown check type: { type (c )} , { c } " )
312
314
return error_counts
313
315
314
316
@@ -358,20 +360,18 @@ def report(self):
358
360
for error in self .errors :
359
361
lines .append ("%s:%s: %s %s" % error [1 :])
360
362
361
- lines .extend (
362
- [
363
- "=" * 8 ,
364
- "Total files scanned = %s" % (self .files_selected ),
365
- "Total files ignored = %s" % (self .files_ignored ),
366
- "Total accumulated errors = %s" % (self .total_errors ),
367
- ]
368
- )
363
+ lines .extend ([
364
+ "=" * 8 ,
365
+ "Total files scanned = %s" % (self .files_selected ),
366
+ "Total files ignored = %s" % (self .files_ignored ),
367
+ "Total accumulated errors = %s" % (self .total_errors ),
368
+ ])
369
369
370
370
if self .error_counts :
371
371
lines .append ("Detailed error counts:" )
372
372
for check_name in sorted (self .error_counts .keys ()):
373
373
check_errors = self .error_counts [check_name ]
374
- lines .append (" - {} = {}" . format ( check_name , check_errors ) )
374
+ lines .append (f " - { check_name } = { check_errors } " )
375
375
376
376
return "\n " .join (lines )
377
377
0 commit comments