Load dictionary_code.txt in addition to the default dictionary.
Add a new command line argument --dictionaries to be able
to specify codespell dictionaries.

Signed-off-by: Roi Dayan <r...@nvidia.com>
Acked-by: Salem Sol <sal...@nvidia.com>
---

Notes:
    v2
    - Add --dictionaries command line option to configure the
      codespell dictionaries being used.

 utilities/checkpatch.py | 25 ++++++++++++++++++-------
 1 file changed, 18 insertions(+), 7 deletions(-)

diff --git a/utilities/checkpatch.py b/utilities/checkpatch.py
index f8caeb811604..241346694e4b 100755
--- a/utilities/checkpatch.py
+++ b/utilities/checkpatch.py
@@ -37,19 +37,23 @@ spellcheck = False
 quiet = False
 spell_check_dict = None
 missing_authors = []
+codespell_dictionaries = ['dictionary.txt', 'dictionary_code.txt']
+__codespell_dict_reset_once = True
 
 
 def open_spell_check_dict():
     import enchant
 
+    codespell_files = []
     try:
         import codespell_lib
         codespell_dir = os.path.dirname(codespell_lib.__file__)
-        codespell_file = os.path.join(codespell_dir, 'data', 'dictionary.txt')
-        if not os.path.exists(codespell_file):
-            codespell_file = ''
+        for fn in codespell_dictionaries:
+            fn = os.path.join(codespell_dir, 'data', fn)
+            if os.path.exists(fn):
+                codespell_files.append(fn)
     except:
-        codespell_file = ''
+        pass
 
     try:
         extra_keywords = ['ovs', 'vswitch', 'vswitchd', 'ovs-vswitchd',
@@ -121,8 +125,8 @@ def open_spell_check_dict():
 
         spell_check_dict = enchant.Dict("en_US")
 
-        if codespell_file:
-            with open(codespell_file) as f:
+        for fn in codespell_files:
+            with open(fn) as f:
                 for line in f.readlines():
                     words = line.strip().split('>')[1].strip(', ').split(',')
                     for word in words:
@@ -1130,6 +1134,7 @@ Check options:
 -a|--check-authors-file        Check AUTHORS file for existence of the authors.
                                Should be used by commiters only!
 -b|--skip-block-whitespace     Skips the if/while/for whitespace tests
+-D|--dictionaries DICTIONARY   Specify codespell dictionaries.
 -l|--skip-leading-whitespace   Skips the leading whitespace test
 -q|--quiet                     Only print error and warning information
 -s|--skip-signoff-lines        Tolerate missing Signed-off-by line
@@ -1215,10 +1220,11 @@ if __name__ == '__main__':
                                           sys.argv[1:])
         n_patches = int(numeric_options[-1][1:]) if numeric_options else 0
 
-        optlist, args = getopt.getopt(args, 'abhlstfSq',
+        optlist, args = getopt.getopt(args, 'abD:hlstfSq',
                                       ["check-file",
                                        "help",
                                        "check-authors-file",
+                                       "dictionaries=",
                                        "skip-block-whitespace",
                                        "skip-leading-whitespace",
                                        "skip-signoff-lines",
@@ -1237,6 +1243,11 @@ if __name__ == '__main__':
             sys.exit(0)
         elif o in ("-a", "--check-authors-file"):
             check_authors_file = True
+        elif o in ("-D", "--dictionaries"):
+            if __codespell_dict_reset_once:
+                __codespell_dict_reset_once = False
+                codespell_dictionaries = []
+            codespell_dictionaries.append(a)
         elif o in ("-b", "--skip-block-whitespace"):
             skip_block_whitespace_check = True
         elif o in ("-l", "--skip-leading-whitespace"):
-- 
2.21.0

_______________________________________________
dev mailing list
d...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to