diff mbox series

[ovs-dev,v2,1/1] checkpatch.py: Load codespell dictionary.

Message ID 20231113105244.868169-2-roid@nvidia.com
State Superseded
Headers show
Series improve checkpatch spell checker | expand

Checks

Context Check Description
ovsrobot/apply-robot fail apply and check: fail
ovsrobot/intel-ovs-compilation fail test: fail

Commit Message

Roi Dayan Nov. 13, 2023, 10:52 a.m. UTC
codespell dictionary contains a list of widely used words
which enchant alone could fail on. for an example:
refcount, pthread, enqueuing, etc.
Load that dictionary, if exists, into enchant spell checker.

Signed-off-by: Roi Dayan <roid@nvidia.com>
---
 utilities/checkpatch.py | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
diff mbox series

Patch

diff --git a/utilities/checkpatch.py b/utilities/checkpatch.py
index 2dd02ee6420c..2669eca11108 100755
--- a/utilities/checkpatch.py
+++ b/utilities/checkpatch.py
@@ -39,6 +39,16 @@  spell_check_dict = None
 def open_spell_check_dict():
     import enchant
 
+    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 = ''
+    except:
+        codespell_file = ''
+
+
     try:
         extra_keywords = ['ovs', 'vswitch', 'vswitchd', 'ovs-vswitchd',
                           'netdev', 'selinux', 'ovs-ctl', 'dpctl', 'ofctl',
@@ -91,7 +101,16 @@  def open_spell_check_dict():
                           'syscall', 'lacp', 'ipf', 'skb', 'valgrind']
 
         global spell_check_dict
+
         spell_check_dict = enchant.Dict("en_US")
+
+        if codespell_file:
+            with open(codespell_file) as f:
+                for line in f.readlines():
+                    words = line.strip().split('>')[1].strip(', ').split(',')
+                    for word in words:
+                        spell_check_dict.add_to_session(word)
+
         for kw in extra_keywords:
             spell_check_dict.add_to_session(kw)