Skip to content

Commit 0ee3e7b

Browse files
ujfalusitorvalds
authored andcommitted
checkpatch: get default codespell dictionary path from package location
The standard location of dictionary.txt is under codespell's package, on my machine atm (codespell 2.1, Artix Linux): /usr/lib/python3.9/site-packages/codespell_lib/data/dictionary.txt Since we enable the codespell by default for SOF I have constant: No codespell typos will be found - file '/usr/share/codespell/dictionary.txt': No such file or directory The patch proposes to try to fix up the path following the recommendation found here: codespell-project/codespell#1540 Link: https://lkml.kernel.org/r/29e25d1364c8ad7f7657cc0660f60c568074d438.camel@perches.com Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com> Acked-by: Joe Perches <joe@perches.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 70a1165 commit 0ee3e7b

1 file changed

Lines changed: 28 additions & 4 deletions

File tree

‎scripts/checkpatch.pl‎

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
my $spelling_file = "$D/spelling.txt";
6464
my $codespell = 0;
6565
my $codespellfile = "/usr/share/codespell/dictionary.txt";
66+
my $user_codespellfile = "";
6667
my $conststructsfile = "$D/const_structs.checkpatch";
6768
my $docsfile = "$D/../Documentation/dev-tools/checkpatch.rst";
6869
my $typedefsfile;
@@ -130,7 +131,7 @@ sub help {
130131
--ignore-perl-version override checking of perl version. expect
131132
runtime errors.
132133
--codespell Use the codespell dictionary for spelling/typos
133-
(default:/usr/share/codespell/dictionary.txt)
134+
(default:$codespellfile)
134135
--codespellfile Use this codespell dictionary
135136
--typedefsfile Read additional types from this file
136137
--color[=WHEN] Use colors 'always', 'never', or only when output
@@ -317,17 +318,40 @@ sub load_docs {
317318
'debug=s' => \%debug,
318319
'test-only=s' => \$tst_only,
319320
'codespell!' => \$codespell,
320-
'codespellfile=s' => \$codespellfile,
321+
'codespellfile=s' => \$user_codespellfile,
321322
'typedefsfile=s' => \$typedefsfile,
322323
'color=s' => \$color,
323324
'no-color' => \$color, #keep old behaviors of -nocolor
324325
'nocolor' => \$color, #keep old behaviors of -nocolor
325326
'kconfig-prefix=s' => \${CONFIG_},
326327
'h|help' => \$help,
327328
'version' => \$help
328-
) or help(1);
329+
) or $help = 2;
330+
331+
if ($user_codespellfile) {
332+
# Use the user provided codespell file unconditionally
333+
$codespellfile = $user_codespellfile;
334+
} elsif (!(-f $codespellfile)) {
335+
# If /usr/share/codespell/dictionary.txt is not present, try to find it
336+
# under codespell's install directory: <codespell_root>/data/dictionary.txt
337+
if (($codespell || $help) && which("codespell") ne "" && which("python") ne "") {
338+
my $python_codespell_dict = << "EOF";
339+
340+
import os.path as op
341+
import codespell_lib
342+
codespell_dir = op.dirname(codespell_lib.__file__)
343+
codespell_file = op.join(codespell_dir, 'data', 'dictionary.txt')
344+
print(codespell_file, end='')
345+
EOF
346+
347+
my $codespell_dict = `python -c "$python_codespell_dict" 2> /dev/null`;
348+
$codespellfile = $codespell_dict if (-f $codespell_dict);
349+
}
350+
}
329351

330-
help(0) if ($help);
352+
# $help is 1 if either -h, --help or --version is passed as option - exitcode: 0
353+
# $help is 2 if invalid option is passed - exitcode: 1
354+
help($help - 1) if ($help);
331355

332356
die "$P: --git cannot be used with --file or --fix\n" if ($git && ($file || $fix));
333357
die "$P: --verbose cannot be used with --terse\n" if ($verbose && $terse);

0 commit comments

Comments
 (0)