From patchwork Thu Jul 4 09:35:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 1602 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 01DA560B2D for ; Thu, 4 Jul 2019 11:35:05 +0200 (CEST) Received: from localhost.localdomain (cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 70EA524B; Thu, 4 Jul 2019 11:35:05 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1562232905; bh=IwIwuP7dqWeoVAcx4ggJAjevj4NU+aLBXRKK8aR0n8k=; h=From:To:Cc:Subject:Date:From; b=rqXYMyAI9zSE63vccx64232D0rzxBLEyaZ7NtPk0to+mK45sM8vxt2vGagonbnx2r lbuTSF2PqLQnePGCWg0FlDI9bpSGUjg79E6ENe1c0RJGEYW+fbbC4RTtaoffs7V2VS hIJbe7MD6EmOyCcELZ6ApitEkPpFjhRcA+/ot8Gw= From: Kieran Bingham To: LibCamera Devel Date: Thu, 4 Jul 2019 10:35:02 +0100 Message-Id: <20190704093502.27448-1-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] utils: checkstyle.py: Add pep8 checker X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 04 Jul 2019 09:35:06 -0000 Process python additions with pep8 and report any errors that are added. Signed-off-by: Kieran Bingham --- utils/checkstyle.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) This checker allows the checkstyle script to self-identify any issue. Isn't that recursivly fun? Todo: - This should not fail if pep8 is not present, and should instead report an issue that pep8 is not installed. - The line_no_regex should ideally be compiled once per class, or globally? But how then do you access a class object from the class instance... - All of the pep8 failures in checkstyle.py should be fixed up ... diff --git a/utils/checkstyle.py b/utils/checkstyle.py index fab4b116d2ff..a960affc71a9 100755 --- a/utils/checkstyle.py +++ b/utils/checkstyle.py @@ -276,6 +276,35 @@ class MesonChecker(StyleChecker): return issues +class Pep8Checker(StyleChecker): + patterns = ('*.py',) + + def __init__(self, content): + super().__init__() + self.__content = content + self.__data = "".join(content).encode('utf-8') + + def check(self, line_numbers): + issues = [] + line_no_regex = re.compile('stdin:([0-9]+):([0-9]+)(.*)') + + ret = subprocess.run(['pep8', '--ignore=E501', '-'], + input=self.__data, stdout=subprocess.PIPE) + + results = ret.stdout.decode('utf-8').splitlines() + for item in results: + search = re.search(line_no_regex, item) + line_number = int(search.group(1)) + position = int(search.group(2)) + msg = search.group(3) + + if line_number in line_numbers: + line = self.__content[line_number - 1] + issues.append(StyleIssue(line_number, line, msg)) + + return issues + + # ------------------------------------------------------------------------------ # Formatters #