checkpatch: auto detect codespell dictionary path
PATCH 1/1 checkpatch: auto detect codespell dictionary path
The codespell dictionary was moved from /usr/share/codespell/dictionary.txt to data/dictionary.txt under the codespell_lib installation directory.
Checkpatch still uses a default absolute path for it which will no longer work on new codespell installations unless the path is specified through --codespellfile.
Detect the codespell dictionary path dynamically during runtime if the default path or the user provided dictionary path does not exist.
--- scripts/checkpatch.pl | 7 +++++++ 1 file changed, 7 insertions(+)
scripts/checkpatch.pl +7 -0
@@ -889,6 +889,13 @@ if (open(my $spelling, '<', $spelling_file)) { } if ($codespell) { + if (! -e "$codespellfile" && which("python3") ne "") { + my $output = `python3 -c "import codespell_lib; print(codespell_lib.__file__, end='');" 2>/dev/null`; + my $dictionary_path = dirname($output) . "/data/dictionary.txt"; + if (-e "$dictionary_path") { + $codespellfile = $dictionary_path; + } + } if (open(my $spelling, '<', $codespellfile)) { while (<$spelling>) { my $line = $_;
Signature · 1 line
2.28.0
Joe Perches
maintainerQuoted 11 lines · Dwaipayan Ray
The codespell dictionary was moved from
/usr/share/codespell/dictionary.txttodata/dictionary.txtunder thecodespell_libinstallation directory.Checkpatch still uses a default absolute path for it which will no longer work on new codespell installations unless the path is specified through --codespellfile.
Detect the codespell dictionary path dynamically during runtime if the default path or the user provided dictionary path does not exist.
[]
scripts/checkpatch.pl
Quoted 1 line
scripts/checkpatch.pl +0
-0
[]
scripts/checkpatch.pl if (open(my $spelling, '<', $spelling_file)) { · line 893
Quoted 7 lines
scripts/checkpatch.pl +0
-0@@ -889,6 +889,13 @@ if (open(my $spelling, '<', $spelling_file)) { }if ($codespell) {
scripts/checkpatch.pl +2
-0+ if (! -e "$codespellfile" && which("python3") ne "") { + my $output = `python3 -c "import codespell_lib; print(codespell_lib.__file__, end='');" 2>/dev/null`;
It doesn't seem to me that using python3 is a great way to invoke python. Maybe test the external command return $? when codespell isn't installed.
scripts/checkpatch.pl if (open(my $spelling, '<', $spelling_file)) { · line 894
Quoted 1 line
scripts/checkpatch.pl +1
-0+ my $dictionary_path = dirname($output) . "/data/dictionary.txt";
Unlikely, but this could still end up with a existing file of /data/dictionary.txt that is not a codespell file.
Quoted 7 lines
scripts/checkpatch.pl +4
-0+ if (-e "$dictionary_path") { + $codespellfile = $dictionary_path; + } + }if (
open(my $spelling, '<', $codespellfile)) { while (<$spelling>) {
my $line = $_;
Quoted 20 lines · Joe Perches
Quoted 11 lines · Dwaipayan Ray
The codespell dictionary was moved from
/usr/share/codespell/dictionary.txttodata/dictionary.txtunder thecodespell_libinstallation directory.Checkpatch still uses a default absolute path for it which will no longer work on new codespell installations unless the path is specified through --codespellfile.
Detect the codespell dictionary path dynamically during runtime if the default path or the user provided dictionary path does not exist.
[]
scripts/checkpatch.pl
Quoted 1 line
scripts/checkpatch.pl +0
-0[]
Quoted 4 lines
scripts/checkpatch.pl +0
-0@@ -889,6 +889,13 @@ if (open(my $spelling, '<', $spelling_file)) { }
Quoted 6 lines
scripts/checkpatch.pl if (open(my $spelling, '<', $spelling_file)) { · line 893
Quoted 3 lines
scripts/checkpatch.pl +2
-0if ($codespell) { + if (! -e "$codespellfile" && which("python3") ne "") { + my $output = `python3 -c "import codespell_lib; print(codespell_lib.__file__, end='');" 2>/dev/null`;It doesn't seem to me that using python3 is a great way to invoke python. Maybe test the external command return $? when codespell isn't installed.
Sure, I will add that.
Quoted 6 lines
scripts/checkpatch.pl if (open(my $spelling, '<', $spelling_file)) { · line 894
Quoted 2 lines
scripts/checkpatch.pl +1
-0+ my $dictionary_path = dirname($output) . "/data/dictionary.txt";Unlikely, but this could still end up with a existing file of /data/dictionary.txt that is not a codespell file.
So does testing for the return status give us some guarantee here? The dictionary
path should be relative to the codespell_lib directory, that's what the codespell
people writes.
Quoted 9 lines
Quoted 7 lines
scripts/checkpatch.pl +4
-0+ if (-e "$dictionary_path") { + $codespellfile = $dictionary_path; + } + } if (open(my $spelling, '<', $codespellfile)) { while (<$spelling>) {my $line = $_;