3535import os
3636import sys
3737
38-
3938try :
4039 # py3.11+
4140 from tomllib import load as toml_load # type: ignore
4544
4645from stevedore import extension
4746
48- from doc8 import checks
47+ from doc8 import checks , utils , version
4948from doc8 import parser as file_parser
50- from doc8 import utils
51- from doc8 import version
5249
5350FILE_PATTERNS = [".rst" , ".txt" ]
5451MAX_LINE_LENGTH = 79
@@ -158,7 +155,8 @@ def extract_config(args):
158155 if not os .path .isfile (cfg_file ):
159156 if args ["config" ]:
160157 print (
161- "Configuration file %s does not exist...ignoring" % (args ["config" ])
158+ "Configuration file %s does not exist...ignoring"
159+ % (args ["config" ]),
162160 )
163161 continue
164162 if cfg_file .endswith ((".ini" , ".cfg" )):
@@ -180,7 +178,9 @@ def fetch_checks(cfg):
180178 checks .CheckNewlineEndOfFile (cfg ),
181179 ]
182180 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 (),),
184184 )
185185 addons = []
186186 for e in mgr :
@@ -194,7 +194,9 @@ def setup_logging(verbose):
194194 else :
195195 level = logging .ERROR
196196 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 ,
198200 )
199201
200202
@@ -205,7 +207,9 @@ def scan(cfg):
205207 ignored_paths = cfg .get ("ignore_path" , [])
206208 files_ignored = 0
207209 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 ,
209213 )
210214 default_extension = cfg .get ("default_extension" )
211215 file_encoding = cfg .get ("file_encoding" )
@@ -216,7 +220,9 @@ def scan(cfg):
216220 print (" Ignoring '%s'" % (filename ))
217221 else :
218222 f = file_parser .parse (
219- filename , default_extension = default_extension , encoding = file_encoding
223+ filename ,
224+ default_extension = default_extension ,
225+ encoding = file_encoding ,
220226 )
221227 files .append (f )
222228 if cfg .get ("verbose" ):
@@ -253,7 +259,7 @@ def validate(cfg, files, result=None):
253259 print (
254260 " Skipping check '%s' since it does not"
255261 " understand parsing a file with extension '%s'"
256- % (check_name , f .extension )
262+ % (check_name , f .extension ),
257263 )
258264 continue
259265 try :
@@ -266,7 +272,7 @@ def validate(cfg, files, result=None):
266272 if cfg .get ("verbose" ):
267273 print (
268274 " Skipping check '%s', determined to only"
269- " check ignoreable codes" % check_name
275+ " check ignoreable codes" % check_name ,
270276 )
271277 continue
272278 if cfg .get ("verbose" ):
@@ -279,13 +285,11 @@ def validate(cfg, files, result=None):
279285 line_num = "?"
280286 if cfg .get ("verbose" ):
281287 print (
282- " - {}:{}: {} {}" .format (
283- f .filename , line_num , code , message
284- )
288+ f" - { f .filename } :{ line_num } : { code } { message } " ,
285289 )
286290 elif not result .capture :
287291 print (
288- "{ }:{}: {} {}" . format ( f . filename , line_num , code , message )
292+ f" { f . filename } :{ line_num } : { code } { message } " ,
289293 )
290294 result .error (check_name , f .filename , line_num , code , message )
291295 error_counts [check_name ] += 1
@@ -297,18 +301,16 @@ def validate(cfg, files, result=None):
297301 if cfg .get ("verbose" ):
298302 print (
299303 " - %s:%s: %s %s"
300- % (f .filename , line_num , code , message )
304+ % (f .filename , line_num , code , message ),
301305 )
302306 elif not result .capture :
303307 print (
304- "{}:{}: {} {}" .format (
305- f .filename , line_num , code , message
306- )
308+ f"{ f .filename } :{ line_num } : { code } { message } " ,
307309 )
308310 result .error (check_name , f .filename , line_num , code , message )
309311 error_counts [check_name ] += 1
310312 else :
311- raise TypeError ("Unknown check type: {}, {}" . format ( type (c ), c ) )
313+ raise TypeError (f "Unknown check type: { type (c )} , { c } " )
312314 return error_counts
313315
314316
@@ -358,20 +360,18 @@ def report(self):
358360 for error in self .errors :
359361 lines .append ("%s:%s: %s %s" % error [1 :])
360362
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+ ])
369369
370370 if self .error_counts :
371371 lines .append ("Detailed error counts:" )
372372 for check_name in sorted (self .error_counts .keys ()):
373373 check_errors = self .error_counts [check_name ]
374- lines .append (" - {} = {}" . format ( check_name , check_errors ) )
374+ lines .append (f " - { check_name } = { check_errors } " )
375375
376376 return "\n " .join (lines )
377377
0 commit comments