Skip to contentSkip to conversation

checkpatch: get default codespell dictionary path from package location

PATCH Superseded Peter Ujfalusi 2 participants 3 messages Oct 11, 2021 Checkpatch

v2 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 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

---
Hi,

Changes sicne v1:
- add missing ';' to the line updating the $codespellfile with $codespell_dict

Regards,
Peter

 scripts/checkpatch.pl | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
scripts/checkpatch.pl +7 -1
index c27d2312cfc3..fe11f2cb9f71 100755
@@ -73,6 +73,12 @@ my $git_command ='export LANGUAGE=en_US.UTF-8; git';
 my $tabsize = 8;
 my ${CONFIG_} = "CONFIG_";
 
+# Override the codespellfile location based on codespell install location
+if (which("codespell") ne "" && which("python") ne "") {
+	my $codespell_dict = `python -c "import os.path as op; import codespell_lib; print(op.join(op.dirname(codespell_lib.__file__), 'data', 'dictionary.txt'), end='')" 2> /dev/null`;
+	$codespellfile = $codespell_dict if (-e $codespell_dict);
+}
+
 sub help {
 	my ($exitcode) = @_;
 
@@ -130,7 +136,7 @@ Options:
   --ignore-perl-version      override checking of perl version.  expect
                              runtime errors.
   --codespell                Use the codespell dictionary for spelling/typos
-                             (default:/usr/share/codespell/dictionary.txt)
+                             (default:$codespellfile)
   --codespellfile            Use this codespell dictionary
   --typedefsfile             Read additional types from this file
   --color[=WHEN]             Use colors 'always', 'never', or only when output
Signature · 1 line
2.33.0
maintainer
#1 lore raw
Quoted 5 lines · Peter Ujfalusi

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:

If you enable it by default, you probably are using a .checkpatch.conf file. --codespell is not a typical default so I think always doing this test regardless of --codespell being enabled is inappropriate.

scripts/checkpatch.pl

Quoted 1 line
scripts/checkpatch.pl +0 -0

[]

scripts/checkpatch.pl my $git_command ='export LANGUAGE=en_US.UTF-8; git'; · line 81

Quoted 10 lines
scripts/checkpatch.pl +6 -0
@@ -73,6 +73,12 @@ my $git_command ='export LANGUAGE=en_US.UTF-8; git';
  my $tabsize = 8;
  my ${CONFIG_} = "CONFIG_";
 
+# Override the codespellfile location based on codespell install location
+if (which("codespell") ne "" && which("python") ne "") {
+	my $codespell_dict = `python -c "import os.path as op; import codespell_lib; print(op.join(op.dirname(codespell_lib.__file__), 'data', 'dictionary.txt'), end='')" 2> /dev/null`;
+	$codespellfile = $codespell_dict if (-e $codespell_dict);
+}
+

Maybe add a function and/or use something like:

	if (($codespell || $help) &&
	    which(etc...

scripts/checkpatch.pl Options: · line 139

Quoted 10 lines
scripts/checkpatch.pl +0 -0
  sub help {
  	my ($exitcode) = @_;

scripts/checkpatch.pl +0 -0
@@ -130,7 +136,7 @@ Options:

   --ignore-perl-version override checking of perl version. expect
                              runtime errors.
   --codespell Use the codespell dictionary for spelling/typos

scripts/checkpatch.pl +1 -1
-                             (default:/usr/share/codespell/dictionary.txt)
+                             (default:$codespellfile)

I think this should not be changed or only be shown as $codespellfile when --codespell is added on the command line

Quoted 3 lines
   --codespellfile            Use this codespell dictionary
   --typedefsfile             Read additional types from this file
   --color[=WHEN]             Use colors 'always', 'never', or only when output
#2 lore raw

Hi Joe,

Quoted 8 lines · Joe Perches
Quoted 5 lines · Peter Ujfalusi

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:

If you enable it by default, you probably are using a .checkpatch.conf file.

It is enabled via a commit hook and started to fail after codespell update to 2.1 (when the /usr/share/codespell/dictionary.txt no longer exist)

This is downstream port of checkpatch.pl in sof:
https://thesofproject.github.io

If I would have enabled it locally I would have also specified the codespellfile in .checkpatch.conf.

Quoted 2 lines

--codespell is not a typical default so I think always doing this test regardless of --codespell being enabled is inappropriate.

I tend to agree.

Quoted 15 lines

scripts/checkpatch.pl

Quoted 1 line
scripts/checkpatch.pl +0 -0

[]

scripts/checkpatch.pl my $git_command ='export LANGUAGE=en_US.UTF-8; git'; · line 81

Quoted 10 lines
scripts/checkpatch.pl +6 -0
@@ -73,6 +73,12 @@ my $git_command ='export LANGUAGE=en_US.UTF-8; git';
  my $tabsize = 8;
  my ${CONFIG_} = "CONFIG_";
 
+# Override the codespellfile location based on codespell install location
+if (which("codespell") ne "" && which("python") ne "") {
+	my $codespell_dict = `python -c "import os.path as op; import codespell_lib; print(op.join(op.dirname(codespell_lib.__file__), 'data', 'dictionary.txt'), end='')" 2> /dev/null`;
+	$codespellfile = $codespell_dict if (-e $codespell_dict);
+}
+

Maybe add a function and/or use something like:

Quoted 2 lines
	if (($codespell || $help) &&
	    which(etc...

Right, so I will move the check after the GetOptions() to have the $codespell and $help options evaluated.

Quoted 4 lines
Quoted 4 lines
scripts/checkpatch.pl +0 -0
  sub help {
  	my ($exitcode) = @_;

Quoted 9 lines

scripts/checkpatch.pl Options: · line 139

Quoted 6 lines
scripts/checkpatch.pl +0 -0
@@ -130,7 +136,7 @@ Options:

   --ignore-perl-version override checking of perl version. expect
                              runtime errors.
   --codespell Use the codespell dictionary for spelling/typos

scripts/checkpatch.pl +1 -1
-                             (default:/usr/share/codespell/dictionary.txt)
+                             (default:$codespellfile)

I think this should not be changed or only be shown as $codespellfile when --codespell is added on the command line

If I run the 'scripts/checkpatch.pl -h' I would like to see the options and defaults that will be used and I don't expect that the default of the dictionary.tx would be different between

scripts/checkpatch.pl -h
default:/usr/share/codespell/dictionary.txt)

scripts/checkpatch.pl --codespell -h
(default:/usr/lib/python3.9/site-packages/codespell_lib/data/dictionary.txt)

I think this is not too intuitive.

Now I have a working and consistent version, let's see how that looks like.

Quoted 6 lines
Quoted 4 lines
   --codespellfile            Use this codespell dictionary
   --typedefsfile             Read additional types from this file
   --color[=WHEN]             Use colors 'always', 'never', or only when output
Signature · 1 line
Péter