Skip to content

Commit ab4509c

Browse files
[python tools] Add to flake8 in workflow and fix python files (part project-chip#25193) (project-chip#27881)
* Flake8 fix error in python tools * Restyled by isort --------- Co-authored-by: Restyled.io <commits@restyled.io>
1 parent 14a3773 commit ab4509c

11 files changed

+21
-38
lines changed

.flake8

-12
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,13 @@ exclude = third_party
66
./examples/common/QRCode/*
77
# temporarily scan only directories with fixed files
88
# TODO: Remove the paths below when all bugs are fixed
9-
src/tools/chip-cert/*
109
build/chip/java/tests/*
1110
build/chip/linux/*
1211
build/config/linux/*
1312
credentials/fetch-paa-certs-from-dcl.py
1413
docs/_extensions/external_content.py
1514
examples/common/pigweed/rpc_console/py/chip_rpc/console.py
1615
examples/lighting-app/python/lighting.py
17-
scripts/tools/check_zcl_file_sync.py
18-
scripts/tools/convert_ini.py
19-
scripts/tools/memory/memdf/__init__.py
20-
scripts/tools/memory/report_summary.py
21-
scripts/tools/silabs/FactoryDataProvider.py
22-
scripts/tools/zap/generate.py
23-
scripts/tools/zap/prune_outputs.py
24-
scripts/tools/zap/version_update.py
25-
scripts/tools/zap/zap_download.py
26-
scripts/tools/zap_convert_all.py
27-
src/app/ota_image_tool.py
2816
src/app/zap_cluster_list.py
2917
src/controller/python/chip/yaml/__init__.py
3018
src/controller/python/chip/yaml/format_converter.py

scripts/tools/check_zcl_file_sync.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,15 @@ def main():
6060
print("%s and %s have unexpected differences." % (base_name, ext_name))
6161
print("Differences between expected and actual:")
6262

63-
for l in difflib.unified_diff(
63+
for line in difflib.unified_diff(
6464
json.dumps(ext_data, indent=2).split('\n'),
6565
json.dumps(base_data, indent=2).split('\n'),
6666
fromfile=ext_name,
6767
tofile="<Expected extension file content>",
6868
):
69-
if l.endswith('\n'):
70-
l = l[:-1]
71-
print(l)
69+
if line.endswith('\n'):
70+
line = line[:-1]
71+
print(line)
7272

7373
return 1
7474

scripts/tools/memory/memdf/__init__.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,7 @@
1515
#
1616
"""Package for working with memory usage information using Pandas DataFrame."""
1717

18-
from memdf.df import DF, SymbolDF, SectionDF, SegmentDF, ExtentDF, DFs
18+
from memdf.df import DF, DFs, ExtentDF, SectionDF, SegmentDF, SymbolDF
1919
from memdf.util.config import Config, ConfigDescription
20+
21+
__all__ = [DF, SymbolDF, SectionDF, SegmentDF, ExtentDF, DFs, Config, ConfigDescription]

scripts/tools/memory/report_summary.py

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import memdf.collect
3232
import memdf.report
3333
import memdf.select
34-
import numpy # type: ignore
3534
from memdf import Config, DFs, SymbolDF
3635

3736

scripts/tools/silabs/FactoryDataProvider.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,9 @@
1515
#
1616

1717
import argparse
18-
import base64
1918
import datetime
2019
import os
21-
import struct
2220
import subprocess
23-
import sys
2421

2522

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

187184
def create_nvm3injected_image(self):
188-
""" Use commander command lines create a binary flashable to the EFR32
185+
""" Use commander command lines create a binary flashable to the EFR32
189186
containing the factory commissioning data in NVM3 section
190187
"""
191188
isDeviceConnected = True
@@ -212,7 +209,7 @@ def create_nvm3injected_image(self):
212209
inputImage = self.BASE_MG24_FILE
213210
else:
214211
raise Exception('Invalid MCU')
215-
except:
212+
except Exception:
216213
isDeviceConnected = False
217214
print("Device not connected")
218215
# When no device is connected user needs to provide the mcu family for which those credentials are to be created

scripts/tools/zap/generate.py

+5-7
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import sys
2525
import tempfile
2626
import traceback
27-
import urllib.request
2827
from dataclasses import dataclass
2928
from pathlib import Path
3029
from typing import Optional
@@ -195,7 +194,7 @@ def matterPathFromZapPath(zap_config_path):
195194
if not target_path.endswith(".matter"):
196195
# We expect "something.zap" and don't handle corner cases of
197196
# multiple extensions. This is to work with existing codebase only
198-
raise Error("Unexpected input zap file %s" % self.zap_config)
197+
raise Exception("Unexpected input zap file %s" % zap_config_path)
199198

200199
return target_path
201200

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

@@ -318,12 +317,11 @@ def runClangPrettifier(templates_file, output_dir):
318317
args = [clang_format, '-i']
319318
args.extend(clangOutputs)
320319
subprocess.check_call(args)
321-
err = None
322320
print('Formatted using %s (%s)' % (clang_format, subprocess.check_output([clang_format, '--version'])))
323321
for outputName in clangOutputs:
324322
print(' - %s' % outputName)
325-
except Exception as err:
326-
print('clang-format error:', err)
323+
except subprocess.CalledProcessError as err:
324+
print('clang-format error: %s', err)
327325

328326

329327
class LockFileSerializer:
@@ -351,7 +349,7 @@ def main():
351349
checkPythonVersion()
352350
cmdLineArgs = runArgumentsParser()
353351

354-
with LockFileSerializer(cmdLineArgs.lock_file) as lock:
352+
with LockFileSerializer(cmdLineArgs.lock_file) as _:
355353
if cmdLineArgs.runBootstrap:
356354
subprocess.check_call(getFilePath("scripts/tools/zap/zap_bootstrap.sh"), shell=True)
357355

scripts/tools/zap/prune_outputs.py

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import argparse
1717
import os
1818
import shutil
19-
import sys
2019

2120

2221
def main():

scripts/tools/zap/version_update.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def version_update(log_level, update, new_version):
125125
found_versions = set()
126126
for m in ZAP_VERSION_RE.finditer(file_data):
127127
version = file_data[m.start():m.end()]
128-
if not version in found_versions:
128+
if version not in found_versions:
129129
logging.info('%s currently used in %s', version, name)
130130
found_versions.add(version)
131131

scripts/tools/zap/zap_download.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
try:
3333
import coloredlogs
3434
_has_coloredlogs = True
35-
except:
35+
except ImportError:
3636
_has_coloredlogs = False
3737

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

5959

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

6666

6767
def _ExecuteProcess(cmd, cwd):
@@ -93,7 +93,7 @@ def _SetupSourceZap(install_directory: str, zap_version: str):
9393
install_directory
9494
)
9595

96-
_ExecuteProcess(f"npm ci".split(), install_directory)
96+
_ExecuteProcess("npm ci".split(), install_directory)
9797

9898

9999
def _SetupReleaseZap(install_directory: str, zap_version: str):

src/app/ota_image_tool.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ def show_header(args: object):
262262
print(f'Magic: {magic:x}')
263263
print(f'Total Size: {total_size}')
264264
print(f'Header Size: {header_size}')
265-
print(f'Header TLV:')
265+
print('Header TLV:')
266266

267267
for tag in header_tlv:
268268
tag_name = HeaderTag(tag).name.replace('_', ' ').title()

src/tools/chip-cert/dacs.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import subprocess
66
import sys
77
import typing
8-
from binascii import hexlify, unhexlify
8+
from binascii import unhexlify
99
from enum import Enum
1010

1111
copyrightNotice = """/*

0 commit comments

Comments
 (0)