Add linting with flake8 tool
authorPetr Štetiar <ynezz@true.cz>
Sat, 23 Dec 2023 06:13:02 +0000 (06:13 +0000)
committerPetr Štetiar <ynezz@true.cz>
Sat, 13 Apr 2024 04:17:49 +0000 (06:17 +0200)
flake8 is a Python tool that glues together pycodestyle, pyflakes,
mccabe, and third-party plugins to check the style and quality of some
Python code.

Currently we've issue in phase2 in checksum step:

 /bin/sh: 2: Syntax error: ")" unexpected

And it seems, that flake8 is able to spot places which might lead to
such issues during runtime:

 phase2/master.cfg:733:151: W605 invalid escape sequence '\('
 phase2/master.cfg:733:155: W605 invalid escape sequence '\)'
 phase2/master.cfg:733:158: W605 invalid escape sequence '\('
 phase2/master.cfg:733:162: W605 invalid escape sequence '\)'

So lets enable flake8 checking on the CI so we can spot similar places
in the future and address them before deployment.

We dont want to make current ongoing work on phase2 code harder, thus we
don't touch that part yet, so we whitelist most of the checks for now.

References: f0faed2970dd ("phase2: compute checksums")
Signed-off-by: Petr Štetiar <ynezz@true.cz>
.flake8 [new file with mode: 0644]
.github/workflows/build-push.yml
.gitignore
phase1/master.cfg
requirements-dev.txt

diff --git a/.flake8 b/.flake8
new file mode 100644 (file)
index 0000000..66380a1
--- /dev/null
+++ b/.flake8
@@ -0,0 +1,4 @@
+[flake8]
+max-line-length = 140
+per-file-ignores =
+    phase2/master.cfg: E101,E117,E128,E201,E202,E203,E221,E225,E251,E266,E302,E305,E501,W191
index 4f5b3f48666fab19d712b3aa691ed9f1e41fca65..1ae0f275cf01ef35cbeca72762cf86fc04e06022 100644 (file)
@@ -40,6 +40,9 @@ jobs:
       - name: Lint with ruff
         run: ruff phase*/master.cfg
 
+      - name: Lint with flake8
+        run: flake8 phase*/master.cfg
+
       - name: Stylecheck with black
         run: black phase1/master.cfg
 
index 0d4e15fcff942daaea0f1aab1d2f04a6977dd3da..5c68e090d88049fe43706b1151165ae9b4a90372 100644 (file)
@@ -27,3 +27,4 @@ phase[12]/twistd.*
 !.ruff.toml
 !tests
 !tests/**/*
+!.flake8
index 2d6f3045d17d5f59d2c12b4ccb04f07aaa159bc2..e9c6b71190e332806d79f87e34bc95725a61cbe0 100644 (file)
@@ -107,7 +107,7 @@ pb_port = inip1.get("port") or 9989
 # a shorter alias to save typing.
 c = BuildmasterConfig = {}
 
-####### PROJECT IDENTITY
+# PROJECT IDENTITY
 
 # the 'title' string will appear at the top of this buildbot
 # installation's html.WebStatus home page (linked to the
@@ -124,7 +124,7 @@ c["titleURL"] = ini["general"].get("title_url")
 
 c["buildbotURL"] = inip1.get("buildbot_url")
 
-####### BUILDWORKERS
+# BUILDWORKERS
 
 # The 'workers' list defines the set of recognized buildworkers. Each element is
 # a Worker object, specifying a unique worker name and password.  The same
@@ -292,7 +292,7 @@ def prioritizeBuilders(master, builders):
 
 c["prioritizeBuilders"] = prioritizeBuilders
 
-####### CHANGESOURCES
+# CHANGESOURCES
 
 # find targets
 targets = dict()
@@ -358,7 +358,7 @@ c["change_source"].append(
     )
 )
 
-####### SCHEDULERS
+# SCHEDULERS
 
 # Configure the Schedulers, which decide how to react to incoming changes.
 
@@ -541,7 +541,7 @@ c["schedulers"].append(
     schedulers.Triggerable(name="trigger", builderNames=builderNames, priority=20)
 )
 
-####### BUILDERS
+# BUILDERS
 
 # The 'builders' list defines the Builders, which tell Buildbot how to perform a build:
 # what steps, and which workers can execute them.  Note that any particular build will
@@ -882,7 +882,11 @@ def prepareFactory(target):
             name="gitverify",
             description="Ensuring that Git HEAD is pointing to a branch or tag",
             descriptionDone="Git HEAD is sane",
