Skip to content

Commit

Permalink
[python tools] Add to flake8 in workflow and fix python files (part #…
Browse files Browse the repository at this point in the history
…25193) (#27881)

* Flake8 fix error in python tools

* Restyled by isort

---------

Co-authored-by: Restyled.io <commits@restyled.io>
  • Loading branch information
2 people authored and pull[bot] committed Aug 18, 2023
1 parent 55a044d commit 2412753
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 38 deletions.
12 changes: 0 additions & 12 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,13 @@ exclude = third_party
./examples/common/QRCode/*
# temporarily scan only directories with fixed files
# TODO: Remove the paths below when all bugs are fixed
src/tools/chip-cert/*
build/chip/java/tests/*
build/chip/linux/*
build/config/linux/*
credentials/fetch-paa-certs-from-dcl.py
docs/_extensions/external_content.py
examples/common/pigweed/rpc_console/py/chip_rpc/console.py
examples/lighting-app/python/lighting.py
scripts/tools/check_zcl_file_sync.py
scripts/tools/convert_ini.py
scripts/tools/memory/memdf/__init__.py
scripts/tools/memory/report_summary.py
scripts/tools/silabs/FactoryDataProvider.py
scripts/tools/zap/generate.py
scripts/tools/zap/prune_outputs.py
scripts/tools/zap/version_update.py
scripts/tools/zap/zap_download.py
scripts/tools/zap_convert_all.py
src/app/ota_image_tool.py
src/app/zap_cluster_list.py
src/controller/python/chip/yaml/__init__.py
src/controller/python/chip/yaml/format_converter.py
Expand Down
8 changes: 4 additions & 4 deletions scripts/tools/check_zcl_file_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ def main():
print("%s and %s have unexpected differences." % (base_name, ext_name))
print("Differences between expected and actual:")

for l in difflib.unified_diff(
for line in difflib.unified_diff(
json.dumps(ext_data, indent=2).split('\n'),
json.dumps(base_data, indent=2).split('\n'),
fromfile=ext_name,
tofile="<Expected extension file content>",
):
if l.endswith('\n'):
l = l[:-1]
print(l)
if line.endswith('\n'):
line = line[:-1]
print(line)

return 1

Expand Down
4 changes: 3 additions & 1 deletion scripts/tools/memory/memdf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@
#
"""Package for working with memory usage information using Pandas DataFrame."""

from memdf.df import DF, SymbolDF, SectionDF, SegmentDF, ExtentDF, DFs
from memdf.df import DF, DFs, ExtentDF, SectionDF, SegmentDF, SymbolDF
from memdf.util.config import Config, ConfigDescription

__all__ = [DF, SymbolDF, SectionDF, SegmentDF, ExtentDF, DFs, Config, ConfigDescription]
1 change: 0 additions & 1 deletion scripts/tools/memory/report_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import memdf.collect
import memdf.report
import memdf.select
import numpy # type: ignore
from memdf import Config, DFs, SymbolDF


Expand Down
7 changes: 2 additions & 5 deletions scripts/tools/silabs/FactoryDataProvider.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,9 @@
#

import argparse
import base64
import datetime
import os
import struct
import subprocess
import sys


class FactoryDataWriter:
Expand Down Expand Up @@ -185,7 +182,7 @@ def add_SerialNo_To_CMD(self, cmdList):
cmdList.extend(["--serialno", self._args.jtagSerial])

def create_nvm3injected_image(self):
""" Use commander command lines create a binary flashable to the EFR32
""" Use commander command lines create a binary flashable to the EFR32
containing the factory commissioning data in NVM3 section
"""
isDeviceConnected = True
Expand All @@ -212,7 +209,7 @@ def create_nvm3injected_image(self):
inputImage = self.BASE_MG24_FILE
else:
raise Exception('Invalid MCU')
except:
except Exception:
isDeviceConnected = False
print("Device not connected")
# When no device is connected user needs to provide the mcu family for which those credentials are to be created
Expand Down
12 changes: 5 additions & 7 deletions scripts/tools/zap/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import sys
import tempfile
import traceback
import urllib.request
from dataclasses import dataclass
from pathlib import Path
from typing import Optional
Expand Down Expand Up @@ -195,7 +194,7 @@ def matterPathFromZapPath(zap_config_path):
if not target_path.endswith(".matter"):
# We expect "something.zap" and don't handle corner cases of
# multiple extensions. This is to work with existing codebase only
raise Error("Unexpected input zap file %s" % self.zap_config)
raise Exception("Unexpected input zap file %s" % zap_config_path)

return target_path

Expand Down Expand Up @@ -290,7 +289,7 @@ def getClangFormatBinary():
print('WARNING: clang-format may not be the right version:')
print(' PIGWEED TAG: %s' % clang_config['tags'][0])
print(' ACTUAL VERSION: %s' % version_string)
except:
except Exception:
print("Failed to validate clang version.")
traceback.print_last()

Expand Down Expand Up @@ -318,12 +317,11 @@ def runClangPrettifier(templates_file, output_dir):
args = [clang_format, '-i']
args.extend(clangOutputs)
subprocess.check_call(args)
err = None
print('Formatted using %s (%s)' % (clang_format, subprocess.check_output([clang_format, '--version'])))
for outputName in clangOutputs:
print(' - %s' % outputName)
except Exception as err:
print('clang-format error:', err)
except subprocess.CalledProcessError as err:
print('clang-format error: %s', err)


class LockFileSerializer:
Expand Down Expand Up @@ -351,7 +349,7 @@ def main():
checkPythonVersion()
cmdLineArgs = runArgumentsParser()

with LockFileSerializer(cmdLineArgs.lock_file) as lock:
with LockFileSerializer(cmdLineArgs.lock_file) as _:
if cmdLineArgs.runBootstrap:
subprocess.check_call(getFilePath("scripts/tools/zap/zap_bootstrap.sh"), shell=True)

Expand Down
1 change: 0 additions & 1 deletion scripts/tools/zap/prune_outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import argparse
import os
import shutil
import sys


def main():
Expand Down
2 changes: 1 addition & 1 deletion scripts/tools/zap/version_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def version_update(log_level, update, new_version):
found_versions = set()
for m in ZAP_VERSION_RE.finditer(file_data):
version = file_data[m.start():m.end()]
if not version in found_versions:
if version not in found_versions:
logging.info('%s currently used in %s', version, name)
found_versions.add(version)

Expand Down
8 changes: 4 additions & 4 deletions scripts/tools/zap/zap_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
try:
import coloredlogs
_has_coloredlogs = True
except:
except ImportError:
_has_coloredlogs = False

# Supported log levels, mapping string values required for argument
Expand All @@ -58,10 +58,10 @@ def _GetDefaultExtractRoot():


def _LogPipeLines(pipe, prefix):
l = logging.getLogger().getChild(prefix)
log = logging.getLogger().getChild(prefix)
for line in iter(pipe.readline, b''):
line = line.strip().decode('utf-8', errors="ignore")
l.info('%s' % line)
log.info('%s' % line)


def _ExecuteProcess(cmd, cwd):
Expand Down Expand Up @@ -93,7 +93,7 @@ def _SetupSourceZap(install_directory: str, zap_version: str):
install_directory
)

_ExecuteProcess(f"npm ci".split(), install_directory)
_ExecuteProcess("npm ci".split(), install_directory)


def _SetupReleaseZap(install_directory: str, zap_version: str):
Expand Down
2 changes: 1 addition & 1 deletion src/app/ota_image_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def show_header(args: object):
print(f'Magic: {magic:x}')
print(f'Total Size: {total_size}')
print(f'Header Size: {header_size}')
print(f'Header TLV:')
print('Header TLV:')

for tag in header_tlv:
tag_name = HeaderTag(tag).name.replace('_', ' ').title()
Expand Down
2 changes: 1 addition & 1 deletion src/tools/chip-cert/dacs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import subprocess
import sys
import typing
from binascii import hexlify, unhexlify
from binascii import unhexlify
from enum import Enum

copyrightNotice = """/*
Expand Down

0 comments on commit 2412753

Please sign in to comment.