Skip to contentSkip to conversation

scripts/spdxcheck.py: make python3 compliant

PATCH In review [email protected] 3 participants 3 messages Nov 17, 2018 – Nov 18, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 14/18 scripts/spdxcheck.py: make python3 compliant

From: Uwe Kleine-König <[email protected]>
Subject: scripts/spdxcheck.py: make python3 compliant

Without this change the following happens when using Python3 (3.6.6):

	$ echo "GPL-2.0" | python3 scripts/spdxcheck.py -
	FAIL: 'str' object has no attribute 'decode'
	Traceback (most recent call last):
	  File "scripts/spdxcheck.py", line 253, in <module>
	    parser.parse_lines(sys.stdin, args.maxlines, '-')
	  File "scripts/spdxcheck.py", line 171, in parse_lines
	    line = line.decode(locale.getpreferredencoding(False), errors='ignore')
	AttributeError: 'str' object has no attribute 'decode'

So as the line is already a string, there is no need to decode it and the line can be dropped.

/usr/bin/python on Arch is Python 3. So this would indeed be worth going into 4.19.

---

scripts/spdxcheck.py renamed from scripts/spdxcheck.py~scripts-spdxcheck-make-python3-compliant +0 -1
@@ -168,7 +168,6 @@ class id_parser(object):
         self.curline = 0
         try:
             for line in fd:
-                line = line.decode(locale.getpreferredencoding(False), errors='ignore')
                 self.curline += 1
                 if self.curline > maxlines:
                     break

_

#1 lore raw
Quoted 14 lines · On Fri, 2018-11-16 at 15:08 -0800, [email protected] wrote:

From: Uwe Kleine-K�nig <[email protected]>
Subject: scripts/spdxcheck.py: make python3 compliant

Without this change the following happens when using Python3 (3.6.6):

	$ echo "GPL-2.0" | python3 scripts/spdxcheck.py -
	FAIL: 'str' object has no attribute 'decode'
	Traceback (most recent call last):
	  File "scripts/spdxcheck.py", line 253, in <module>
	    parser.parse_lines(sys.stdin, args.maxlines, '-')
	  File "scripts/spdxcheck.py", line 171, in parse_lines
	    line = line.decode(locale.getpreferredencoding(False), errors='ignore')
	AttributeError: 'str' object has no attribute 'decode'
Quoted 5 lines

So as the line is already a string, there is no need to decode it and the line can be dropped.

/usr/bin/python on Arch is Python 3. So this would indeed be worth going into 4.19.

OK, I tested this (and it works fine) but found I needed to install a couple of extra packages that I didn't already have for the default python3 installation.

python3-ply and python3-git

Perhaps that should be mentioned in some requirements doc.

In fact, scripts/spdxcheck.py is not mentioned in any doc file.

Quoted 20 lines

---

scripts/spdxcheck.py renamed from scripts/spdxcheck.py~scripts-spdxcheck-make-python3-compliant +0 -1
@@ -168,7 +168,6 @@ class id_parser(object):
         self.curline = 0
         try:
             for line in fd:
-                line = line.decode(locale.getpreferredencoding(False), errors='ignore')
                 self.curline += 1
                 if self.curline > maxlines:
                     break
#2 lore raw
Quoted 25 lines · Joe Perches
Quoted 14 lines · On Fri, 2018-11-16 at 15:08 -0800, [email protected] wrote:

From: Uwe Kleine-K�nig <[email protected]>
Subject: scripts/spdxcheck.py: make python3 compliant

Without this change the following happens when using Python3 (3.6.6):

	$ echo "GPL-2.0" | python3 scripts/spdxcheck.py -
	FAIL: 'str' object has no attribute 'decode'
	Traceback (most recent call last):
	  File "scripts/spdxcheck.py", line 253, in <module>
	    parser.parse_lines(sys.stdin, args.maxlines, '-')
	  File "scripts/spdxcheck.py", line 171, in parse_lines
	    line = line.decode(locale.getpreferredencoding(False), errors='ignore')
	AttributeError: 'str' object has no attribute 'decode'
Quoted 5 lines

So as the line is already a string, there is no need to decode it and the line can be dropped.

/usr/bin/python on Arch is Python 3. So this would indeed be worth going into 4.19.

OK, I tested this (and it works fine) but found I needed to install a couple of extra packages that I didn't already have for the default python3 installation.

Quoted 5 lines

python3-ply and python3-git

Perhaps that should be mentioned in some requirements doc.

In fact, scripts/spdxcheck.py is not mentioned in any doc file.

In fact I tried to run spdxcheck with python3 becaus I didn't have python-ply and python-git which don't come with python2 :-)

Best regards
Uwe

Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-K�nig            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |