Skip to content

Commit

Permalink
checkpatch.py: Load codespell dictionary.
Browse files Browse the repository at this point in the history
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>
Acked-by: Eelco Chaudron <echaudro@redhat.com>
Signed-off-by: Aaron Conole <aconole@redhat.com>
  • Loading branch information
roidayan authored and apconole committed Jan 9, 2024
1 parent 21c6124 commit 915b979
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions utilities/checkpatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@
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',
Expand Down Expand Up @@ -91,7 +100,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.strip())

for kw in extra_keywords:
spell_check_dict.add_to_session(kw)

Expand Down

0 comments on commit 915b979

Please sign in to comment.