From patchwork Tue Jul 4 14:16:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Stringer X-Patchwork-Id: 784016 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3x25gn2ywkz9t1y for ; Wed, 5 Jul 2017 00:17:57 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 17A4AAA6; Tue, 4 Jul 2017 14:17:54 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 8BCC7A91 for ; Tue, 4 Jul 2017 14:17:52 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id E5F1A198 for ; Tue, 4 Jul 2017 14:17:51 +0000 (UTC) Received: from mfilter39-d.gandi.net (mfilter39-d.gandi.net [217.70.178.170]) by relay5-d.mail.gandi.net (Postfix) with ESMTP id 3BA7941C0A1; Tue, 4 Jul 2017 16:17:50 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at mfilter39-d.gandi.net Received: from relay5-d.mail.gandi.net ([IPv6:::ffff:217.70.183.197]) by mfilter39-d.gandi.net (mfilter39-d.gandi.net [::ffff:10.0.15.180]) (amavisd-new, port 10024) with ESMTP id aDI9ICG9IhhY; Tue, 4 Jul 2017 16:17:48 +0200 (CEST) X-Originating-IP: 193.136.225.129 Received: from localhost.localdomain (unknown [193.136.225.129]) (Authenticated sender: joe@ovn.org) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id 03CC541C0F2; Tue, 4 Jul 2017 16:17:35 +0200 (CEST) From: Joe Stringer To: dev@openvswitch.org Date: Tue, 4 Jul 2017 07:16:46 -0700 Message-Id: <20170704141646.5274-1-joe@ovn.org> X-Mailer: git-send-email 2.12.2 X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH] checkpatch: Use default encoding from email library. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org 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 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 Acked-by: Ben Pfaff --- utilities/checkpatch.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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))