* [PATCH] checkpatch: auto detect codespell dictionary path
@ 2021-05-10 17:11 Dwaipayan Ray
2021-05-10 17:39 ` Joe Perches
0 siblings, 1 reply; 3+ messages in thread
From: Dwaipayan Ray @ 2021-05-10 17:11 UTC (permalink / raw)
To: joe; +Cc: linux-kernel, lukas.bulwahn, Dwaipayan Ray
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>
---
scripts/checkpatch.pl | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 23697a6b1eaa..cc69d2c758a3 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("python3") ne "") {
+ my $output = `python3 -c "import codespell_lib; print(codespell_lib.__file__, end='');" 2>/dev/null`;
+ my $dictionary_path = dirname($output) . "/data/dictionary.txt";
+ if (-e "$dictionary_path") {
+ $codespellfile = $dictionary_path;
+ }
+ }
if (open(my $spelling, '<', $codespellfile)) {
while (<$spelling>) {
my $line = $_;
--
2.28.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] checkpatch: auto detect codespell dictionary path
2021-05-10 17:11 [PATCH] checkpatch: auto detect codespell dictionary path Dwaipayan Ray
@ 2021-05-10 17:39 ` Joe Perches
2021-05-10 17:54 ` Dwaipayan Ray
0 siblings, 1 reply; 3+ messages in thread
From: Joe Perches @ 2021-05-10 17:39 UTC (permalink / raw)
To: Dwaipayan Ray; +Cc: linux-kernel, lukas.bulwahn
On Mon, 2021-05-10 at 22:41 +0530, Dwaipayan Ray wrote:
> 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.
[]
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
[]
> @@ -889,6 +889,13 @@ if (open(my $spelling, '<', $spelling_file)) {
> }
>
>
> if ($codespell) {
> + if (! -e "$codespellfile" && which("python3") ne "") {
> + my $output = `python3 -c "import codespell_lib; print(codespell_lib.__file__, end='');" 2>/dev/null`;
It doesn't seem to me that using python3 is a great way to invoke python.
Maybe test the external command return $? when codespell isn't installed.
> + my $dictionary_path = dirname($output) . "/data/dictionary.txt";
Unlikely, but this could still end up with a existing file of /data/dictionary.txt
that is not a codespell file.
> + if (-e "$dictionary_path") {
> + $codespellfile = $dictionary_path;
> + }
> + }
> if (open(my $spelling, '<', $codespellfile)) {
> while (<$spelling>) {
> my $line = $_;
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] checkpatch: auto detect codespell dictionary path
2021-05-10 17:39 ` Joe Perches
@ 2021-05-10 17:54 ` Dwaipayan Ray
0 siblings, 0 replies; 3+ messages in thread
From: Dwaipayan Ray @ 2021-05-10 17:54 UTC (permalink / raw)
To: Joe Perches; +Cc: linux-kernel, Lukas Bulwahn
On Mon, May 10, 2021 at 11:09 PM Joe Perches <joe@perches.com> wrote:
>
> On Mon, 2021-05-10 at 22:41 +0530, Dwaipayan Ray wrote:
> > 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.
> []
> > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> []
> > @@ -889,6 +889,13 @@ if (open(my $spelling, '<', $spelling_file)) {
> > }
> >
> >
> > if ($codespell) {
> > + if (! -e "$codespellfile" && which("python3") ne "") {
> > + my $output = `python3 -c "import codespell_lib; print(codespell_lib.__file__, end='');" 2>/dev/null`;
>
> It doesn't seem to me that using python3 is a great way to invoke python.
> Maybe test the external command return $? when codespell isn't installed.
Sure, I will add that.
>
> > + my $dictionary_path = dirname($output) . "/data/dictionary.txt";
>
> Unlikely, but this could still end up with a existing file of /data/dictionary.txt
> that is not a codespell file.
>
So does testing for the return status give us some guarantee here? The
dictionary
path should be relative to the codespell_lib directory, that's what
the codespell
people writes.
> > + if (-e "$dictionary_path") {
> > + $codespellfile = $dictionary_path;
> > + }
> > + }
> > if (open(my $spelling, '<', $codespellfile)) {
> > while (<$spelling>) {
> > my $line = $_;
>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-05-10 17:54 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-10 17:11 [PATCH] checkpatch: auto detect codespell dictionary path Dwaipayan Ray
2021-05-10 17:39 ` Joe Perches
2021-05-10 17:54 ` Dwaipayan Ray
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).