Skip to content

Commit

Permalink
checkpatch: use python3 to find codespell dictionary
Browse files Browse the repository at this point in the history
Commit 0ee3e7b ("checkpatch: get default codespell dictionary path
from package location") introduced the ability to search for the
codespell dictionary rather than hardcoding its path.

codespell requires Python 3.6 or above, but on some systems, the python
executable is a Python 2.7 interpreter.  In this case, searching for the
dictionary fails, subsequently making codespell fail:

  No codespell typos will be found - file '/usr/share/codespell/dictionary.txt': No such file or directory

So, use python3 to remove ambiguity.

In addition, when searching for dictionary.txt, do not check if the
codespell executable exists since,

 - checkpatch.pl only uses dictionary.txt, not the codespell
   executable.

 - codespell can be installed via a Python package manager, in which
   case the codespell executable may not be present in a typical $PATH,
   but a dictionary does exist.

Link: https://lkml.kernel.org/r/[email protected]
Signed-off-by: Sagar Patel <[email protected]>
Reviewed-by: Peter Ujfalusi <[email protected]>
Cc: Joe Perches <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
msagarpatel authored and torvalds committed Mar 24, 2022
1 parent 05dc40e commit c882c6b
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions scripts/checkpatch.pl
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ sub load_docs {
} elsif (!(-f $codespellfile)) {
# If /usr/share/codespell/dictionary.txt is not present, try to find it
# under codespell's install directory: <codespell_root>/data/dictionary.txt
if (($codespell || $help) && which("codespell") ne "" && which("python") ne "") {
if (($codespell || $help) && which("python3") ne "") {
my $python_codespell_dict = << "EOF";
import os.path as op
Expand All @@ -344,7 +344,7 @@ sub load_docs {
print(codespell_file, end='')
EOF

my $codespell_dict = `python -c "$python_codespell_dict" 2> /dev/null`;
my $codespell_dict = `python3 -c "$python_codespell_dict" 2> /dev/null`;
$codespellfile = $codespell_dict if (-f $codespell_dict);
}
}
Expand Down

0 comments on commit c882c6b

Please sign in to comment.