History

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: https://github.com/codespell-project/codespell/issues/1540

Peter Ujfalusi committed 5 years ago

Commit 0ee3e7b1 parent 70a11651 file · +28 −4Browse files

Showing the changes to scripts/checkpatch.pl (1 of 1 file). Show all

Unified · Split

scripts/checkpatch.pl+28−4
@@ -63,6 +63,7 @@ my $min_conf_desc_length = 4; · 62 unmodified lines
63my $spelling_file = "$D/spelling.txt";63my $spelling_file = "$D/spelling.txt";
64my $codespell = 0;64my $codespell = 0;
65my $codespellfile = "/usr/share/codespell/dictionary.txt";65my $codespellfile = "/usr/share/codespell/dictionary.txt";
66my $user_codespellfile = "";
66my $conststructsfile = "$D/const_structs.checkpatch";67my $conststructsfile = "$D/const_structs.checkpatch";
67my $docsfile = "$D/../Documentation/dev-tools/checkpatch.rst";68my $docsfile = "$D/../Documentation/dev-tools/checkpatch.rst";
68my $typedefsfile;69my $typedefsfile;
@@ -130,7 +131,7 @@ Options: · 61 unmodified lines
130 --ignore-perl-version override checking of perl version. expect131 --ignore-perl-version override checking of perl version. expect
131 runtime errors.132 runtime errors.
132 --codespell Use the codespell dictionary for spelling/typos133 --codespell Use the codespell dictionary for spelling/typos
133 (default:/usr/share/codespell/dictionary.txt)134 (default:$codespellfile)
134 --codespellfile Use this codespell dictionary135 --codespellfile Use this codespell dictionary
135 --typedefsfile Read additional types from this file136 --typedefsfile Read additional types from this file
136 --color[=WHEN] Use colors 'always', 'never', or only when output137 --color[=WHEN] Use colors 'always', 'never', or only when output
@@ -317,7 +318,7 @@ GetOptions( · 180 unmodified lines
317 'debug=s' => \%debug,318 'debug=s' => \%debug,
318 'test-only=s' => \$tst_only,319 'test-only=s' => \$tst_only,
319 'codespell!' => \$codespell,320 'codespell!' => \$codespell,
320 'codespellfile=s' => \$codespellfile,321 'codespellfile=s' => \$user_codespellfile,
321 'typedefsfile=s' => \$typedefsfile,322 'typedefsfile=s' => \$typedefsfile,
322 'color=s' => \$color,323 'color=s' => \$color,
323 'no-color' => \$color, #keep old behaviors of -nocolor324 'no-color' => \$color, #keep old behaviors of -nocolor
@@ -325,9 +326,32 @@ GetOptions( · 1 unmodified line
325 'kconfig-prefix=s' => \${CONFIG_},326 'kconfig-prefix=s' => \${CONFIG_},
326 'h|help' => \$help,327 'h|help' => \$help,
327 'version' => \$help328 'version' => \$help
328) or help(1);329) or $help = 2;
330
331if ($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
340import os.path as op
341import codespell_lib
342codespell_dir = op.dirname(codespell_lib.__file__)
343codespell_file = op.join(codespell_dir, 'data', 'dictionary.txt')
344print(codespell_file, end='')
345EOF
346
347 my $codespell_dict = `python -c "$python_codespell_dict" 2> /dev/null`;
348 $codespellfile = $codespell_dict if (-f $codespell_dict);
349 }
350}
329 351
330help(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
354help($help - 1) if ($help);
331 355
332die "$P: --git cannot be used with --file or --fix\n" if ($git && ($file || $fix));356die "$P: --git cannot be used with --file or --fix\n" if ($git && ($file || $fix));
333die "$P: --verbose cannot be used with --terse\n" if ($verbose && $terse);357die "$P: --verbose cannot be used with --terse\n" if ($verbose && $terse);