linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] checkpatch: use python3 to find codespell dictionary
@ 2022-03-08  2:55 Sagar Patel
  2022-03-08  7:58 ` Péter Ujfalusi
  0 siblings, 1 reply; 3+ messages in thread
From: Sagar Patel @ 2022-03-08  2:55 UTC (permalink / raw)
  To: Andy Whitcroft; +Cc: Joe Perches, Peter Ujfalusi, linux-kernel, Sagar Patel

Commit 0ee3e7b8893e ("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
binary 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 the dictionary, do not check if the
codespell binary exists since codespell can be installed via a Python
package manager. In this case, a codespell binary is not exported in
$PATH, but a dictionary does exist.

Signed-off-by: Sagar Patel <sagarmp@cs.unc.edu>
---
 scripts/checkpatch.pl | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index b01c36a15d9d..46302e074b18 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -334,7 +334,7 @@ if ($user_codespellfile) {
 } 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
@@ -344,7 +344,7 @@ codespell_file = op.join(codespell_dir, 'data', 'dictionary.txt')
 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);
 	}
 }
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] checkpatch: use python3 to find codespell dictionary
  2022-03-08  2:55 [PATCH] checkpatch: use python3 to find codespell dictionary Sagar Patel
@ 2022-03-08  7:58 ` Péter Ujfalusi
  2022-03-09 18:01   ` Sagar Patel
  0 siblings, 1 reply; 3+ messages in thread
From: Péter Ujfalusi @ 2022-03-08  7:58 UTC (permalink / raw)
  To: Sagar Patel, Andy Whitcroft; +Cc: Joe Perches, linux-kernel

Hi Sagar,

On 08/03/2022 04:55, Sagar Patel wrote:
> Commit 0ee3e7b8893e ("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
> binary 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 the dictionary, do not check if the
> codespell binary exists since codespell can be installed via a Python
> package manager. In this case, a codespell binary is not exported in
> $PATH, but a dictionary does exist.

Installing codespell via pip will place the 'codespell' executable under
the user's $HOME/.local/bin/ and it expects that it is in PATH:

# pip install codespell
Defaulting to user installation because normal site-packages is not writeable
Collecting codespell
  Downloading codespell-2.1.0-py3-none-any.whl (177 kB)
     |████████████████████████████████| 177 kB 1.9 MB/s            
Installing collected packages: codespell
  WARNING: The script codespell is installed in '/home/my_user/.local/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.

Having said that, the executable itself is not used by checkpatch.pl, so

Reviewed-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>

> 
> Signed-off-by: Sagar Patel <sagarmp@cs.unc.edu>
> ---
>  scripts/checkpatch.pl | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index b01c36a15d9d..46302e074b18 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -334,7 +334,7 @@ if ($user_codespellfile) {
>  } 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
> @@ -344,7 +344,7 @@ codespell_file = op.join(codespell_dir, 'data', 'dictionary.txt')
>  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);
>  	}
>  }

-- 
Péter

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] checkpatch: use python3 to find codespell dictionary
  2022-03-08  7:58 ` Péter Ujfalusi
@ 2022-03-09 18:01   ` Sagar Patel
  0 siblings, 0 replies; 3+ messages in thread
From: Sagar Patel @ 2022-03-09 18:01 UTC (permalink / raw)
  To: Péter Ujfalusi; +Cc: Andy Whitcroft, Joe Perches, linux-kernel

On Tue, Mar 8, 2022 at 2:58 AM Péter Ujfalusi wrote:
> > In addition, when searching for the dictionary, do not check if the
> > codespell binary exists since codespell can be installed via a Python
> > package manager. In this case, a codespell binary is not exported in
> > $PATH, but a dictionary does exist.
>
> Installing codespell via pip will place the 'codespell' executable under
> the user's $HOME/.local/bin/ and it expects that it is in PATH:

Good point, I'll reword the commit message in v2.

> Having said that, the executable itself is not used by checkpatch.pl, so
>
> Reviewed-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>

Thank you!

---Sagar Patel

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-03-09 18:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-08  2:55 [PATCH] checkpatch: use python3 to find codespell dictionary Sagar Patel
2022-03-08  7:58 ` Péter Ujfalusi
2022-03-09 18:01   ` Sagar Patel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).