diff --git a/build/config/linux/pkg-config.py b/build/config/linux/pkg-config.py index da11fbb1a92e16..5f6208ded0f934 100755 --- a/build/config/linux/pkg-config.py +++ b/build/config/linux/pkg-config.py @@ -107,10 +107,7 @@ def GetPkgConfigPrefixToStrip(options, args): def MatchesAnyRegexp(flag, list_of_regexps): """Returns true if the first argument matches any regular expression in the given list.""" - for regexp in list_of_regexps: - if regexp.search(flag) is not None: - return True - return False + return any(regexp.search(flag) is not None for regexp in list_of_regexps) def RewritePath(path, strip_prefix, sysroot): diff --git a/credentials/generate_revocation_set.py b/credentials/generate_revocation_set.py index 9e3a91fd3b4be1..ad7406ff705508 100755 --- a/credentials/generate_revocation_set.py +++ b/credentials/generate_revocation_set.py @@ -358,7 +358,7 @@ def fetch_crl_from_url(url: str, timeout: int) -> x509.CertificateRevocationList log.debug(f"Fetched CRL: {r.content}") return x509.load_der_x509_crl(r.content) except Exception as e: - log.error('Failed to fetch a valid CRL', e) + log.error("Failed to fetch a valid CRL: %s", e) class DclClientInterface: @@ -439,7 +439,7 @@ def get_paa_cert(self, initial_cert: x509.Certificate) -> Optional[x509.Certific break except Exception as e: - log.error('Failed to get PAA certificate', e) + log.error("Failed to get PAA certificate: %s", e) return None log.debug(f"issuer_name: {issuer_certificate.subject.rfc4514_string()}") issuer_name = issuer_certificate.issuer diff --git a/pyproject.toml b/pyproject.toml index ba4908823be6ee..757f0295e8c48b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,14 +12,16 @@ known_first_party = "matter" line-length = 132 target-version = "py311" exclude = [ - ".environment", - ".git", - ".github", ".*", - "build", "out", + "scripts/py_matter_yamltests/build", + "scripts/py_matter_idl/build", + "src/python_testing/matter_testing_infrastructure/build", + # Exclude submodules since we do not maintain them + # TODO: Use exact paths once we will have a way to sync and validate them in CI + "examples/common/QRCode/repo", + "examples/common/m5stack-tft/repo", "third_party", - "examples/common/QRCode/", # TODO(#37698) "docs/development_controllers/matter-repl/*.ipynb", ] @@ -30,7 +32,7 @@ reportMissingTypeStubs = "warning" [tool.ruff.lint] select = [ # Standard errors and warnings - "E", "W", "F", + "E", "PLE", "W", "F", # Ensure that async is used properly "ASYNC", # Consistent commas @@ -39,6 +41,8 @@ select = [ "C4", "RET", "SIM", # Ensure that scripts are executable "EXE", + # Check for common exception issues + "RSE", # Check for common logging issues "LOG", # Check for common optimization issues diff --git a/scripts/build/build/__init__.py b/scripts/build/build/__init__.py index 1bac31f437adfb..0d8fd76c1bf7a2 100644 --- a/scripts/build/build/__init__.py +++ b/scripts/build/build/__init__.py @@ -3,12 +3,13 @@ import shutil import time from enum import Enum, auto -from multiprocessing.pool import ThreadPool -from typing import Optional, Sequence +from typing import Sequence from builders.builder import BuilderOptions -from .targets import BUILD_TARGETS, BuildTarget +from .targets import BUILD_TARGETS + +log = logging.getLogger(__name__) class BuildSteps(Enum): @@ -32,10 +33,10 @@ def time_builds(self, builders): def print_timing_report(self): total_time = self._total_end_time - self._total_start_time - logging.info("Build Time Summary:") + log.info("Build Time Summary:") for target, duration in self._build_times.items(): - logging.info(f" - {target}: {self._format_duration(duration)}") - logging.info(f"Total build time: {self._format_duration(total_time)}") + log.info(f" - {target}: {self._format_duration(duration)}") + log.info(f"Total build time: {self._format_duration(total_time)}") def _format_duration(self, seconds): minutes = int(seconds // 60) @@ -81,7 +82,7 @@ def SetupBuilders(self, targets: Sequence[str], options: BuilderOptions): break if found_choice is None: - logging.error(f"Target '{target}' could not be found. Nothing executed for it") + log.error(f"Target '{target}' could not be found. Nothing executed for it") continue parts = found_choice.StringIntoTargetParts(target) @@ -109,7 +110,7 @@ def Generate(self): self.runner.StartCommandExecution() for builder in self.builders: - logging.info('Generating %s', builder.output_dir) + log.info('Generating %s', builder.output_dir) builder.generate() self.completed_steps.add(BuildSteps.GENERATED) @@ -123,7 +124,7 @@ def Build(self): def CleanOutputDirectories(self): for builder in self.builders: - logging.warning('Cleaning %s', builder.output_dir) + log.warning('Cleaning %s', builder.output_dir) if os.path.exists(builder.output_dir): shutil.rmtree(builder.output_dir) @@ -131,7 +132,7 @@ def CleanOutputDirectories(self): self.completed_steps.discard(BuildSteps.GENERATED) def CreateArtifactArchives(self, directory: str): - logging.info('Copying build artifacts to %s', directory) + log.info('Copying build artifacts to %s', directory) if not os.path.exists(directory): os.makedirs(directory) for builder in self.builders: @@ -140,7 +141,7 @@ def CreateArtifactArchives(self, directory: str): directory, f'{builder.identifier}.tar.gz')) def CopyArtifactsTo(self, path: str): - logging.info('Copying build artifacts to %s', path) + log.info('Copying build artifacts to %s', path) if not os.path.exists(path): os.makedirs(path) diff --git a/scripts/build/build/target.py b/scripts/build/build/target.py index 4b1f43a7252bb8..48d1b10836b126 100644 --- a/scripts/build/build/target.py +++ b/scripts/build/build/target.py @@ -47,6 +47,8 @@ from builders.builder import BuilderOptions +log = logging.getLogger(__name__) + report_rejected_parts = True @@ -83,14 +85,14 @@ def Accept(self, full_input: str): if self.except_if_re.search(full_input): if report_rejected_parts: # likely nothing will match when we get such an error - logging.error(f"'{self.name}' does not support '{full_input}' due to rule EXCEPT IF '{self.except_if_re.pattern}'") + log.error(f"'{self.name}' does not support '{full_input}' due to rule EXCEPT IF '{self.except_if_re.pattern}'") return False if self.only_if_re: if not self.only_if_re.search(full_input): if report_rejected_parts: # likely nothing will match when we get such an error - logging.error(f"'{self.name}' does not support '{full_input}' due to rule ONLY IF '{self.only_if_re.pattern}'") + log.error(f"'{self.name}' does not support '{full_input}' due to rule ONLY IF '{self.only_if_re.pattern}'") return False return True @@ -140,6 +142,7 @@ def _HasVariantPrefix(value: str, prefix: str): if value.startswith(prefix + '-'): return value[len(prefix)+1:] + return None def _StringIntoParts(full_input: str, remaining_input: str, fixed_targets: List[List[TargetPart]], modifiers: List[TargetPart]): @@ -224,10 +227,7 @@ def __init__(self, name, builder_class, **kwargs): def isUnifiedBuild(self, parts: List[TargetPart]): """Checks if the given parts combine into a unified build.""" - for part in parts: - if part.build_arguments.get('unified', False): - return True - return False + return any(part.build_arguments.get('unified', False) for part in parts) def AppendFixedTargets(self, parts: List[TargetPart]): """Append a list of potential targets/variants. @@ -283,7 +283,7 @@ def HumanString(self): result = self.name for fixed in self.fixed_targets: if len(fixed) > 1: - result += '-{' + ",".join(sorted(map(lambda x: x.name, fixed))) + '}' + result += '-{' + ",".join(sorted(x.name for x in fixed)) + '}' else: result += '-' + fixed[0].name @@ -411,9 +411,7 @@ def AllVariants(self) -> Iterable[str]: while True: - prefix = "-".join(map( - lambda p: self.fixed_targets[p[0]][p[1]].name, enumerate(fixed_indices) - )) + prefix = "-".join(self.fixed_targets[i][n].name for i, n in enumerate(fixed_indices)) for n in range(len(self.modifiers) + 1): for c in itertools.combinations(self.modifiers, n): @@ -462,7 +460,7 @@ def Create(self, name: str, runner, repository_path: str, output_prefix: str, for part in parts: kargs.update(part.build_arguments) - logging.info("Preparing builder '%s'" % (name,)) + log.info("Preparing builder '%s'" % (name,)) builder = self.builder_class(repository_path, runner=runner, **kargs) builder.target = self diff --git a/scripts/build/build/targets.py b/scripts/build/build/targets.py old mode 100755 new mode 100644 diff --git a/scripts/build/build_darwin_framework.py b/scripts/build/build_darwin_framework.py old mode 100644 new mode 100755 index 439ba4a50ffc8d..476c7d7c37089c --- a/scripts/build/build_darwin_framework.py +++ b/scripts/build/build_darwin_framework.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. import argparse +import contextlib import glob import os import platform @@ -50,10 +51,8 @@ def run_command(command): if returncode != 0: # command_log is binary, so decoding as utf-8 might technically fail. We don't want # to throw on that. - try: + with contextlib.suppress(Exception): print("Failure log: {}".format(command_log.decode())) - except Exception: - pass return returncode diff --git a/scripts/build/build_examples.py b/scripts/build/build_examples.py index 23acb98442893e..17871f480db7ca 100755 --- a/scripts/build/build_examples.py +++ b/scripts/build/build_examples.py @@ -19,12 +19,13 @@ import os import sys -import build import click import coloredlogs from builders.builder import BuilderOptions from runner import PrintOnlyRunner, ShellRunner +import build + sys.path.append(os.path.abspath(os.path.dirname(__file__))) @@ -38,10 +39,6 @@ } -def CommaSeparate(items) -> str: - return ', '.join([x for x in items]) - - def ValidateRepoPath(context, parameter, value): """ Validates that the given path looks like a valid chip repository checkout. @@ -170,7 +167,7 @@ def main(context, log_level, verbose, target, enable_link_map_file, repo, ninja_jobs=ninja_jobs, runner=runner ) - requested_targets = set([t.lower() for t in target]) + requested_targets = {t.lower() for t in target} context.obj.SetupBuilders(targets=requested_targets, options=BuilderOptions( enable_link_map_file=enable_link_map_file, enable_flashbundle=enable_flashbundle, diff --git a/scripts/build/builders/android.py b/scripts/build/builders/android.py index 6b33293ca2cd81..d6c1d0a324ce36 100644 --- a/scripts/build/builders/android.py +++ b/scripts/build/builders/android.py @@ -19,6 +19,8 @@ from .builder import Builder, BuilderOutput +log = logging.getLogger(__name__) + class AndroidBoard(Enum): ARM = auto() @@ -176,17 +178,17 @@ def _find_sdk_manager(self, for_purpose="validation"): # Test environment - assume the path is valid sdk_manager = path checked_details.append(f"{path} (test environment - assumed valid)") - logging.info(f"Using SDK manager for {for_purpose} from test environment: {sdk_manager}") + log.info(f"Using SDK manager for {for_purpose} from test environment: {sdk_manager}") break # Real environment - check actual file existence exists = os.path.isfile(path) executable = os.access(path, os.X_OK) checked_details.append(f"{path} (exists: {exists}, executable: {executable})") - logging.debug(f"Checking SDK manager path for {for_purpose}: {path} - exists: {exists}, executable: {executable}") + log.debug(f"Checking SDK manager path for {for_purpose}: {path} - exists: {exists}, executable: {executable}") if exists and executable: sdk_manager = path - logging.info(f"Found SDK manager for {for_purpose} at: {sdk_manager}") + log.info(f"Found SDK manager for {for_purpose} at: {sdk_manager}") break return sdk_manager, checked_details @@ -203,16 +205,16 @@ def _handle_sdk_license_acceptance(self): title="Accepting NDK licenses using: %s" % sdk_manager_for_licenses, ) else: - logging.warning("No SDK manager found for license acceptance - licenses may need to be accepted manually") + log.warning("No SDK manager found for license acceptance - licenses may need to be accepted manually") def validate_build_environment(self): # Log Android environment paths for debugging android_ndk_home = os.environ.get("ANDROID_NDK_HOME", "") android_home = os.environ.get("ANDROID_HOME", "") - logging.info("Android environment paths:") - logging.info(f" ANDROID_NDK_HOME: {android_ndk_home}") - logging.info(f" ANDROID_HOME: {android_home}") + log.info("Android environment paths:") + log.info(f" ANDROID_NDK_HOME: {android_ndk_home}") + log.info(f" ANDROID_HOME: {android_home}") for k in ["ANDROID_NDK_HOME", "ANDROID_HOME"]: if k not in os.environ: @@ -225,9 +227,9 @@ def validate_build_environment(self): sdk_manager, checked_details = self._find_sdk_manager("validation") if not sdk_manager: - logging.error("SDK manager not found in any expected location") + log.error("SDK manager not found in any expected location") for detail in checked_details: - logging.error(f" {detail}") + log.error(f" {detail}") android_home = os.environ["ANDROID_HOME"] possible_fixes = [ @@ -314,7 +316,7 @@ def copyToSrcAndroid(self): "CHIPClusterID.jar": "src/controller/java/CHIPClusterID.jar", } - for jarName in jars.keys(): + for jarName in jars: self._Execute( [ "cp", @@ -339,7 +341,7 @@ def copyToExampleApp(self, jnilibs_dir, libs_dir, libs, jars): ] ) - for jarName in jars.keys(): + for jarName in jars: self._Execute( [ "cp", diff --git a/scripts/build/builders/bouffalolab.py b/scripts/build/builders/bouffalolab.py index 6617217585303a..e65a6fd3470175 100644 --- a/scripts/build/builders/bouffalolab.py +++ b/scripts/build/builders/bouffalolab.py @@ -21,6 +21,8 @@ from .builder import BuilderOutput from .gn import GnBuilder +log = logging.getLogger(__name__) + class BouffalolabApp(Enum): LIGHT = auto() @@ -128,7 +130,7 @@ def __init__(self, self.argsOpt.append(f'board="{self.board.GnArgName()}"') self.argsOpt.append(f'baudrate="{baudrate}"') - enable_thread = False if enable_thread_type == BouffalolabThreadType.NONE else True + enable_thread = enable_thread_type != BouffalolabThreadType.NONE if not (enable_wifi or enable_thread or enable_ethernet): # decide default connectivity for each chip @@ -187,10 +189,10 @@ def __init__(self, enable_littlefs = True else: if not enable_easyflash and not enable_littlefs: - logging.fatal('*' * 80) - logging.fatal('littlefs is added to support for flash storage access.') - logging.fatal('Please consider and select one of easyflash and littlefs to use.') - logging.fatal('*' * 80) + log.fatal('*' * 80) + log.fatal('littlefs is added to support for flash storage access.') + log.fatal('Please consider and select one of easyflash and littlefs to use.') + log.fatal('*' * 80) raise Exception("None of easyflash and littlefs select to build.") self.argsOpt.append(f'bouffalo_sdk_component_easyflash_enabled={"false" if enable_littlefs else "true"}') @@ -255,14 +257,14 @@ def __init__(self, raise err def print_enviroment_error(self): - logging.fatal('*' * 80) - logging.error('Flashtool is not installed, or environment variable BOUFFALOLAB_SDK_ROOT is not exported.') - logging.fatal('\tPlease make sure Bouffalo Lab SDK installs as below:') - logging.fatal('\t\t./integrations/docker/images/stage-2/chip-build-bouffalolab/setup.sh') + log.fatal('*' * 80) + log.error('Flashtool is not installed, or environment variable BOUFFALOLAB_SDK_ROOT is not exported.') + log.fatal('\tPlease make sure Bouffalo Lab SDK installs as below:') + log.fatal('\t\t./integrations/docker/images/stage-2/chip-build-bouffalolab/setup.sh') - logging.fatal('\tPlease make sure BOUFFALOLAB_SDK_ROOT exports before building as below:') - logging.fatal('\t\texport BOUFFALOLAB_SDK_ROOT="your install path"') - logging.fatal('*' * 80) + log.fatal('\tPlease make sure BOUFFALOLAB_SDK_ROOT exports before building as below:') + log.fatal('\t\texport BOUFFALOLAB_SDK_ROOT="your install path"') + log.fatal('*' * 80) def extract_sdk_version(self, filepath): pattern = r'PROJECT_SDK_VERSION\s+"([^"]+)"' @@ -278,7 +280,7 @@ def extract_sdk_version(self, filepath): return ver raise Exception('Invalid version format') except Exception as err: - logging.error(f"Failed to extract SDK version: {err}") + log.error(f"Failed to extract SDK version: {err}") return (2, 1, 0) def GnBuildArgs(self): @@ -311,15 +313,15 @@ def PostBuildCommand(self): path_fw = os.path.join(target_dir, self.app.AppNamePrefix(self.chip_name) + ".bin") path_flash_script = os.path.join(target_dir, self.app.AppNamePrefix(self.chip_name) + ".flash.py") - logging.info('*' * 80) - - logging.info("Firmware is built out at: {}".format(path_fw)) - logging.info("Command to generate ota image: ") - logging.info('./{} --build-ota --vendor-id --product-id ' - '--version --version-str ' - '--digest-algorithm '.format(path_flash_script)) - logging.info("Command to generate and sign ota image: ") - logging.info('./{} --build-ota --vendor-id --product-id ' - '--version --version-str ' - '--digest-algorithm --sk '.format(path_flash_script)) - logging.info('*' * 80) + log.info('*' * 80) + + log.info("Firmware is built out at: {}".format(path_fw)) + log.info("Command to generate ota image: ") + log.info('./{} --build-ota --vendor-id --product-id ' + '--version --version-str ' + '--digest-algorithm '.format(path_flash_script)) + log.info("Command to generate and sign ota image: ") + log.info('./{} --build-ota --vendor-id --product-id ' + '--version --version-str ' + '--digest-algorithm --sk '.format(path_flash_script)) + log.info('*' * 80) diff --git a/scripts/build/builders/builder.py b/scripts/build/builders/builder.py index 4ffde00ae34c71..471ea6c6a9d7a6 100644 --- a/scripts/build/builders/builder.py +++ b/scripts/build/builders/builder.py @@ -19,6 +19,8 @@ from abc import ABC, abstractmethod from dataclasses import dataclass +log = logging.getLogger(__name__) + @dataclass class BuilderOptions: @@ -61,12 +63,12 @@ def __init__(self, root, runner): @abstractmethod def generate(self): """Generate the build files - generally the ninja/makefiles""" - raise NotImplementedError() + raise NotImplementedError @abstractmethod def _build(self): """Perform an actual build""" - raise NotImplementedError() + raise NotImplementedError def _bundle(self): """Perform an actual generating of flashbundle. @@ -84,7 +86,7 @@ def build_outputs(self): May use build output data (e.g. manifests), so this should be invoked only after a build has succeeded. """ - raise NotImplementedError() + raise NotImplementedError def bundle_outputs(self): """Return the BuilderOutput objects in flashbundle. @@ -114,20 +116,20 @@ def _Execute(self, cmdarray, title=None, dedup=False): def CompressArtifacts(self, target_file: str): with tarfile.open(target_file, "w:gz") as tar: for output in self.outputs(): - logging.info('Adding %s into %s(%s)', - output.source, target_file, output.target) + log.info('Adding %s into %s(%s)', + output.source, target_file, output.target) tar.add(output.source, output.target) def CopyArtifacts(self, target_dir: str): for output in self.outputs(): - logging.info(f'Copying {output.source} into {output.target}') + log.info(f'Copying {output.source} into {output.target}') target_full_name = os.path.join(target_dir, output.target) target_dir_full_name = os.path.dirname(target_full_name) if not os.path.exists(target_dir_full_name): - logging.info('Creating subdirectory %s first', - target_dir_full_name) + log.info('Creating subdirectory %s first', + target_dir_full_name) os.makedirs(target_dir_full_name) shutil.copyfile(output.source, target_full_name) diff --git a/scripts/build/builders/efr32.py b/scripts/build/builders/efr32.py index c23e126591e926..ed6ce5393ac33f 100644 --- a/scripts/build/builders/efr32.py +++ b/scripts/build/builders/efr32.py @@ -22,6 +22,8 @@ from .builder import BuilderOutput from .gn import GnBuilder +log = logging.getLogger(__name__) + class Efr32App(Enum): EVSE = auto() @@ -296,7 +298,7 @@ def _bundle(self): # Only unit-test needs to generate the flashbundle here. All other examples will generate a flashbundle via the silabs_executable template. if self.app == Efr32App.UNIT_TEST: flash_bundle_path = os.path.join(self.output_dir, self.app.FlashBundleName()) - logging.info(f'Generating flashbundle {flash_bundle_path}') + log.info(f'Generating flashbundle {flash_bundle_path}') patterns = [ os.path.join(self.output_dir, "tests", "*.flash.py"), diff --git a/scripts/build/builders/esp32.py b/scripts/build/builders/esp32.py index 95adabfb1d9e9d..a72f383a8c86fc 100644 --- a/scripts/build/builders/esp32.py +++ b/scripts/build/builders/esp32.py @@ -20,6 +20,8 @@ from .builder import Builder, BuilderOutput +log = logging.getLogger(__name__) + class Esp32Board(Enum): DevKitC = auto() @@ -261,7 +263,7 @@ def generate(self): self._IdfEnvExecute(cmd) def _build(self): - logging.info('Compiling Esp32 at %s', self.output_dir) + log.info('Compiling Esp32 at %s', self.output_dir) # Unfortunately sdkconfig is sticky and needs reset on every build self._Execute( diff --git a/scripts/build/builders/genio.py b/scripts/build/builders/genio.py old mode 100755 new mode 100644 diff --git a/scripts/build/builders/nrf.py b/scripts/build/builders/nrf.py index af86600286d736..84c4f98b9eca2f 100644 --- a/scripts/build/builders/nrf.py +++ b/scripts/build/builders/nrf.py @@ -19,6 +19,8 @@ from .builder import Builder, BuilderOutput +log = logging.getLogger(__name__) + class NrfApp(Enum): ALL_CLUSTERS = auto() @@ -148,8 +150,8 @@ def _check_ncs_version(self): self._Execute( ['python3', 'scripts/setup/nrfconnect/update_ncs.py', '--check']) except Exception: - logging.exception('Failed to validate ZEPHYR_BASE status') - logging.error( + log.exception('Failed to validate ZEPHYR_BASE status') + log.error( 'To update $ZEPHYR_BASE run: python3 scripts/setup/nrfconnect/update_ncs.py --update --shallow') raise Exception('ZEPHYR_BASE validation failed') @@ -198,7 +200,7 @@ def generate(self): title='Generating ' + self.identifier) def _build(self): - logging.info('Compiling NrfConnect at %s', self.output_dir) + log.info('Compiling NrfConnect at %s', self.output_dir) cmd = self._prepare_environment() cmd += f'ninja -C {self.output_dir}' @@ -216,7 +218,7 @@ def _build(self): title='Run Tests ' + self.identifier) def _bundle(self): - logging.info(f'Generating flashbundle at {self.output_dir}') + log.info(f'Generating flashbundle at {self.output_dir}') self._Execute(['ninja', '-C', os.path.join(self.output_dir, 'nrfconnect'), 'flashing_script'], title='Generating flashable files of ' + self.identifier) diff --git a/scripts/build/builders/nuttx.py b/scripts/build/builders/nuttx.py index 67c7b7273f958b..167ca48aa0817d 100644 --- a/scripts/build/builders/nuttx.py +++ b/scripts/build/builders/nuttx.py @@ -19,6 +19,8 @@ from .builder import BuilderOutput from .gn import Builder +log = logging.getLogger(__name__) + class NuttXApp(Enum): LIGHT = auto() @@ -77,12 +79,12 @@ def generate(self): title='Configuring ' + self.identifier) def _build(self): - logging.info('Compiling NuttX %s at %s, ', - self.board.board_config, self.output_dir) + log.info('Compiling NuttX %s at %s, ', + self.board.board_config, self.output_dir) self._Execute(['cmake', '--build', self.output_dir]) def build_outputs(self): - logging.info('Compiling outputs NuttX at %s', self.output_dir) + log.info('Compiling outputs NuttX at %s', self.output_dir) extensions = ["out"] if self.options.enable_link_map_file: extensions.append("out.map") diff --git a/scripts/build/builders/nxp.py b/scripts/build/builders/nxp.py index 82d36c7ac6607f..d6f3dc33b3e15f 100644 --- a/scripts/build/builders/nxp.py +++ b/scripts/build/builders/nxp.py @@ -20,6 +20,8 @@ from .builder import BuilderOutput from .gn import GnBuilder +log = logging.getLogger(__name__) + class NxpOsUsed(Enum): FREERTOS = auto() @@ -215,7 +217,7 @@ def __init__(self, self.iw610_transceiver = iw610_transceiver self.se05x_enable = se05x_enable if self.low_power and log_level != NxpLogLevel.NONE: - logging.warning("Switching log level to 'NONE' for low power build") + log.warning("Switching log level to 'NONE' for low power build") log_level = NxpLogLevel.NONE self.log_level = log_level diff --git a/scripts/build/builders/telink.py b/scripts/build/builders/telink.py index 186df23599e170..792ae4b4aa3614 100644 --- a/scripts/build/builders/telink.py +++ b/scripts/build/builders/telink.py @@ -19,6 +19,8 @@ from .builder import Builder, BuilderOutput +log = logging.getLogger(__name__) + class TelinkLogLevel(Enum): DEFAULT = auto() # default everything @@ -286,7 +288,7 @@ def generate(self): title='Generating ' + self.identifier) def _build(self): - logging.info('Compiling Telink at %s', self.output_dir) + log.info('Compiling Telink at %s', self.output_dir) cmd = self.get_cmd_prefixes() + ("ninja -C %s" % self.output_dir) diff --git a/scripts/build/builders/tizen.py b/scripts/build/builders/tizen.py index b20bd415a47a9f..a245b33718a631 100644 --- a/scripts/build/builders/tizen.py +++ b/scripts/build/builders/tizen.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import contextlib import logging import os from collections import namedtuple @@ -21,6 +22,8 @@ from .builder import BuilderOutput from .gn import GnBuilder +log = logging.getLogger(__name__) + Board = namedtuple('Board', ['target_cpu']) App = namedtuple('App', ['name', 'source', 'outputs']) Tool = namedtuple('Tool', ['name', 'source', 'outputs']) @@ -102,15 +105,13 @@ def __init__(self, self.extra_gn_options = [] if self.app.is_tpk: - try: + with contextlib.suppress(FileNotFoundError): # Try to load Tizen application XML manifest. We have to use # try/except here, because of TestBuilder test. This test runs # in a fake build root /TEST/BUILD/ROOT which obviously does # not have Tizen manifest file. self.app.parse_manifest( os.path.join(self.root, "tizen-manifest.xml")) - except FileNotFoundError: - pass if app == TizenApp.TESTS: self.extra_gn_options.append('chip_build_tests=true') @@ -222,7 +223,7 @@ def GnBuildArgs(self): def _bundle(self): if self.app.is_tpk: - logging.info('Packaging %s', self.output_dir) + log.info('Packaging %s', self.output_dir) cmd = ['ninja', '-C', self.output_dir, self.app.value.name + ':tpk'] self._Execute(cmd, title='Packaging ' + self.identifier) diff --git a/scripts/build/clang_coverage_wrapper.py b/scripts/build/clang_coverage_wrapper.py old mode 100644 new mode 100755 index 452d827d417667..e6d13e671af3ff --- a/scripts/build/clang_coverage_wrapper.py +++ b/scripts/build/clang_coverage_wrapper.py @@ -54,12 +54,14 @@ } gInitLLVMProfilingPaths; """ +log = logging.getLogger(__name__) + @click.command() @click.option( "--log-level", default="INFO", - type=click.Choice([k for k in __LOG_LEVELS__], case_sensitive=False), + type=click.Choice(list(__LOG_LEVELS__), case_sensitive=False), help="Determines the verbosity of script output.", ) @click.option( @@ -82,14 +84,14 @@ def main(log_level, log_timestamps, output, raw_profile_filename): if os.path.exists(output): with open(output) as f: if f.read() == expected_output: - logging.info("File %s is already as expected. Will not re-write", output) + log.info("File %s is already as expected. Will not re-write", output) sys.exit(0) - logging.info("Writing output to %s (profile name: %s)", output, raw_profile_filename) + log.info("Writing output to %s (profile name: %s)", output, raw_profile_filename) with open(output, "wt") as f: f.write(expected_output) - logging.debug("Writing completed") + log.debug("Writing completed") if __name__ == "__main__": diff --git a/scripts/build/runner/shell.py b/scripts/build/runner/shell.py index 67eda1d3352bc6..4a8a3abc739b77 100644 --- a/scripts/build/runner/shell.py +++ b/scripts/build/runner/shell.py @@ -19,6 +19,8 @@ from .command_dedup import CommandDedup +log = logging.getLogger(__name__) + class LogPipe(threading.Thread): @@ -41,7 +43,7 @@ def fileno(self): def run(self): """Run the thread, logging everything.""" for line in iter(self.pipeReader.readline, ''): - logging.log(self.level, line.strip('\n')) + log.log(self.level, line.strip('\n')) self.pipeReader.close() @@ -63,10 +65,10 @@ def StartCommandExecution(self): def Run(self, cmd, title=None, dedup=False): if title: - logging.info(title) + log.info(title) - if dedup & self.deduplicator.is_duplicate(cmd): - logging.info("Skipping duplicate command...") + if dedup and self.deduplicator.is_duplicate(cmd): + log.info("Skipping duplicate command...") return outpipe = LogPipe(logging.INFO) @@ -79,4 +81,4 @@ def Run(self, cmd, title=None, dedup=False): code = s.wait() if code != 0: raise Exception('Command %r failed: %d' % (cmd, code)) - logging.info('Command %r completed', cmd) + log.info('Command %r completed', cmd) diff --git a/scripts/build/test.py b/scripts/build/test.py old mode 100644 new mode 100755 index a545cba884f324..7a8f1931272fda --- a/scripts/build/test.py +++ b/scripts/build/test.py @@ -76,10 +76,10 @@ def assertCommandOutput(self, expected_file: str, args: List[str]): ROOT = '/TEST/BUILD/ROOT' OUT = '/OUTPUT/DIR' - expected = [line for line in build_expected_output(expected_file, ROOT, OUT)] - actual = [line for line in build_actual_output(ROOT, OUT, args)] + expected = list(build_expected_output(expected_file, ROOT, OUT)) + actual = list(build_actual_output(ROOT, OUT, args)) - diffs = [line for line in difflib.unified_diff(expected, actual)] + diffs = list(difflib.unified_diff(expected, actual)) if diffs: reference = os.path.basename(expected_file) + '.actual' diff --git a/scripts/build/test_glob_matcher.py b/scripts/build/test_glob_matcher.py old mode 100644 new mode 100755 diff --git a/scripts/flashing/firmware_utils.py b/scripts/flashing/firmware_utils.py index d02e2179a6ffb8..569145d7f4b788 100755 --- a/scripts/flashing/firmware_utils.py +++ b/scripts/flashing/firmware_utils.py @@ -180,7 +180,7 @@ def status(self): def actions(self): """Perform actions on the device according to self.option.""" - raise NotImplementedError() + raise NotImplementedError def log(self, level, *args): """Optionally log a message to stderr.""" diff --git a/scripts/flashing/psoc6_firmware_utils.py b/scripts/flashing/psoc6_firmware_utils.py index 0dcf8c59424871..064a0f63b3e9b8 100755 --- a/scripts/flashing/psoc6_firmware_utils.py +++ b/scripts/flashing/psoc6_firmware_utils.py @@ -138,10 +138,10 @@ def __init__(self, **options): self.define_options(PSOC6_OPTIONS) def verify(self, image): - raise NotImplementedError() + raise NotImplementedError def reset(self): - raise NotImplementedError() + raise NotImplementedError def erase(self): tools_path = _find_tools_path() diff --git a/scripts/py_matter_idl/matter/idl/generators/storage.py b/scripts/py_matter_idl/matter/idl/generators/storage.py index 589e81da4f6fcb..b490cc94e65e13 100644 --- a/scripts/py_matter_idl/matter/idl/generators/storage.py +++ b/scripts/py_matter_idl/matter/idl/generators/storage.py @@ -41,11 +41,11 @@ def get_existing_data(self, relative_path: str): """Gets the existing data at the given path. If such data does not exist, will return None. """ - raise NotImplementedError() + raise NotImplementedError def write_new_data(self, relative_path: str, content: str): """Write new data to the given path.""" - raise NotImplementedError() + raise NotImplementedError class FileSystemGeneratorStorage(GeneratorStorage): diff --git a/scripts/py_matter_idl/matter/idl/lint/type_definitions.py b/scripts/py_matter_idl/matter/idl/lint/type_definitions.py index a755828af1514a..99d4d830da69b9 100644 --- a/scripts/py_matter_idl/matter/idl/lint/type_definitions.py +++ b/scripts/py_matter_idl/matter/idl/lint/type_definitions.py @@ -156,7 +156,7 @@ def _ClusterCode(self, name: str, location: Optional[LocationInFile]): On error returns None and _lint_errors is updated internlly """ if not self._idl: - raise MissingIdlError() + raise MissingIdlError cluster_definition = [c for c in self._idl.clusters if c.name == name] if not cluster_definition: @@ -173,7 +173,7 @@ def _ClusterCode(self, name: str, location: Optional[LocationInFile]): def _LintImpl(self): if not self._idl: - raise MissingIdlError() + raise MissingIdlError for endpoint in self._idl.endpoints: cluster_codes = set() @@ -238,7 +238,7 @@ def _ServerClusterDefinition(self, name: str, location: Optional[LocationInFile] On error returns None and _lint_errors is updated internlly """ if not self._idl: - raise MissingIdlError() + raise MissingIdlError cluster_definition = [c for c in self._idl.clusters if c.name == name] if not cluster_definition: @@ -255,7 +255,7 @@ def _ServerClusterDefinition(self, name: str, location: Optional[LocationInFile] def _LintImpl(self): if not self._idl: - raise MissingIdlError() + raise MissingIdlError for endpoint in self._idl.endpoints: @@ -358,7 +358,7 @@ def RequireCommand(self, cmd: ClusterCommandRequirement): def _LintImpl(self): if not self._idl: - raise MissingIdlError() + raise MissingIdlError for cluster in self._idl.clusters: if cluster.code not in self._mandatory_commands: diff --git a/src/controller/python/matter/clusters/ClusterObjects.py b/src/controller/python/matter/clusters/ClusterObjects.py index ec09a8fe8de73e..a8a7ab33698e76 100644 --- a/src/controller/python/matter/clusters/ClusterObjects.py +++ b/src/controller/python/matter/clusters/ClusterObjects.py @@ -210,7 +210,7 @@ def FromTLV(cls, data: bytes): @ChipUtility.classproperty def descriptor(cls): - raise NotImplementedError() + raise NotImplementedError # The below dictionaries will be filled dynamically @@ -243,15 +243,15 @@ def __init_subclass__(cls, *args, **kwargs) -> None: @ChipUtility.classproperty def cluster_id(self) -> int: - raise NotImplementedError() + raise NotImplementedError @ChipUtility.classproperty def command_id(self) -> int: - raise NotImplementedError() + raise NotImplementedError @ChipUtility.classproperty def is_client(self) -> bool: - raise NotImplementedError() + raise NotImplementedError @ChipUtility.classproperty def must_use_timed_invoke(cls) -> bool: @@ -334,15 +334,15 @@ def FromTagDictOrRawValue(cls, val: Any): @ChipUtility.classproperty def cluster_id(self) -> int: - raise NotImplementedError() + raise NotImplementedError @ChipUtility.classproperty def attribute_id(self) -> int: - raise NotImplementedError() + raise NotImplementedError @ChipUtility.classproperty def attribute_type(cls) -> ClusterObjectFieldDescriptor: - raise NotImplementedError() + raise NotImplementedError @ChipUtility.classproperty def must_use_timed_write(cls) -> bool: @@ -382,8 +382,8 @@ def __init_subclass__(cls, *args, **kwargs) -> None: @ChipUtility.classproperty def cluster_id(self) -> int: - raise NotImplementedError() + raise NotImplementedError @ChipUtility.classproperty def event_id(self) -> int: - raise NotImplementedError() + raise NotImplementedError diff --git a/src/controller/python/matter/commissioning/__init__.py b/src/controller/python/matter/commissioning/__init__.py index 15cbf33a770704..f11496fba43fe1 100644 --- a/src/controller/python/matter/commissioning/__init__.py +++ b/src/controller/python/matter/commissioning/__init__.py @@ -139,7 +139,7 @@ async def get_commissionee_nonces(self) -> Tuple[bytes, bytes]: async def get_commissionee_credentials(self, request: GetCommissioneeCredentialsRequest) -> GetCommissioneeCredentialsResponse: ''' Returns certifications and infomations for the commissioning. ''' - raise NotImplementedError() + raise NotImplementedError class ExampleCredentialProvider: diff --git a/src/controller/python/matter/crypto/p256keypair.py b/src/controller/python/matter/crypto/p256keypair.py index 3e4d46ef0a309b..9b4652764fbec3 100644 --- a/src/controller/python/matter/crypto/p256keypair.py +++ b/src/controller/python/matter/crypto/p256keypair.py @@ -120,11 +120,11 @@ def public_key(self) -> bytes: For P256Keypair, the output length should be exactly 65 bytes. ''' - raise NotImplementedError() + raise NotImplementedError @abc.abstractmethod def ECDSA_sign_msg(self, message: bytes) -> bytes: - raise NotImplementedError() + raise NotImplementedError @abc.abstractmethod def ECDH_derive_secret(self, remote_pubkey: bytes) -> bytes: @@ -133,7 +133,7 @@ def ECDH_derive_secret(self, remote_pubkey: bytes) -> bytes: remote_pubkey will be a public key conforms with the uncompressed format of section 2.3.3 of the SECG SEC 1 standard. ''' - raise NotImplementedError() + raise NotImplementedError class TestP256Keypair(P256Keypair): diff --git a/src/controller/python/tests/scripts/cluster_objects.py b/src/controller/python/tests/scripts/cluster_objects.py index acbc660554d55e..599dbd795830ca 100644 --- a/src/controller/python/tests/scripts/cluster_objects.py +++ b/src/controller/python/tests/scripts/cluster_objects.py @@ -84,15 +84,15 @@ class ClusterObjectTests: @base.test_case def TestAPI(cls): if Clusters.OnOff.id != 6: - raise ValueError() + raise ValueError if Clusters.OnOff.Commands.Off.command_id != 0: - raise ValueError() + raise ValueError if Clusters.OnOff.Commands.Off.cluster_id != 6: - raise ValueError() + raise ValueError if Clusters.OnOff.Commands.On.command_id != 1: - raise ValueError() + raise ValueError if Clusters.OnOff.Commands.On.cluster_id != 6: - raise ValueError() + raise ValueError @classmethod @base.test_case @@ -102,7 +102,7 @@ async def TestCommandRoundTrip(cls, devCtrl): if res is not None: logger.error( f"Got {res} Response from server, but None is expected.") - raise ValueError() + raise ValueError @classmethod @base.test_case @@ -122,10 +122,10 @@ async def TestCommandWithResponse(cls, devCtrl): res = await devCtrl.SendCommand(nodeId=NODE_ID, endpoint=LIGHTING_ENDPOINT_ID, payload=req) if not isinstance(res, Clusters.UnitTesting.Commands.TestAddArgumentsResponse): logger.error(f"Unexpected response of type {type(res)} received.") - raise ValueError() + raise ValueError logger.info(f"Received response: {res}") if res.returnValue != 5: - raise ValueError() + raise ValueError @classmethod @base.test_case