37
37
quiet = False
38
38
spell_check_dict = None
39
39
missing_authors = []
40
+ codespell_dictionaries = ['dictionary.txt' , 'dictionary_code.txt' ]
41
+ __codespell_dict_reset_once = True
40
42
41
43
42
44
def open_spell_check_dict ():
43
45
import enchant
44
46
47
+ codespell_files = []
45
48
try :
46
49
import codespell_lib
47
50
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 )
51
55
except :
52
- codespell_file = ''
56
+ pass
53
57
54
58
try :
55
59
extra_keywords = ['ovs' , 'vswitch' , 'vswitchd' , 'ovs-vswitchd' ,
@@ -121,8 +125,8 @@ def open_spell_check_dict():
121
125
122
126
spell_check_dict = enchant .Dict ("en_US" )
123
127
124
- if codespell_file :
125
- with open (codespell_file ) as f :
128
+ for fn in codespell_files :
129
+ with open (fn ) as f :
126
130
for line in f .readlines ():
127
131
words = line .strip ().split ('>' )[1 ].strip (', ' ).split (',' )
128
132
for word in words :
@@ -1130,6 +1134,7 @@ def usage():
1130
1134
-a|--check-authors-file Check AUTHORS file for existence of the authors.
1131
1135
Should be used by commiters only!
1132
1136
-b|--skip-block-whitespace Skips the if/while/for whitespace tests
1137
+ -D|--dictionaries DICTIONARY Specify codespell dictionaries.
1133
1138
-l|--skip-leading-whitespace Skips the leading whitespace test
1134
1139
-q|--quiet Only print error and warning information
1135
1140
-s|--skip-signoff-lines Tolerate missing Signed-off-by line
@@ -1215,10 +1220,11 @@ def partition(pred, iterable):
1215
1220
sys .argv [1 :])
1216
1221
n_patches = int (numeric_options [- 1 ][1 :]) if numeric_options else 0
1217
1222
1218
- optlist , args = getopt .getopt (args , 'abhlstfSq ' ,
1223
+ optlist , args = getopt .getopt (args , 'abD:hlstfSq ' ,
1219
1224
["check-file" ,
1220
1225
"help" ,
1221
1226
"check-authors-file" ,
1227
+ "dictionaries=" ,
1222
1228
"skip-block-whitespace" ,
1223
1229
"skip-leading-whitespace" ,
1224
1230
"skip-signoff-lines" ,
@@ -1237,6 +1243,11 @@ def partition(pred, iterable):
1237
1243
sys .exit (0 )
1238
1244
elif o in ("-a" , "--check-authors-file" ):
1239
1245
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 )
1240
1251
elif o in ("-b" , "--skip-block-whitespace" ):
1241
1252
skip_block_whitespace_check = True
1242
1253
elif o in ("-l" , "--skip-leading-whitespace" ):
@@ -1252,11 +1263,7 @@ def partition(pred, iterable):
1252
1263
elif o in ("-f" , "--check-file" ):
1253
1264
checking_file = True
1254
1265
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
1260
1267
elif o in ("-q" , "--quiet" ):
1261
1268
quiet = True
1262
1269
else :
@@ -1266,6 +1273,11 @@ def partition(pred, iterable):
1266
1273
if sys .stdout .isatty ():
1267
1274
colors = True
1268
1275
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
+
1269
1281
if n_patches :
1270
1282
status = 0
1271
1283
0 commit comments