From patchwork Thu Jul 4 15:06:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 1620 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 DE4DE61569 for ; Thu, 4 Jul 2019 17:07:02 +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 6F4E324B; Thu, 4 Jul 2019 17:07:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1562252822; bh=oMftc4m+KDvWvCpDtRRHXVfM7xwXSAtIsNeRa9bbwo0=; h=From:To:Cc:Subject:Date:From; b=ev+lvf6N+wD/L1IaLzfM4lHlfxtunMDyBkn7rvGwoTuoQNoGzJE2BoXEq9NEuVPFE 1XYEUeBoi6tctvdmsii1c1+Q3cw34JoRtIxjJaGN7NaEQPk12cVBmJxt53GUMXjer8 5WqvXi4OcDnj8BoJmR2Mvm9tSlyovti8fdYrBiWU= From: Kieran Bingham To: LibCamera Devel Date: Thu, 4 Jul 2019 16:06:58 +0100 Message-Id: <20190704150658.18809-1-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2] 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 15:07:03 -0000 Process python additions with pep8 and report any errors that are added. Signed-off-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- v2: - Now catches if pep8 is not available - line_no_regex renamed to results_regex and contained in Pep8Checker class - Single quotes used instead of double quotes - 'data' moved to local variable instance of class instance --- utils/checkstyle.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/utils/checkstyle.py b/utils/checkstyle.py index fab4b116d2ff..c5ecdc12112b 100755 --- a/utils/checkstyle.py +++ b/utils/checkstyle.py @@ -276,6 +276,39 @@ class MesonChecker(StyleChecker): return issues +class Pep8Checker(StyleChecker): + patterns = ('*.py',) + results_regex = re.compile('stdin:([0-9]+):([0-9]+)(.*)') + + def __init__(self, content): + super().__init__() + self.__content = content + + def check(self, line_numbers): + issues = [] + data = ''.join(self.__content).encode('utf-8') + + try: + ret = subprocess.run(['pep8', '--ignore=E501', '-'], + input=data, stdout=subprocess.PIPE) + except FileNotFoundError: + issues.append(StyleIssue(0, '', "Please install pep8 to validate python additions")) + return issues + + results = ret.stdout.decode('utf-8').splitlines() + for item in results: + search = re.search(Pep8Checker.results_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 #