From nobody Sat May 18 09:01:25 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1622826103; cv=none; d=zohomail.com; s=zohoarc; b=LuHI9oYsBSZIx2zoWz1OVsGf5XTT+ZEf3C82U4Ce/YHKIz7Pl9M6Qz75R2gbnbSoNQdvvkybBGHCc8nAzn4rbzzP5dZlQV7bath18WyEtwu65nhHwTGggj/ExyCa71v7N8pVsFZvhvtenc/VRecpqCWDuCFXflinrJgMnSeWz1A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622826103; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=a3IM2q0LzgrouGp2vGThiaRl54X+krhSSpSKs3IzzDM=; b=NW7ted6/jP0fbU2CzPoaiMjYtfs4yM0BVFcGokeuqtmFSXCiREKujoRwgP57DRs7PCH0QxllXHqm+m9yFi0MlcEaJamcgMaIzR+2QHrM1CueSLshEEvsg5Xs1X4am4PIzn4Sda5/NG0bGobi52OEXkowt8Mq1/d9nuGhANUyHPI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1622826102995797.7592943481982; Fri, 4 Jun 2021 10:01:42 -0700 (PDT) Received: from localhost ([::1]:42484 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lpDCX-0006WN-W9 for importer@patchew.org; Fri, 04 Jun 2021 13:01:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37148) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lpCqt-00055h-7c for qemu-devel@nongnu.org; Fri, 04 Jun 2021 12:39:19 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:58793) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lpCqp-000585-IA for qemu-devel@nongnu.org; Fri, 04 Jun 2021 12:39:18 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-20-hHziJ7YjNiu8NXH_vFVvOg-1; Fri, 04 Jun 2021 12:39:11 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7A6CC803624; Fri, 4 Jun 2021 16:39:10 +0000 (UTC) Received: from scv.redhat.com (ovpn-116-137.rdu2.redhat.com [10.10.116.137]) by smtp.corp.redhat.com (Postfix) with ESMTP id 71C3419D61; Fri, 4 Jun 2021 16:39:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1622824755; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=a3IM2q0LzgrouGp2vGThiaRl54X+krhSSpSKs3IzzDM=; b=h8PAcUJubjvsB3O1va/Bub/Jm0fFIdJpbPrhhZXoi21/rpuiPJpPgaK5EnmIIP265d4WUO pDYJrQ1Bj4Qv3BRXCYTWaXSlrPOM09UWMRbALduyVdzahDMhJLCH49DZ/wlBL3+eoKBkzn dtep+vITWaSfSPSTRdMxviAjYYcXfZM= X-MC-Unique: hHziJ7YjNiu8NXH_vFVvOg-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH RFC 1/3] python: expose typing information via PEP 561 Date: Fri, 4 Jun 2021 12:39:05 -0400 Message-Id: <20210604163907.1511224-2-jsnow@redhat.com> In-Reply-To: <20210604163907.1511224-1-jsnow@redhat.com> References: <20210604163907.1511224-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.373, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , Eduardo Habkost , qemu-block@nongnu.org, Markus Armbruster , Max Reitz , Cleber Rosa , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Create 'py.typed' files in each subpackage that indicate to mypy that this is a typed module, so that users of any of these packages can use mypy to check their code as well. (Note: theoretically it's possible to ditch MANIFEST.in in favor of using package_data, but I genuinely could not figure out how to get it to include things from the source root into the package root. I tried!...) https: //www.python.org/dev/peps/pep-0561/#specification Signed-off-by: John Snow --- python/qemu/machine/py.typed | 0 python/qemu/qmp/py.typed | 0 python/qemu/utils/py.typed | 0 python/setup.cfg | 3 +++ 4 files changed, 3 insertions(+) create mode 100644 python/qemu/machine/py.typed create mode 100644 python/qemu/qmp/py.typed create mode 100644 python/qemu/utils/py.typed diff --git a/python/qemu/machine/py.typed b/python/qemu/machine/py.typed new file mode 100644 index 0000000000..e69de29bb2 diff --git a/python/qemu/qmp/py.typed b/python/qemu/qmp/py.typed new file mode 100644 index 0000000000..e69de29bb2 diff --git a/python/qemu/utils/py.typed b/python/qemu/utils/py.typed new file mode 100644 index 0000000000..e69de29bb2 diff --git a/python/setup.cfg b/python/setup.cfg index 0fcdec6f32..a1f9e9d76d 100644 --- a/python/setup.cfg +++ b/python/setup.cfg @@ -37,6 +37,9 @@ devel =3D pylint >=3D 2.8.0 tox >=3D 3.18.0 =20 +[options.package_data] +* =3D py.typed + [flake8] extend-ignore =3D E722 # Prefer pylint's bare-except checks to flake8's exclude =3D __pycache__, --=20 2.31.1 From nobody Sat May 18 09:01:25 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1622827700; cv=none; d=zohomail.com; s=zohoarc; b=RQ2DcLWgZ+ntwr2owCfwhP9tKqPNgOa+HsaenuDLHJHrqbkcmE3krJjyDQu1wWSgFCFnK0y09f1GNGT2lRfS199CwhFwiucwzO9z+rVDbk+Ghl1kvamumUnVtXLcV4E+X55+tXqXFCery6Los5fCde78QO784lUvm5KP9FIWasM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622827700; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=uFDz24qq6jVReAegG1rk9pzB53tPt+tnOVWWIqxD0mY=; b=lfexlV1OnZ9+3zTHKewthpz9EMl/v6aceShqg38uoMWqHORZnyqOKpAiGUQQb/M513TeENjQ377YX7wiQ9z7M7LriiCbCfdJcJZuJ9yIYXJDh6ledOYzMPp3AH20lzV73S8A/dNbPHthh/YeCz3p0dkBuosBnHYquzH92pZySLE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1622827700664864.6345140788278; Fri, 4 Jun 2021 10:28:20 -0700 (PDT) Received: from localhost ([::1]:50174 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lpDcJ-0003h9-Hn for importer@patchew.org; Fri, 04 Jun 2021 13:28:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37158) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lpCqu-00056K-2R for qemu-devel@nongnu.org; Fri, 04 Jun 2021 12:39:20 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:22581) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lpCqq-000591-Kz for qemu-devel@nongnu.org; Fri, 04 Jun 2021 12:39:19 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-249-wOPE7NYwNmeVyetz1cM04A-1; Fri, 04 Jun 2021 12:39:13 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1A8DA8015F8; Fri, 4 Jun 2021 16:39:12 +0000 (UTC) Received: from scv.redhat.com (ovpn-116-137.rdu2.redhat.com [10.10.116.137]) by smtp.corp.redhat.com (Postfix) with ESMTP id A17CB19D61; Fri, 4 Jun 2021 16:39:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1622824755; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uFDz24qq6jVReAegG1rk9pzB53tPt+tnOVWWIqxD0mY=; b=JR99DmL7wW2JnMjQjRAduIbV+xMVVZJMEIh93lWoHgjhGbgcCvoeODEiXIBELfqxVHKamF EzC430b2wTHk1kALPIEGVgxAAZGTgdfEiiIplgpw9fhxnJItWNez0ZDtHUYnZKGicbsj30 RtAnfkNCu/7M5GQe7Qfn7gDnkw7ayoI= X-MC-Unique: wOPE7NYwNmeVyetz1cM04A-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH RFC 2/3] iotests: split 'linters.py' off from 297 Date: Fri, 4 Jun 2021 12:39:06 -0400 Message-Id: <20210604163907.1511224-3-jsnow@redhat.com> In-Reply-To: <20210604163907.1511224-1-jsnow@redhat.com> References: <20210604163907.1511224-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.373, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , Eduardo Habkost , qemu-block@nongnu.org, Markus Armbruster , Max Reitz , Cleber Rosa , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Refactor the core function of the linting configuration out of 297 and into a new file called linters.py. Now, linters.py represents an invocation of the linting scripts that more resembles a "normal" execution of pylint/mypy, like you'd expect to use if 'qemu' was a bona-fide package you obtained from PyPI. 297, by contrast, now represents the iotests-specific configuration bits you need to get it to function correctly as a part of iotests, and with 'qemu' as a namespace package that isn't "installed" to the current environment, but just lives elsewhere in our source tree. By doing this, we will able to run the same linting configuration from the Python CI tests without calling iotest logging functions or messing around with PYTHONPATH / MYPYPATH. iotest 297 continues to operate in a standalone fashion for now -- presumably, it's convenient for block maintainers and contributors to run in this manner. See the following commit for how this is used from the Python packaging sid= e. Signed-off-by: John Snow --- - It's a big glob of a patch. Sorry. I can work it into smaller pieces if the idea is well received. - I change the invocations of mypy/pylint to "python3 -m pylint" and "python3 -m mypy" respectively, which causes these linters to use the virtual environment's preferred version. This forces the test to use the test environments curated by the CI jobs. - If you have installed Fedora's pylint package that provides "pylint-3", the above trick will still work correctly. - Checking for "pylint-3" specifically in 297 was left alone. Theoretically, this check could be broadened to simply look for the presence of a 'pylint' module to allow it to be more permissive. Signed-off-by: John Snow --- tests/qemu-iotests/297 | 88 ++++------------------- tests/qemu-iotests/linters.py | 130 ++++++++++++++++++++++++++++++++++ 2 files changed, 143 insertions(+), 75 deletions(-) create mode 100644 tests/qemu-iotests/linters.py diff --git a/tests/qemu-iotests/297 b/tests/qemu-iotests/297 index 433b732336..5c753279fc 100755 --- a/tests/qemu-iotests/297 +++ b/tests/qemu-iotests/297 @@ -17,98 +17,36 @@ # along with this program. If not, see . =20 import os -import re import shutil -import subprocess -import sys =20 import iotests +import linters =20 =20 -# TODO: Empty this list! -SKIP_FILES =3D ( - '030', '040', '041', '044', '045', '055', '056', '057', '065', '093', - '096', '118', '124', '132', '136', '139', '147', '148', '149', - '151', '152', '155', '163', '165', '169', '194', '196', '199', '202', - '203', '205', '206', '207', '208', '210', '211', '212', '213', '216', - '218', '219', '222', '224', '228', '234', '235', '236', '237', '238', - '240', '242', '245', '246', '248', '255', '256', '257', '258', '260', - '262', '264', '266', '274', '277', '280', '281', '295', '296', '298', - '299', '302', '303', '304', '307', - 'nbd-fault-injector.py', 'qcow2.py', 'qcow2_format.py', 'qed.py' -) - - -def is_python_file(filename): - if not os.path.isfile(filename): - return False - - if filename.endswith('.py'): - return True - - with open(filename) as f: - try: - first_line =3D f.readline() - return re.match('^#!.*python', first_line) is not None - except UnicodeDecodeError: # Ignore binary files - return False - - -def run_linters(): - files =3D [filename for filename in (set(os.listdir('.')) - set(SKIP_F= ILES)) - if is_python_file(filename)] +def main(): + files =3D linters.get_test_files() =20 iotests.logger.debug('Files to be checked:') iotests.logger.debug(', '.join(sorted(files))) =20 - print('=3D=3D=3D pylint =3D=3D=3D') - sys.stdout.flush() - - # Todo notes are fine, but fixme's or xxx's should probably just be - # fixed (in tests, at least) env =3D os.environ.copy() - qemu_module_path =3D os.path.join(os.path.dirname(__file__), - '..', '..', 'python') + qemu_module_path =3D os.path.join( + os.path.dirname(__file__), + '..', '..', 'python' + ) + try: env['PYTHONPATH'] +=3D os.pathsep + qemu_module_path except KeyError: env['PYTHONPATH'] =3D qemu_module_path - subprocess.run(('pylint-3', '--score=3Dn', '--notes=3DFIXME,XXX', *fil= es), - env=3Denv, check=3DFalse) =20 - print('=3D=3D=3D mypy =3D=3D=3D') - sys.stdout.flush() - - # We have to call mypy separately for each file. Otherwise, it - # will interpret all given files as belonging together (i.e., they - # may not both define the same classes, etc.; most notably, they - # must not both define the __main__ module). env['MYPYPATH'] =3D env['PYTHONPATH'] - for filename in files: - p =3D subprocess.run(('mypy', - '--warn-unused-configs', - '--disallow-subclassing-any', - '--disallow-any-generics', - '--disallow-incomplete-defs', - '--disallow-untyped-decorators', - '--no-implicit-optional', - '--warn-redundant-casts', - '--warn-unused-ignores', - '--no-implicit-reexport', - '--namespace-packages', - filename), - env=3Denv, - check=3DFalse, - stdout=3Dsubprocess.PIPE, - stderr=3Dsubprocess.STDOUT, - universal_newlines=3DTrue) =20 - if p.returncode !=3D 0: - print(p.stdout) + for linter in ('pylint-3', 'mypy'): + if shutil.which(linter) is None: + iotests.notrun(f'{linter} not found') =20 + iotests.script_main(lambda: linters.run_linters(files, env=3Denv)) =20 -for linter in ('pylint-3', 'mypy'): - if shutil.which(linter) is None: - iotests.notrun(f'{linter} not found') =20 -iotests.script_main(run_linters) +main() diff --git a/tests/qemu-iotests/linters.py b/tests/qemu-iotests/linters.py new file mode 100644 index 0000000000..1bbcfd1088 --- /dev/null +++ b/tests/qemu-iotests/linters.py @@ -0,0 +1,130 @@ +# Copyright (C) 2020 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +import os +import re +import subprocess +import sys +from typing import List, Mapping, Optional + + +# TODO: Empty this list! +SKIP_FILES =3D ( + '030', '040', '041', '044', '045', '055', '056', '057', '065', '093', + '096', '118', '124', '132', '136', '139', '147', '148', '149', + '151', '152', '155', '163', '165', '169', '194', '196', '199', '202', + '203', '205', '206', '207', '208', '210', '211', '212', '213', '216', + '218', '219', '222', '224', '228', '234', '235', '236', '237', '238', + '240', '242', '245', '246', '248', '255', '256', '257', '258', '260', + '262', '264', '266', '274', '277', '280', '281', '295', '296', '298', + '299', '302', '303', '304', '307', + 'nbd-fault-injector.py', 'qcow2.py', 'qcow2_format.py', 'qed.py' +) + + +def is_python_file(filename: str, directory: str =3D '.') -> bool: + filepath =3D os.path.join(directory, filename) + + if not os.path.isfile(filepath): + return False + + if filename.endswith('.py'): + return True + + with open(filepath) as f: + try: + first_line =3D f.readline() + return re.match('^#!.*python', first_line) is not None + except UnicodeDecodeError: # Ignore binary files + return False + + +def get_test_files(directory: str =3D '.') -> List[str]: + return [ + f for f in (set(os.listdir(directory)) - set(SKIP_FILES)) + if is_python_file(f, directory) + ] + + +def run_linters( + files: List[str], + directory: str =3D '.', + env: Optional[Mapping[str, str]] =3D None, +) -> int: + ret =3D 0 + + print('=3D=3D=3D pylint =3D=3D=3D') + sys.stdout.flush() + + # Todo notes are fine, but fixme's or xxx's should probably just be + # fixed (in tests, at least) + p =3D subprocess.run( + ('python3', '-m', 'pylint', '--score=3Dn', '--notes=3DFIXME,XXX', = *files), + cwd=3Ddirectory, + env=3Denv, + check=3DFalse, + universal_newlines=3DTrue, + ) + ret +=3D p.returncode + + print('=3D=3D=3D mypy =3D=3D=3D') + sys.stdout.flush() + + # We have to call mypy separately for each file. Otherwise, it + # will interpret all given files as belonging together (i.e., they + # may not both define the same classes, etc.; most notably, they + # must not both define the __main__ module). + for filename in files: + p =3D subprocess.run( + ( + 'python3', '-m', 'mypy', + '--warn-unused-configs', + '--disallow-subclassing-any', + '--disallow-any-generics', + '--disallow-incomplete-defs', + '--disallow-untyped-decorators', + '--no-implicit-optional', + '--warn-redundant-casts', + '--warn-unused-ignores', + '--no-implicit-reexport', + '--namespace-packages', + filename, + ), + cwd=3Ddirectory, + env=3Denv, + check=3DFalse, + stdout=3Dsubprocess.PIPE, + stderr=3Dsubprocess.STDOUT, + universal_newlines=3DTrue + ) + + ret +=3D p.returncode + if p.returncode !=3D 0: + print(p.stdout) + + return ret + + +def main() -> int: + """ + Used by the Python CI system as an entry point to run these linters. + """ + directory =3D os.path.dirname(os.path.realpath(__file__)) + files =3D get_test_files(directory) + return run_linters(files, directory) + + +if __name__ =3D=3D '__main__': + sys.exit(main()) --=20 2.31.1 From nobody Sat May 18 09:01:25 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1622827907; cv=none; d=zohomail.com; s=zohoarc; b=dRBOzvlZZ7JhKjwKmNIjuM/1nsPfVfxLEerxjVeuHFu6z1p5jOOrFwxG14Mzw/JTHwNCF1pr++e5lKhX5bvQfki2k4Rj1tWvo0OeYPnF8fARMSfqTcTbgToiJIY2LLBsnS3/LVcyqKYFZKMJTL6iULYJgBKOU+1r8BEbqnjCjI4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622827907; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=aAOB/E5CPaLjPwAcFGN/NLfEOV/TwQV7VnVyCc7I0nw=; b=FKbW6MDyY5kil4V+KMttwSq3Q0vNZVzN+ECe792TfQjSG3mj51yoyuPY2M/+neTm4bIfaCXI4zUO0TJ8OvHnmQMWAp8QuY0aY4tdYFuAuYEEXcruSY3WwCwevnewX3j1sYg4JwQqB676B2GqnLvvnauB7hVJMbCV5dbmV2O4T7s= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1622827907024823.2926898067643; Fri, 4 Jun 2021 10:31:47 -0700 (PDT) Received: from localhost ([::1]:56398 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lpDfd-0007vN-Mg for importer@patchew.org; Fri, 04 Jun 2021 13:31:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37150) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lpCqt-00055i-GS for qemu-devel@nongnu.org; Fri, 04 Jun 2021 12:39:20 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:44624) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lpCqq-00059F-Sj for qemu-devel@nongnu.org; Fri, 04 Jun 2021 12:39:19 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-351-imv3oJA9Niqutoe8t57qlQ-1; Fri, 04 Jun 2021 12:39:14 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7DFC4425D1; Fri, 4 Jun 2021 16:39:13 +0000 (UTC) Received: from scv.redhat.com (ovpn-116-137.rdu2.redhat.com [10.10.116.137]) by smtp.corp.redhat.com (Postfix) with ESMTP id 67A661A8A0; Fri, 4 Jun 2021 16:39:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1622824756; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aAOB/E5CPaLjPwAcFGN/NLfEOV/TwQV7VnVyCc7I0nw=; b=CgUOb4VXOzn5aQv5wFfiwuHKzmqaOSvGuMcYp/fV5KYbzEHUHGMEtnYeFgKHM195Msh/hr DSo6G13f/Yl9FdXpwsx9ODHEPjjoCwTHZQI0SH646TmSPX4XIp8lWNMM4GeP7WBsfDklcy 7aTo8LS1DlNpHLitkfO2ie305ymRPFU= X-MC-Unique: imv3oJA9Niqutoe8t57qlQ-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH RFC 3/3] python: Add iotest linters to test suite Date: Fri, 4 Jun 2021 12:39:07 -0400 Message-Id: <20210604163907.1511224-4-jsnow@redhat.com> In-Reply-To: <20210604163907.1511224-1-jsnow@redhat.com> References: <20210604163907.1511224-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.373, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , Eduardo Habkost , qemu-block@nongnu.org, Markus Armbruster , Max Reitz , Cleber Rosa , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" As a convenience, since iotests is an extremely prominent user of the qemu.qmp and qemu.machine packages and already implements a linting regime, run those tests as well so that it's very hard to miss regressions caused by changes to the python library. Signed-off-by: John Snow --- python/tests/iotests.sh | 2 ++ 1 file changed, 2 insertions(+) create mode 100755 python/tests/iotests.sh diff --git a/python/tests/iotests.sh b/python/tests/iotests.sh new file mode 100755 index 0000000000..ec2fc58066 --- /dev/null +++ b/python/tests/iotests.sh @@ -0,0 +1,2 @@ +#!/bin/sh -e +PYTHONPATH=3D../tests/qemu-iotests/ python3 -m linters --=20 2.31.1