22
33import sys
44import os
5+ import fnmatch
56import glob
67import argparse
78import re
@@ -186,6 +187,17 @@ def exclude_check(name, exclude_list):
186187 return False
187188
188189
190+ def skip_check (name , skip_list ):
191+ """Return True if ``name`` matches any of the glob pattern listed in
192+ ``skip_list``."""
193+ if skip_list is None :
194+ return False
195+ for skip in "," .join (skip_list ).split ("," ):
196+ if fnmatch .fnmatch (name , skip ):
197+ return True
198+ return False
199+
200+
189201def parse_args ():
190202 parser = argparse .ArgumentParser ()
191203
@@ -211,6 +223,12 @@ def parse_args():
211223 dest = 'exclude' ,
212224 help = 'Specify regex for excluding files (multiples allowed)' )
213225
226+ parser .add_argument ('--skip' , '-S' , action = 'append' ,
227+ help = 'comma-separated list of files to skip. It '
228+ 'accepts globs as well. E.g.: if you want '
229+ 'codespell to skip .eps and .txt files, '
230+ 'you\' d give "*.eps,*.txt" to this option.' )
231+
214232 parser .add_argument ('--prefix' , '-p' , action = 'append' , default = [],
215233 dest = 'prefixes' ,
216234 help = 'Add word prefix (multiples allowed)' )
@@ -305,7 +323,7 @@ def main():
305323 # spell check the files found in f
306324 for x in dir_entries :
307325
308- if exclude_check (x , args .exclude ):
326+ if exclude_check (x , args .exclude ) or skip_check ( x , args . skip ) :
309327 if not args .miss :
310328 print ("\n Excluding" , x )
311329 continue
@@ -320,7 +338,7 @@ def main():
320338 else :
321339
322340 # f is a file
323- if exclude_check (f , args .exclude ):
341+ if exclude_check (f , args .exclude ) or skip_check ( f , args . skip ) :
324342 if not args .miss :
325343 print ("\n Excluding" , x )
326344 continue
0 commit comments