Skip to contentSkip to conversation

checkpatch: auto detect codespell dictionary path

PATCH New Dwaipayan Ray 1 participant 1 message May 11, 2021 Checkpatch

lore
Share & tools
lore
#0 lore raw

PATCH v2 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.

---

Changes in v2:
- Check the external command return code to handle the case when codespell isn't installed.
- Use python to invoke the interpreter rather than python3

 scripts/checkpatch.pl | 7 +++++++
 1 file changed, 7 insertions(+)
scripts/checkpatch.pl +7 -0
index 23697a6b1eaa..4b1994bb443e 100755
@@ -889,6 +889,13 @@ if (open(my $spelling, '<', $spelling_file)) {
 }
 
 if ($codespell) {
+	if (! -e "$codespellfile" && which("python") ne "" &&
+	    `python -c "import sys; print(sys.version_info.major)"` >= "3") {
+		my $output = `python -c "import codespell_lib; print(codespell_lib.__file__);" 2>/dev/null`;
+		if ($? == 0) {
+			$codespellfile = dirname($output) . "/data/dictionary.txt";
+		}
+	}
 	if (open(my $spelling, '<', $codespellfile)) {
 		while (<$spelling>) {
 			my $line = $_;
Signature · 1 line
2.28.0