From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=none (p=none dis=none) header.from=gibson.dropbear.id.au Authentication-Results: passt.top; dkim=pass (2048-bit key; secure) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.a=rsa-sha256 header.s=202508 header.b=ExlYwFnv; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id BB5005A0619 for ; Thu, 02 Oct 2025 04:53:06 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202508; t=1759373583; bh=lzIQlRoIbrxXiZkRddlj9HOCx+HBxNjiGUTG0jlSXa0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ExlYwFnvxGx5yuwaTMaJ+CYWK/8BDAx89iCihAnZFu4hLBgA+YBLe+ZHxF+70Lkwy G//kuyfewLFPHfNylRPIE6m+YgIZhVqCwR5A52EtZWx185kcur0HrCKuBjzMj0Epdk pmPFI40H65m7SHoOehAOJS9GKNyK/FTUlNH62N7O47sT0dCWMWASv60qwQsX2k/4uA bUld/sh3ZymW/yGsUBzZFI2Z5fR1h4jBOchA8WqGFVmyOu96e/X9AI9haY96GhlT+3 gkKgM2MwwULf0csEx0RZE8fjdvGhczaWcoF34GnhcY7/npwxs0/XHHWBD2K4nhrvXQ 4WYLCGiqdbuvQ== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4ccbvM1wZfz4wC3; Thu, 2 Oct 2025 12:53:03 +1000 (AEST) Date: Thu, 2 Oct 2025 11:09:31 +1000 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH 2/6] test: Add linting of Python test scripts Message-ID: References: <20251001095202.3875003-1-david@gibson.dropbear.id.au> <20251001095202.3875003-3-david@gibson.dropbear.id.au> <20251001122351.7020b79a@elisabeth> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="sB+nXqve15x4N720" Content-Disposition: inline In-Reply-To: <20251001122351.7020b79a@elisabeth> Message-ID-Hash: IJNJA5H7NAKPL22L2ABHRGYNVHY5O54V X-Message-ID-Hash: IJNJA5H7NAKPL22L2ABHRGYNVHY5O54V X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: passt-dev@passt.top X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: --sB+nXqve15x4N720 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Oct 01, 2025 at 12:23:51PM +0200, Stefano Brivio wrote: > On Wed, 1 Oct 2025 19:51:58 +1000 > David Gibson wrote: >=20 > > We currently have one test moved to the new exeter based framwork writt= en > > in Python. We plan to add many more, so add linting (flake8) and type > > checking (mypy) of those scripts. This can be invoked manually with > > "make flake8" or "make mypy" in test/, and is also added to the static > > checkers test set. >=20 > I never used a Python linter, so I'm not sure if it's as bad as Go or > Rust linters taking the whole poetry away, as it happened for instance > in my most recent experience with 'cargo fmt': >=20 > https://github.com/AsahiLinux/muvm/compare/68094c02c19b6f5d5e3def6d2937= 9c1244c9a5e4..9af11c334a1ce37f533c056d982f8608c8d80d27#diff-e1a95ce380b9a8a= 317f97cccce1cbfd3dccd343dc62169ed1340208ab304fab9L106 >=20 > https://github.com/AsahiLinux/muvm/pull/111#discussion_r1863551727 > (you need to click around before you get to it, no idea how to share > a proper link that opens that comment right away) >=20 > Maybe with Python it's not as annoying? I don't have a strong > preference against this, I just wanted to raise a possible downside. I've been using flake8 for a while now. It _is_ pedantic about formatting, but so far at least, I haven't felt like it conflicted with anything I wanted to express. Finding missing or redundant imports and the like is certainly useful, since there's no compiler to do so. There is certainly some overlap with what mypy does. > In general, my thought is that coding style serves a purpose, and it's > used by humans for humans, so it's flexible, with exceptions, and > reasons behind it and behind those exceptions. >=20 > If we just pass everything through a linter, well, except for the > purposes of revision control, we don't really need a coding style? flake8 is partly about code formatting, but not entirely. Think of it as sitting somewhere in between indent and cppcheck, maybe? >=20 > > Signed-off-by: David Gibson > > --- > > test/Makefile | 14 +++++++++++++- > > test/build/build.py | 5 +++-- > > test/build/static_checkers.sh | 6 +++++- > > 3 files changed, 21 insertions(+), 4 deletions(-) > >=20 > > diff --git a/test/Makefile b/test/Makefile > > index 69987d0b..2637e0ed 100644 > > --- a/test/Makefile > > +++ b/test/Makefile > > @@ -8,6 +8,8 @@ > > BATS =3D bats -j $(shell nproc) > > EXETOOL =3D exeter/exetool/exetool > > WGET =3D wget -c > > +FLAKE8 =3D flake8 > > +MYPY =3D mypy --strict > > =20 > > DEBIAN_IMGS =3D debian-8.11.0-openstack-amd64.qcow2 \ > > debian-10-nocloud-amd64.qcow2 \ > > @@ -65,11 +67,15 @@ LOCAL_ASSETS =3D mbuto.img mbuto.mem.img podman/bin= /podman QEMU_EFI.fd \ > > ASSETS =3D $(DOWNLOAD_ASSETS) $(LOCAL_ASSETS) > > =20 > > EXETER_PYPATH =3D exeter/py3 > > +EXETER_PYTHON =3D build/build.py > > EXETER_BATS =3D smoke/smoke.sh.bats \ > > - build/build.py.bats build/static_checkers.sh.bats > > + $(EXETER_PYTHON:%=3D%.bats) build/static_checkers.sh.bats > > BATS_FILES =3D $(EXETER_BATS) \ > > podman/test/system/505-networking-pasta.bats > > =20 > > +# Python test code (for linters) > > +PYPKGS =3D $(EXETER_PYTHON) > > + > > CFLAGS =3D -Wall -Werror -Wextra -pedantic -std=3Dc99 > > =20 > > assets: $(ASSETS) > > @@ -130,6 +136,12 @@ medium.bin: > > big.bin: > > dd if=3D/dev/urandom bs=3D1M count=3D10 of=3D$@ > > =20 > > +flake8: pull-exeter > > + PYTHONPATH=3D$(EXETER_PYPATH) $(FLAKE8) $(PYPKGS) > > + > > +mypy: pull-exeter > > + PYTHONPATH=3D$(EXETER_PYPATH) $(MYPY) $(PYPKGS) > > + > > $(EXETER_BATS): %.bats: % $(EXETOOL) > > PYTHONPATH=3D$(EXETER_PYPATH) $(EXETOOL) bats -- $< > $@ > > =20 > > diff --git a/test/build/build.py b/test/build/build.py > > index e49287c9..e3de8305 100755 > > --- a/test/build/build.py > > +++ b/test/build/build.py > > @@ -18,11 +18,12 @@ import os > > from pathlib import Path > > import subprocess > > import tempfile > > -from typing import Iterable, Iterator > > +from typing import Iterator > > =20 > > import exeter > > =20 > > -def sh(cmd): > > + > > +def sh(cmd: str) -> None: > > """Run given command in a shell""" > > subprocess.run(cmd, shell=3DTrue) > > =20 > > diff --git a/test/build/static_checkers.sh b/test/build/static_checkers= =2Esh > > index 42806e79..228b99ae 100755 > > --- a/test/build/static_checkers.sh > > +++ b/test/build/static_checkers.sh > > @@ -21,6 +21,10 @@ exeter_set_description cppcheck "passt sources pass = cppcheck" > > exeter_register clang_tidy make -C .. clang-tidy > > exeter_set_description clang_tidy "passt sources pass clang-tidy" > > =20 > > -exeter_main "$@" > > +exeter_register flake8 make flake8 > > +exeter_set_description flake8 "passt tests in Python pass flake8" > > =20 > > +exeter_register mypy make mypy > > +exeter_set_description mypy "passt tests in Python pass mypy --strict" > > =20 > > +exeter_main "$@" >=20 > --=20 > Stefano >=20 --=20 David Gibson (he or they) | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you, not the other way | around. http://www.ozlabs.org/~dgibson --sB+nXqve15x4N720 Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmjd0LcACgkQzQJF27ox 2GeLrA//UNR1vgzzru1PHrLEAjsLaAg+MICRYp91y3bXCkM1Yrp560sKtOHildMf iRkSNTB3wJluDb+2v2aUkBx9OCbiDgUMpspehUQtYzVtUV6+WEVuZA/AUWXTPaaN Nec/SYr0ZONxuKdf5Sv4M01g6KnAj0kpMWyiT3vhiWTK22zXBU+EXKhGzuZ4tH4t MS8zhTOFBDlUQHNnw+IXc7IR7dvdxPgtiHkhFDFce6od3g61Cy1YFtMTfU/uYE/g WLAG9Pr16dUkvJs3sUUcZtBHyYrsa5cZIGexkq5rEF5iKpzxS//lmxgRuqrnlS2x 4HZp+fWpt1o9tS7tgI9GUeDnNpJbeKPEGxduEI4e9JPU8jlvGxsy7SzCdG1AMhEC kcZ5fIOaIwDlpkBnTiZbRXTcq3NnGJ4pOI0Pbt8t6wmcHu++WtpIfIAbsudx2c6s lf41klB5BrpQEDb7aIvrufY0mGzZCzkGqKLZDVfbs3WiWtcCAI/pdMy8W3hSQD9R 95chQcusE17F4Ed9Ld48H8FVKFoX8KNfcc459eozz+vnAY5GIJmanySTTBfcZ3iA bcHLh9mP7gQi9j3EVo+FcGBuTuAZauN1AYlzl1VvYQh3ma6mq3lHnl7Tc4UgVcD5 /5+c19iY2k0auHVOep+fvJ0kUatilYHhMVr7UFoLx+N5hRGjLAA= =2F33 -----END PGP SIGNATURE----- --sB+nXqve15x4N720--