From 992b1e9f78bef11dd7b9b7372e5aa94cd69a84b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damian=20Michalak-Szmaci=C5=84ski?= Date: Tue, 11 Jul 2023 16:41:04 +0200 Subject: [PATCH] Flake8 fixes Python error files in the scripts directory --- .flake8 | 21 ---------------- scripts/build/build/targets.py | 2 +- scripts/build/builders/android.py | 2 -- scripts/build/builders/bouffalolab.py | 1 - scripts/build/builders/cc13x2x7_26x2x7.py | 2 +- scripts/build/builders/genio.py | 2 +- scripts/build/builders/gn.py | 1 - scripts/build/builders/infineon.py | 2 +- scripts/codegen.py | 8 +++---- scripts/codepregen.py | 6 ++--- scripts/error_table.py | 1 - scripts/examples/gn_to_cmakelists.py | 6 ++--- .../flashing/bouffalolab_firmware_utils.py | 2 +- scripts/flashing/cyw30739_firmware_utils.py | 1 - scripts/gen_chip_version.py | 24 +++++++++---------- scripts/helpers/bloat_check.py | 2 +- scripts/pregenerate/using_codegen.py | 3 --- scripts/pregenerate/using_zap.py | 2 -- scripts/run-clang-tidy-on-compile-commands.py | 14 +++++------ 19 files changed, 34 insertions(+), 68 deletions(-) diff --git a/.flake8 b/.flake8 index c53238a9262656..2481f916e89300 100644 --- a/.flake8 +++ b/.flake8 @@ -3,7 +3,6 @@ max-line-length = 132 exclude = third_party .* out/* - scripts/idl/* ./examples/common/QRCode/* # temporarily scan only directories with fixed files # TODO: Remove the paths below when all bugs are fixed @@ -15,26 +14,6 @@ exclude = third_party docs/_extensions/external_content.py examples/common/pigweed/rpc_console/py/chip_rpc/console.py examples/lighting-app/python/lighting.py - scripts/build/build/target.py - scripts/build/build/targets.py - scripts/build/builders/android.py - scripts/build/builders/bouffalolab.py - scripts/build/builders/cc13x2x7_26x2x7.py - scripts/build/builders/genio.py - scripts/build/builders/gn.py - scripts/build/builders/imx.py - scripts/build/builders/infineon.py - scripts/codegen.py - scripts/codepregen.py - scripts/error_table.py - scripts/examples/gn_to_cmakelists.py - scripts/flashing/bouffalolab_firmware_utils.py - scripts/flashing/cyw30739_firmware_utils.py - scripts/gen_chip_version.py - scripts/helpers/bloat_check.py - scripts/pregenerate/using_codegen.py - scripts/pregenerate/using_zap.py - scripts/run-clang-tidy-on-compile-commands.py scripts/tools/check_zcl_file_sync.py scripts/tools/convert_ini.py scripts/tools/memory/memdf/__init__.py diff --git a/scripts/build/build/targets.py b/scripts/build/build/targets.py index 7447eec8e5561c..b444a8652e1599 100755 --- a/scripts/build/build/targets.py +++ b/scripts/build/build/targets.py @@ -543,7 +543,7 @@ def BuildQorvoTarget(): TargetPart('qpg6105', board=QpgBoard.QPG6105), ]) - # apps + # apps target.AppendFixedTargets([ TargetPart('lock', app=QpgApp.LOCK), TargetPart('light', app=QpgApp.LIGHT), diff --git a/scripts/build/builders/android.py b/scripts/build/builders/android.py index 7e0ec61bc7290c..3ae81c9f8e8b09 100644 --- a/scripts/build/builders/android.py +++ b/scripts/build/builders/android.py @@ -396,8 +396,6 @@ def generate(self): title="Accepting NDK licenses @ tools", ) - app_dir = os.path.join(self.root, "examples/", self.app.AppName()) - def stripSymbols(self): output_libs_dir = os.path.join( self.output_dir, diff --git a/scripts/build/builders/bouffalolab.py b/scripts/build/builders/bouffalolab.py index 51529e54bbfc8f..52477be7519ebf 100644 --- a/scripts/build/builders/bouffalolab.py +++ b/scripts/build/builders/bouffalolab.py @@ -14,7 +14,6 @@ import logging import os -import platform from enum import Enum, auto from .gn import GnBuilder diff --git a/scripts/build/builders/cc13x2x7_26x2x7.py b/scripts/build/builders/cc13x2x7_26x2x7.py index 713a5ca7bc913b..907d92fe1575b4 100644 --- a/scripts/build/builders/cc13x2x7_26x2x7.py +++ b/scripts/build/builders/cc13x2x7_26x2x7.py @@ -81,7 +81,7 @@ def GnBuildArgs(self): 'ti_sysconfig_root="%s"' % os.environ['TI_SYSCONFIG_ROOT'], ] - if self.openthread_ftd == None: + if self.openthread_ftd is None: pass elif self.openthread_ftd: args.append('chip_openthread_ftd=true') diff --git a/scripts/build/builders/genio.py b/scripts/build/builders/genio.py index 56ba33f7b705ff..822f198fd798da 100755 --- a/scripts/build/builders/genio.py +++ b/scripts/build/builders/genio.py @@ -27,7 +27,7 @@ def AppNamePrefix(self): def FlashBundleName(self): if self == GenioApp.LIGHT: return 'lighting_app.flashbundle.txt' - elif self == GEnioApp.SHELL: + elif self == GenioApp.SHELL: return 'shell.flashbundle.txt' else: raise Exception('Unknown app type: %r' % self) diff --git a/scripts/build/builders/gn.py b/scripts/build/builders/gn.py index 9e859f6025a5a7..75f6bb02c4231e 100644 --- a/scripts/build/builders/gn.py +++ b/scripts/build/builders/gn.py @@ -12,7 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import os import shlex from .builder import Builder diff --git a/scripts/build/builders/infineon.py b/scripts/build/builders/infineon.py index 1783faefa0ef75..7237f0625cc92e 100644 --- a/scripts/build/builders/infineon.py +++ b/scripts/build/builders/infineon.py @@ -111,5 +111,5 @@ def build_outputs(self): def flashbundle(self): with open(os.path.join(self.output_dir, self.app.FlashBundleName()), 'r') as fp: return { - l.strip(): os.path.join(self.output_dir, l.strip()) for l in fp.readlines() if l.strip() + line.strip(): os.path.join(self.output_dir, line.strip()) for line in fp.readlines() if line.strip() } diff --git a/scripts/codegen.py b/scripts/codegen.py index e703b8229e854c..1f679ea6148ed3 100755 --- a/scripts/codegen.py +++ b/scripts/codegen.py @@ -152,10 +152,10 @@ def main(log_level, generator, option, output_dir, dry_run, name_only, expected_ if expected_outputs: with open(expected_outputs, 'rt') as fin: expected = set() - for l in fin.readlines(): - l = l.strip() - if l: - expected.add(l) + for line in fin.readlines(): + line = line.strip() + if line: + expected.add(line) if expected != storage.generated_paths: logging.fatal("expected and generated files do not match.") diff --git a/scripts/codepregen.py b/scripts/codepregen.py index 43de8fc21c4dc1..6c0f24c60632eb 100755 --- a/scripts/codepregen.py +++ b/scripts/codepregen.py @@ -14,7 +14,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import enum import itertools import logging import multiprocessing @@ -25,8 +24,7 @@ try: from pregenerate import FindPregenerationTargets, TargetFilter -except: - import os +except ImportError: sys.path.append(os.path.abspath(os.path.dirname(__file__))) from pregenerate import FindPregenerationTargets, TargetFilter @@ -36,7 +34,7 @@ try: import coloredlogs _has_coloredlogs = True -except: +except ImportError: _has_coloredlogs = False # Supported log levels, mapping string values required for argument diff --git a/scripts/error_table.py b/scripts/error_table.py index 4f5dc13a22939d..54e9474fa8f338 100644 --- a/scripts/error_table.py +++ b/scripts/error_table.py @@ -28,7 +28,6 @@ from enum import IntEnum from operator import attrgetter from pathlib import Path -from xml.etree.ElementInclude import include @dataclass diff --git a/scripts/examples/gn_to_cmakelists.py b/scripts/examples/gn_to_cmakelists.py index 3525fce49606b1..aa17aa87ce5b6e 100755 --- a/scripts/examples/gn_to_cmakelists.py +++ b/scripts/examples/gn_to_cmakelists.py @@ -76,8 +76,8 @@ def Escape(c): return ''.join(map(Escape, a)) -def RemoveByPrefix(l, prefixs): - ret = l +def RemoveByPrefix(list, prefixs): + ret = list for pre in prefixs: ret = [x for x in ret if not x.startswith(pre)] @@ -450,7 +450,7 @@ def WriteCopy(out, target, project, sources, synthetic_dependencies): def WriteCompilerFlags(out, target, project, sources): # Hack, set linker language to c if no c or cxx files present. - if not 'c' in sources and not 'cxx' in sources: + if 'c' not in sources and 'cxx' not in sources: SetCurrentTargetProperty(out, 'LINKER_LANGUAGE', ['C']) # Mark uncompiled sources as uncompiled. diff --git a/scripts/flashing/bouffalolab_firmware_utils.py b/scripts/flashing/bouffalolab_firmware_utils.py index 2e7596892da94a..03aabaa9fd2b3b 100644 --- a/scripts/flashing/bouffalolab_firmware_utils.py +++ b/scripts/flashing/bouffalolab_firmware_utils.py @@ -207,7 +207,7 @@ def actions(self): continue if value: - if value == True: + if value is True: arg = ("--{}".format(key)).strip() elif isinstance(value, pathlib.Path): arg = ("--{}={}".format(key, os.path.join(os.getcwd(), str(value)))).strip() diff --git a/scripts/flashing/cyw30739_firmware_utils.py b/scripts/flashing/cyw30739_firmware_utils.py index 58913202ed53df..0b671bffd76c86 100644 --- a/scripts/flashing/cyw30739_firmware_utils.py +++ b/scripts/flashing/cyw30739_firmware_utils.py @@ -19,7 +19,6 @@ For `Flasher`, see the class documentation. """ -import os import sys import firmware_utils diff --git a/scripts/gen_chip_version.py b/scripts/gen_chip_version.py index bae79f01b4afee..baa201485bafb9 100755 --- a/scripts/gen_chip_version.py +++ b/scripts/gen_chip_version.py @@ -17,19 +17,19 @@ import optparse import sys -TEMPLATE = '''/* +TEMPLATE = r'''/* * * Copyright (c) 2020 Project CHIP Authors * All rights reserved. * - * Licensed under the Apache License, Version 2.0 (the \"License\"); + * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an \"AS IS\" BASIS, + * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. @@ -94,9 +94,9 @@ * \@endcode * */ -#define CHIP_VERSION_CODE_ENCODE(major, minor, patch) \\ - ((((major) & _CHIP_VERSION_CODE_MAJOR_MASK) << _CHIP_VERSION_CODE_MAJOR_SHIFT) | \\ - (((minor) & _CHIP_VERSION_CODE_MINOR_MASK) << _CHIP_VERSION_CODE_MINOR_SHIFT) | \\ +#define CHIP_VERSION_CODE_ENCODE(major, minor, patch) \ + ((((major) & _CHIP_VERSION_CODE_MAJOR_MASK) << _CHIP_VERSION_CODE_MAJOR_SHIFT) | \ + (((minor) & _CHIP_VERSION_CODE_MINOR_MASK) << _CHIP_VERSION_CODE_MINOR_SHIFT) | \ (((patch) & _CHIP_VERSION_CODE_PATCH_MASK) << _CHIP_VERSION_CODE_PATCH_SHIFT)) /** @@ -160,7 +160,7 @@ * The CHIP version extra component, as a quoted C string. * */ -#define CHIP_VERSION_EXTRA \"%(chip_extra)s\" +#define CHIP_VERSION_EXTRA "%(chip_extra)s" /** * \@def CHIP_VERSION_STRING @@ -169,7 +169,7 @@ * The CHIP version, as a quoted C string. * */ -#define CHIP_VERSION_STRING \"%(chip_version)s\" +#define CHIP_VERSION_STRING "%(chip_version)s" /** * \@def CHIP_VERSION_CODE @@ -191,10 +191,10 @@ * \@endcode * */ -#define CHIP_VERSION_CODE CHIP_VERSION_CODE_ENCODE( \\ - CHIP_VERSION_MAJOR, \\ - CHIP_VERSION_MINOR, \\ - CHIP_VERSION_PATCH \\ +#define CHIP_VERSION_CODE CHIP_VERSION_CODE_ENCODE( \ + CHIP_VERSION_MAJOR, \ + CHIP_VERSION_MINOR, \ + CHIP_VERSION_PATCH \ ) #endif /* CHIP_VERSION_H_ */ diff --git a/scripts/helpers/bloat_check.py b/scripts/helpers/bloat_check.py index 798df246b78554..72ad3705df2785 100755 --- a/scripts/helpers/bloat_check.py +++ b/scripts/helpers/bloat_check.py @@ -357,7 +357,7 @@ def main(): # Output processed. a.delete() - except Exception as e: + except Exception: tb = traceback.format_exc() logging.warning('Failed to process bloat report: %s', tb) diff --git a/scripts/pregenerate/using_codegen.py b/scripts/pregenerate/using_codegen.py index a48f187f5d9466..15c2e4ceb26ebf 100644 --- a/scripts/pregenerate/using_codegen.py +++ b/scripts/pregenerate/using_codegen.py @@ -14,9 +14,6 @@ import logging import os -import shlex -import subprocess -from enum import Enum, auto from .types import IdlFileType, InputIdlFile diff --git a/scripts/pregenerate/using_zap.py b/scripts/pregenerate/using_zap.py index 57df8ec42f7890..6af561b1a2921d 100644 --- a/scripts/pregenerate/using_zap.py +++ b/scripts/pregenerate/using_zap.py @@ -14,8 +14,6 @@ import logging import os -import shlex -import subprocess from enum import Enum, auto from .types import IdlFileType, InputIdlFile diff --git a/scripts/run-clang-tidy-on-compile-commands.py b/scripts/run-clang-tidy-on-compile-commands.py index 90ca9ed6cf9fac..d9dc6cdcfa374e 100755 --- a/scripts/run-clang-tidy-on-compile-commands.py +++ b/scripts/run-clang-tidy-on-compile-commands.py @@ -147,16 +147,16 @@ def Check(self): "Use -system-headers to display errors from system headers as well.", ] - for l in err.decode('utf-8').split('\n'): - l = l.strip() + for line in err.decode('utf-8').split('\n'): + line = line.strip() - if any(map(lambda s: s in l, skip_strings)): + if any(map(lambda s: s in line, skip_strings)): continue - if not l: + if not line: continue # no empty lines - logging.warning('TIDY %s: %s', self.file, l) + logging.warning('TIDY %s: %s', self.file, line) if proc.returncode != 0: if proc.returncode < 0: @@ -168,7 +168,7 @@ def Check(self): "Tidy %s ended with code %d", self.file, proc.returncode ) return TidyResult(self.full_path, False) - except: + except Exception: traceback.print_exc() return TidyResult(self.full_path, False) @@ -198,7 +198,7 @@ def find_darwin_gcc_sysroot(): if not line.startswith('Path: '): continue path = line[line.find(': ')+2:] - if not '/MacOSX.platform/' in path: + if '/MacOSX.platform/' not in path: continue logging.info("Found %s" % path) return path