Skip to content

Commit 3dea4e0

Browse files
roidayanapconole
authored andcommitted
checkpatch.py: Load multiple codespell dictionaries.
Load dictionary_code.txt in addition to the default dictionary. Add a new command line argument --dictionaries to be able to specify codespell dictionaries. Acked-by: Salem Sol <[email protected]> Signed-off-by: Roi Dayan <[email protected]> Signed-off-by: Aaron Conole <[email protected]>
1 parent a824a6b commit 3dea4e0

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

utilities/checkpatch.py

+24-12
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,23 @@
3737
quiet = False
3838
spell_check_dict = None
3939
missing_authors = []
40+
codespell_dictionaries = ['dictionary.txt', 'dictionary_code.txt']
41+
__codespell_dict_reset_once = True
4042

4143

4244
def open_spell_check_dict():
4345
import enchant
4446

47+
codespell_files = []
4548
try:
4649
import codespell_lib
4750
codespell_dir = os.path.dirname(codespell_lib.__file__)
48-
codespell_file = os.path.join(codespell_dir, 'data', 'dictionary.txt')
49-
if not os.path.exists(codespell_file):
50-
codespell_file = ''
51+
for fn in codespell_dictionaries:
52+
fn = os.path.join(codespell_dir, 'data', fn)
53+
if os.path.exists(fn):
54+
codespell_files.append(fn)
5155
except:
52-
codespell_file = ''
56+
pass
5357

5458
try:
5559
extra_keywords = ['ovs', 'vswitch', 'vswitchd', 'ovs-vswitchd',
@@ -121,8 +125,8 @@ def open_spell_check_dict():
121125

122126
spell_check_dict = enchant.Dict("en_US")
123127

124-
if codespell_file:
125-
with open(codespell_file) as f:
128+
for fn in codespell_files:
129+
with open(fn) as f:
126130
for line in f.readlines():
127131
words = line.strip().split('>')[1].strip(', ').split(',')
128132
for word in words:
@@ -1130,6 +1134,7 @@ def usage():
11301134
-a|--check-authors-file Check AUTHORS file for existence of the authors.
11311135
Should be used by commiters only!
11321136
-b|--skip-block-whitespace Skips the if/while/for whitespace tests
1137+
-D|--dictionaries DICTIONARY Specify codespell dictionaries.
11331138
-l|--skip-leading-whitespace Skips the leading whitespace test
11341139
-q|--quiet Only print error and warning information
11351140
-s|--skip-signoff-lines Tolerate missing Signed-off-by line
@@ -1215,10 +1220,11 @@ def partition(pred, iterable):
12151220
sys.argv[1:])
12161221
n_patches = int(numeric_options[-1][1:]) if numeric_options else 0
12171222

1218-
optlist, args = getopt.getopt(args, 'abhlstfSq',
1223+
optlist, args = getopt.getopt(args, 'abD:hlstfSq',
12191224
["check-file",
12201225
"help",
12211226
"check-authors-file",
1227+
"dictionaries=",
12221228
"skip-block-whitespace",
12231229
"skip-leading-whitespace",
12241230
"skip-signoff-lines",
@@ -1237,6 +1243,11 @@ def partition(pred, iterable):
12371243
sys.exit(0)
12381244
elif o in ("-a", "--check-authors-file"):
12391245
check_authors_file = True
1246+
elif o in ("-D", "--dictionaries"):
1247+
if __codespell_dict_reset_once:
1248+
__codespell_dict_reset_once = False
1249+
codespell_dictionaries = []
1250+
codespell_dictionaries.append(a)
12401251
elif o in ("-b", "--skip-block-whitespace"):
12411252
skip_block_whitespace_check = True
12421253
elif o in ("-l", "--skip-leading-whitespace"):
@@ -1252,11 +1263,7 @@ def partition(pred, iterable):
12521263
elif o in ("-f", "--check-file"):
12531264
checking_file = True
12541265
elif o in ("-S", "--spellcheck"):
1255-
if not open_spell_check_dict():
1256-
print("WARNING: The enchant library isn't available.")
1257-
print(" Please install python enchant.")
1258-
else:
1259-
spellcheck = True
1266+
spellcheck = True
12601267
elif o in ("-q", "--quiet"):
12611268
quiet = True
12621269
else:
@@ -1266,6 +1273,11 @@ def partition(pred, iterable):
12661273
if sys.stdout.isatty():
12671274
colors = True
12681275

1276+
if spellcheck and not open_spell_check_dict():
1277+
print("WARNING: The enchant library isn't available.")
1278+
print(" Please install python enchant.")
1279+
spellcheck = False
1280+
12691281
if n_patches:
12701282
status = 0
12711283

0 commit comments

Comments
 (0)