diff mbox

[ovs-dev] checkpatch: Use default encoding from email library.

Message ID 20170704141646.5274-1-joe@ovn.org
State Accepted
Headers show

Commit Message

Joe Stringer July 4, 2017, 2:16 p.m. UTC
There are three paths for running the core checkpatch path: From a file,
from stdin, or reading from git output. Currently, the file version of
this calls the "email" library's decode routine which translates the
stream into a bytes array, which we later call decode() to turn it back
into a regular string. This works on python2 and python3, but the other
paths don't work in python3 due to the following error:

$ utilities/checkpatch.py -1
== Checking HEAD~0 ==
Traceback (most recent call last):
  File "utilities/checkpatch.py", line 491, in <module>
    if ovs_checkpatch_parse(patch, revision):
  File "utilities/checkpatch.py", line 324, in ovs_checkpatch_parse
    for line in text.decode().split('\n'):
AttributeError: 'str' object has no attribute 'decode'

Rather than performing this extra encode/decode, strip these out from
this path so that the stdin and git variants of checkpatch can work in
python3.

Signed-off-by: Joe Stringer <joe@ovn.org>
---
 utilities/checkpatch.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Ben Pfaff July 6, 2017, 12:26 a.m. UTC | #1
On Tue, Jul 04, 2017 at 07:16:46AM -0700, Joe Stringer wrote:
> There are three paths for running the core checkpatch path: From a file,
> from stdin, or reading from git output. Currently, the file version of
> this calls the "email" library's decode routine which translates the
> stream into a bytes array, which we later call decode() to turn it back
> into a regular string. This works on python2 and python3, but the other
> paths don't work in python3 due to the following error:
> 
> $ utilities/checkpatch.py -1
> == Checking HEAD~0 ==
> Traceback (most recent call last):
>   File "utilities/checkpatch.py", line 491, in <module>
>     if ovs_checkpatch_parse(patch, revision):
>   File "utilities/checkpatch.py", line 324, in ovs_checkpatch_parse
>     for line in text.decode().split('\n'):
> AttributeError: 'str' object has no attribute 'decode'
> 
> Rather than performing this extra encode/decode, strip these out from
> this path so that the stdin and git variants of checkpatch can work in
> python3.
> 
> Signed-off-by: Joe Stringer <joe@ovn.org>

I didn't test this but it sounds reasonable to me.

Acked-by: Ben Pfaff <blp@ovn.org>
Joe Stringer July 6, 2017, 12:47 p.m. UTC | #2
On 5 July 2017 at 17:26, Ben Pfaff <blp@ovn.org> wrote:
> On Tue, Jul 04, 2017 at 07:16:46AM -0700, Joe Stringer wrote:
>> There are three paths for running the core checkpatch path: From a file,
>> from stdin, or reading from git output. Currently, the file version of
>> this calls the "email" library's decode routine which translates the
>> stream into a bytes array, which we later call decode() to turn it back
>> into a regular string. This works on python2 and python3, but the other
>> paths don't work in python3 due to the following error:
>>
>> $ utilities/checkpatch.py -1
>> == Checking HEAD~0 ==
>> Traceback (most recent call last):
>>   File "utilities/checkpatch.py", line 491, in <module>
>>     if ovs_checkpatch_parse(patch, revision):
>>   File "utilities/checkpatch.py", line 324, in ovs_checkpatch_parse
>>     for line in text.decode().split('\n'):
>> AttributeError: 'str' object has no attribute 'decode'
>>
>> Rather than performing this extra encode/decode, strip these out from
>> this path so that the stdin and git variants of checkpatch can work in
>> python3.
>>
>> Signed-off-by: Joe Stringer <joe@ovn.org>
>
> I didn't test this but it sounds reasonable to me.
>
> Acked-by: Ben Pfaff <blp@ovn.org>

Thanks, applied.
diff mbox

Patch

diff --git a/utilities/checkpatch.py b/utilities/checkpatch.py
index b45a255ceb4b..dbbab3d11021 100755
--- a/utilities/checkpatch.py
+++ b/utilities/checkpatch.py
@@ -320,7 +320,7 @@  def ovs_checkpatch_parse(text, filename):
     is_co_author = re.compile(r'(\s*(Co-authored-by: )(.*))$',
                               re.I | re.M | re.S)
 
-    for line in text.decode(errors='ignore').split('\n'):
+    for line in text.split('\n'):
         if current_file != previous_file:
             previous_file = current_file
 
@@ -418,7 +418,7 @@  def ovs_checkpatch_file(filename):
     for part in mail.walk():
         if part.get_content_maintype() == 'multipart':
             continue
-    result = ovs_checkpatch_parse(part.get_payload(decode=True), filename)
+    result = ovs_checkpatch_parse(part.get_payload(decode=False), filename)
     if result < 0:
         print("Lines checked: %d, Warnings: %d, Errors: %d" %
               (total_line, __warnings, __errors))