Skip to contentSkip to conversation

checkpatch: scripts/spdxcheck.py now requires python3

PATCH Applied Guenter Roeck 2 participants 2 messages May 5, 2021 Checkpatch

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 checkpatch: scripts/spdxcheck.py now requires python3

Since commit d0259c42abff ("spdxcheck.py: Use Python 3"), spdxcheck.py explicitly expects to run as python3 script. If "python" still points to python v2.7 and the script is executed with "python scripts/spdxcheck.py", the following error may be seen even if git-python is installed for python3.

Traceback (most recent call last):
File "scripts/spdxcheck.py", line 10, in <module>
import git
ImportError: No module named git

To fix the problem, check for the existence of python3, check if the script is executable and not just for its existence, and execute it directly.

---
 scripts/checkpatch.pl | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
scripts/checkpatch.pl +2 -2
index ccb412a74725..8a1b782dd7e7 100755
@@ -1084,10 +1084,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 "$gitroot"));
+	return 1 if (!$tree || which("python3") eq "" || !(-x "$root/scripts/spdxcheck.py") || !(-e "$gitroot"));
 
 	my $root_path = abs_path($root);
-	my $status = `cd "$root_path"; echo "$license" | python scripts/spdxcheck.py -`;
+	my $status = `cd "$root_path"; echo "$license" | scripts/spdxcheck.py -`;
 	return 0 if ($status ne "");
 	return 1;
 }
Signature · 1 line
2.25.1
maintainer
#1 lore raw
Quoted 11 lines · Guenter Roeck

Since commit d0259c42abff ("spdxcheck.py: Use Python 3"), spdxcheck.py explicitly expects to run as python3 script. If "python" still points to python v2.7 and the script is executed with "python scripts/spdxcheck.py", the following error may be seen even if git-python is installed for python3.

Traceback (most recent call last):
  File "scripts/spdxcheck.py", line 10, in <module> import git
ImportError: No module named git

Quoted 6 lines

To fix the problem, check for the existence of python3, check if the script is executable and not just for its existence, and execute it directly.

Seems sensible, thanks.

Quoted 23 lines

---
 scripts/checkpatch.pl | 4 ++--

 1 file changed, 2 insertions(+), 2 deletions(-)
scripts/checkpatch.pl +0 -0
index ccb412a74725..8a1b782dd7e7 100755
@@ -1084,10 +1084,10 @@ sub is_maintained_obsolete {
  sub is_SPDX_License_valid {
  	my ($license) = @_;

scripts/checkpatch.pl +1 -1
-	return 1 if (!$tree || which("python") eq "" || !(-e "$root/scripts/spdxcheck.py") || !(-e "$gitroot"));
+	return 1 if (!$tree || which("python3") eq "" || !(-x "$root/scripts/spdxcheck.py") || !(-e "$gitroot"));

  my $root_path = abs_path($root);

scripts/checkpatch.pl +1 -1
-	my $status = `cd "$root_path"; echo "$license" | python scripts/spdxcheck.py -`;
+	my $status = `cd "$root_path"; echo "$license" | scripts/spdxcheck.py -`;

  return 0 if ($status ne "");
  return 1;
 }