12
12
13
13
"""
14
14
from __future__ import with_statement
15
+ from distutils .command .check import check
15
16
16
17
import os
17
18
import sys
@@ -440,9 +441,20 @@ def get_option_parser():
440
441
help = 'show explanation of each error' )
441
442
option ('-s' , '--source' , action = 'store_true' ,
442
443
help = 'show source for each error' )
444
+ option ('--select' , metavar = '<codes>' , default = '' ,
445
+ help = 'choose the basic list of checked errors by specifying which '
446
+ 'errors to check for (with a list of comma-separated error '
447
+ 'codes). for example: --select=D101,D202' )
443
448
option ('--ignore' , metavar = '<codes>' , default = '' ,
444
- help = 'ignore a list comma-separated error codes, '
445
- 'for example: --ignore=D101,D202' )
449
+ help = 'choose the basic list of checked errors by specifying which '
450
+ 'errors to ignore (with a list of comma-separated error '
451
+ 'codes). for example: --ignore=D101,D202' )
452
+ option ('--add-select' , metavar = '<codes>' , default = '' ,
453
+ help = 'amend the list of errors to check for by specifying more '
454
+ 'error codes to check.' )
455
+ option ('--add-ignore' , metavar = '<codes>' , default = '' ,
456
+ help = 'amend the list of errors to check for by specifying more '
457
+ 'error codes to ignore.' )
446
458
option ('--match' , metavar = '<pattern>' , default = '(?!test_).*\.py' ,
447
459
help = "check only files that exactly match <pattern> regular "
448
460
"expression; default is --match='(?!test_).*\.py' which "
@@ -484,14 +496,14 @@ def collect(names, match=lambda name: True, match_dir=lambda name: True):
484
496
yield name
485
497
486
498
487
- def check (filenames , ignore = ()):
499
+ def check (filenames , checked_codes = ()):
488
500
"""Generate PEP 257 errors that exist in `filenames` iterable.
489
501
490
- Skips errors with error-codes defined in `ignore ` iterable.
502
+ Only returns errors with error-codes defined in `checked_codes ` iterable.
491
503
492
504
Example
493
505
-------
494
- >>> check(['pep257.py'], ignore =['D100'])
506
+ >>> check(['pep257.py'], checked_codes =['D100'])
495
507
<generator object check at 0x...>
496
508
497
509
"""
@@ -502,7 +514,7 @@ def check(filenames, ignore=()):
502
514
source = file .read ()
503
515
for error in PEP257Checker ().check_source (source , filename ):
504
516
code = getattr (error , 'code' , None )
505
- if code is not None and code not in ignore :
517
+ if code in checked_codes :
506
518
yield error
507
519
except (EnvironmentError , AllError ):
508
520
yield sys .exc_info ()[1 ]
@@ -567,6 +579,9 @@ def setup_stream_handler(options):
567
579
log .addHandler (stream_handler )
568
580
569
581
582
+ def get_checked_error_codes (options ):
583
+ return ['D100' ]
584
+
570
585
def run_pep257 ():
571
586
log .setLevel (logging .DEBUG )
572
587
opt_parser = get_option_parser ()
@@ -589,7 +604,9 @@ def run_pep257():
589
604
Error .explain = options .explain
590
605
Error .source = options .source
591
606
collected = list (collected )
592
- errors = check (collected , ignore = options .ignore .split (',' ))
607
+ checked_codes = get_checked_error_codes (options )
608
+ # options.ignore.split(',')
609
+ errors = check (collected , checked_codes = checked_codes )
593
610
code = 0
594
611
count = 0
595
612
for error in errors :
@@ -724,7 +741,7 @@ def check_blank_before_after_class(slef, class_, docstring):
724
741
docstring.
725
742
726
743
"""
727
- # NOTE: this gives flase -positive in this case
744
+ # NOTE: this gives false -positive in this case
728
745
# class Foo:
729
746
#
730
747
# """Docstring."""
0 commit comments