public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Dwaipayan Ray <dwaipayanray1@gmail.com>
To: joe@perches.com
Cc: linux-kernel@vger.kernel.org, lukas.bulwahn@gmail.com,
	Dwaipayan Ray <dwaipayanray1@gmail.com>
Subject: [PATCH v2] checkpatch: auto detect codespell dictionary path
Date: Tue, 11 May 2021 19:35:22 +0530	[thread overview]
Message-ID: <20210511140522.3253-1-dwaipayanray1@gmail.com> (raw)

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.

Signed-off-by: Dwaipayan Ray <dwaipayanray1@gmail.com>
---

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(+)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 23697a6b1eaa..4b1994bb443e 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -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 = $_;
-- 
2.28.0


                 reply	other threads:[~2021-05-11 14:05 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210511140522.3253-1-dwaipayanray1@gmail.com \
    --to=dwaipayanray1@gmail.com \
    --cc=joe@perches.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lukas.bulwahn@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox