Skip to content

Commit 1d99588

Browse files
committed
ENH: Add support for excluding files specifying glob pattern
This is intended to streamline the integration of project already using the checker provided by "codespell-project".
1 parent 2876e96 commit 1d99588

1 file changed

Lines changed: 20 additions & 2 deletions

File tree

codespell.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import sys
44
import os
5+
import fnmatch
56
import glob
67
import argparse
78
import 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+
189201
def 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("\nExcluding", 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("\nExcluding", x)
326344
continue

0 commit comments

Comments
 (0)