[PATCH] checkpatch: Allow users to specify the python command to use

From: Palmer Dabbelt
Date: Tue Apr 21 2020 - 13:39:30 EST


From: Palmer Dabbelt <palmerdabbelt@xxxxxxxxxx>

checkpatch.pl invokes spdxcheck.py using "python". On my system that's
Python 2, but I only have a git package for Python 3. This patch adds a
"--python=..." argument to checkpatch.pl that allows users to specify a
command to invoke Python. I've just given this a little smoke test:
running it without any arguments still works, and running with
--python=python3 finds the git module.

Signed-off-by: Palmer Dabbelt <palmerdabbelt@xxxxxxxxxx>

---
I'd considered reading some sort of environment variable, but searching
for "getenv" in checkpatch.pl didn't reveal any other enviornment
variables so I figured it'd be cleaner to avoid adding one. I only
invoke checkpatch.pl from wrapper scripts anyway, so it's the same for
me.
---
scripts/checkpatch.pl | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index d64c67b67e3c..05ce52a2aaa9 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -65,6 +65,7 @@ my $allow_c99_comments = 1; # Can be overridden by --ignore C99_COMMENT_TOLERANC
# git output parsing needs US English output, so first set backtick child process LANGUAGE
my $git_command ='export LANGUAGE=en_US.UTF-8; git';
my $tabsize = 8;
+my $python = "python";

sub help {
my ($exitcode) = @_;
@@ -125,6 +126,7 @@ Options:
--typedefsfile Read additional types from this file
--color[=WHEN] Use colors 'always', 'never', or only when output
is a terminal ('auto'). Default is 'auto'.
+ --python=COMMAND Use the give command to invoke python.
-h, --help, --version display this help and exit

When FILE is - read standard input.
@@ -233,6 +235,7 @@ GetOptions(
'color=s' => \$color,
'no-color' => \$color, #keep old behaviors of -nocolor
'nocolor' => \$color, #keep old behaviors of -nocolor
+ 'python=s' => \$python,
'h|help' => \$help,
'version' => \$help
) or help(1);
@@ -897,10 +900,10 @@ sub is_maintained_obsolete {
sub is_SPDX_License_valid {
my ($license) = @_;

- return 1 if (!$tree || which("python") eq "" || !(-e "$root/scripts/spdxcheck.py") || !(-e "$root/.git"));
+ return 1 if (!$tree || which($python) eq "" || !(-e "$root/scripts/spdxcheck.py") || !(-e "$root/.git"));

my $root_path = abs_path($root);
- my $status = `cd "$root_path"; echo "$license" | python scripts/spdxcheck.py -`;
+ my $status = `cd "$root_path"; echo "$license" | $python scripts/spdxcheck.py -`;
return 0 if ($status ne "");
return 1;
}
--
2.26.1.301.g55bc3eb7cb9-goog