-            command='git rev-parse --abbrev-ref HEAD | grep -vxqF HEAD || git show-ref --tags --dereference 2>/dev/null | sed -ne "/^$(git rev-parse HEAD) / { s|^.*/||; s|\\^.*||; p }" | grep -qE "^v[0-9][0-9]\\."',
+            command=(
+                "git rev-parse --abbrev-ref HEAD | grep -vxqF HEAD || "
+                "git show-ref --tags --dereference 2>/dev/null | sed -ne "
+                '"/^$(git rev-parse HEAD) / { s|^.*/||; s|\\^.*||; p }" | grep -qE "^v[0-9][0-9]\\."'
+            ),
             haltOnFailure=True,
         )
     )
@@ -944,7 +948,9 @@ def prepareFactory(target):
             name="newconfig",
             descriptionDone=".config seeded",
             command=Interpolate(
-                "printf 'CONFIG_TARGET_%(kw:target)s=y\\nCONFIG_TARGET_%(kw:target)s_%(kw:subtarget)s=y\\nCONFIG_SIGNED_PACKAGES=%(kw:usign:#?|y|n)s\\n' >> .config",
+                "printf 'CONFIG_TARGET_%(kw:target)s=y\\n"
+                "CONFIG_TARGET_%(kw:target)s_%(kw:subtarget)s=y\\n"
+                "CONFIG_SIGNED_PACKAGES=%(kw:usign:#?|y|n)s\\n' >> .config",
                 target=target,
                 subtarget=subtarget,
                 usign=GetUsignKey,
@@ -1145,7 +1151,11 @@ def prepareFactory(target):
             name="kernelversion",
             property="kernelversion",
             description="Finding the effective Kernel version",
-            command="make --no-print-directory -C target/linux/ val.LINUX_VERSION val.LINUX_RELEASE val.LINUX_VERMAGIC | xargs printf '%s-%s-%s\\n'",
+            command=(
+                "make --no-print-directory -C target/linux/ "
+                "val.LINUX_VERSION val.LINUX_RELEASE val.LINUX_VERMAGIC | "
+                "xargs printf '%s-%s-%s\\n'"
+            ),
             env={"TOPDIR": Interpolate("%(prop:builddir)s/build")},
         )
     )
@@ -1341,7 +1351,10 @@ def prepareFactory(target):
             description="Packing files to sign",
             descriptionDone="Files to sign packed",
             command=Interpolate(
-                "find bin/targets/%(kw:target)s/%(kw:subtarget)s%(prop:libc)s/ bin/targets/%(kw:target)s/%(kw:subtarget)s%(prop:libc)s/kmods/ -mindepth 1 -maxdepth 2 -type f -name sha256sums -print0 -or -name Packages -print0 | xargs -0 tar -czf sign.tar.gz",
+                "find bin/targets/%(kw:target)s/%(kw:subtarget)s%(prop:libc)s/ "
+                "bin/targets/%(kw:target)s/%(kw:subtarget)s%(prop:libc)s/kmods/ "
+                "-mindepth 1 -maxdepth 2 -type f -name sha256sums -print0 -or "
+                "-name Packages -print0 | xargs -0 tar -czf sign.tar.gz",
                 target=target,
                 subtarget=subtarget,
             ),
@@ -1674,7 +1687,11 @@ def prepareFactory(target):
             name="sourcelist",
             description="Finding source archives to upload",
             descriptionDone="Source archives to upload found",
-            command="find dl/ -maxdepth 1 -type f -not -size 0 -not -name '.*' -not -name '*.hash' -not -name '*.dl' -newer .config -printf '%f\\n' > sourcelist",
+            command=(
+                "find dl/ -maxdepth 1 -type f -not -size 0 "
+                "-not -name '.*' -not -name '*.hash' -not -name "
+                "'*.dl' -newer .config -printf '%f\\n' > sourcelist"
+            ),
             haltOnFailure=True,
         )
     )
@@ -1775,7 +1792,7 @@ for brname in branchNames:
         )
 
 
-####### STATUS TARGETS
+# STATUS TARGETS
 
 # 'status' is a list of Status Targets. The results of each build will be
 # pushed to these targets. buildbot/status/*.py has a variety to choose from,
@@ -1826,7 +1843,7 @@ c["revlink"] = util.RevlinkMatch(
     r"https://git.openwrt.org/?p=openwrt/\1.git;a=commit;h=%s",
 )
 
-####### DB URL
+# DB URL
 
 c["db"] = {
     # This specifies what database buildbot uses to store its state.  You can leave
index e1cb65f0c300f27d7e01c96f567b13f524fba55d..033af6bbc2af928e2e7068e69ccb1e5e23d0df16 100644 (file)
@@ -1,3 +1,4 @@
 cram==0.7
 black==23.3.0
 ruff==0.0.267
+flake8==6.1.0