Skip to content

Commit d5bfb4b

Browse files
Add isort formatter to restyled configuration (project-chip#24148)
* Add isort formatter to restyled configuration * Sort Python imports using isort tool This commit also removes unused imports (reported by flake8) in few places. * Restyled by autopep8 * Restyled by isort * Update ZAP template for cluster Objects * Fix E402 suppressions in connection with isort * Fix imports which depend on modified sys path * Fix circular dependency when importing FabricAdmin * Restyled by isort Co-authored-by: Restyled.io <commits@restyled.io>
1 parent feca44a commit d5bfb4b

File tree

211 files changed

+763
-859
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

211 files changed

+763
-859
lines changed

.isort.cfg

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[settings]
2+
line_length = 132

.restyled.yaml

+10-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ restylers:
213213
- "**/*.sh"
214214
- "**/*.bash"
215215
- name: autopep8
216-
image: 'restyled/restyler-autopep8:v1.5.7'
216+
image: 'restyled/restyler-autopep8:v2.0.0'
217217
command:
218218
- autopep8
219219
- '--in-place'
@@ -222,3 +222,12 @@ restylers:
222222
- '**/*.py'
223223
interpreters:
224224
- python
225+
- name: isort
226+
image: 'restyled/restyler-isort:v5.11.2'
227+
command:
228+
- isort
229+
arguments: []
230+
include:
231+
- '**/*.py'
232+
interpreters:
233+
- python

build/chip/java/tests/test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818

1919
import json
2020
import os
21-
from os import path
2221
import subprocess
2322
import unittest
23+
from os import path
2424

2525

2626
class JavaBuildTest(unittest.TestCase):

build/config/linux/pkg-config.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@
3232

3333
import json
3434
import os
35+
import re
3536
import subprocess
3637
import sys
37-
import re
3838
from optparse import OptionParser
3939

4040
# This script runs pkg-config, optionally filtering out some results, and

config/esp32/components/chip/create_args_gn.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
# Component makefile for building CHIP within the ESP32 ESP-IDF environment.
2020
#
2121

22+
import argparse
2223
import json
2324
import os
24-
import argparse
2525

2626
# Parse the build's compile_commands.json to generate
2727
# final args file for CHIP build.

credentials/fetch-paa-certs-from-dcl.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,18 @@
2121
# For usage please run:.
2222
# python ./credentials/fetch-paa-certs-from-dcl.py --help
2323

24-
from contextlib import nullcontext
25-
import os
26-
import sys
27-
import subprocess
2824
import copy
25+
import os
2926
import re
30-
from cryptography.hazmat.primitives import serialization
31-
from cryptography import x509
27+
import subprocess
28+
import sys
29+
from contextlib import nullcontext
30+
3231
import click
33-
from click_option_group import optgroup, RequiredMutuallyExclusiveOptionGroup
3432
import requests
33+
from click_option_group import RequiredMutuallyExclusiveOptionGroup, optgroup
34+
from cryptography import x509
35+
from cryptography.hazmat.primitives import serialization
3536

3637
PRODUCTION_NODE_URL = "https://on.dcl.csa-iot.org:26657"
3738
PRODUCTION_NODE_URL_REST = "https://on.dcl.csa-iot.org"

examples/all-clusters-app/linux/entitlements/codesign.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
# limitations under the License.
1616

1717
import argparse
18-
import subprocess
1918
import re
19+
import subprocess
2020

2121

2222
def run_command(command):

examples/all-clusters-minimal-app/linux/entitlements/codesign.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
# limitations under the License.
1616

1717
import argparse
18-
import subprocess
1918
import re
19+
import subprocess
2020

2121

2222
def run_command(command):

examples/chef/chef.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,16 @@
1818
import json
1919
import optparse
2020
import os
21+
import re
2122
import shutil
2223
import sys
2324
import tarfile
2425
import textwrap
2526
from typing import Any, Dict, Sequence
2627

27-
import yaml
28-
import re
29-
3028
import constants
3129
import stateful_shell
30+
import yaml
3231
from sample_app_util import zap_file_parser
3332

3433
TermColors = constants.TermColors
@@ -876,14 +875,14 @@ def main() -> int:
876875
f"python3 -m chip_rpc.console --device {config['esp32']['TTY']}")
877876
elif (options.build_target == "silabs-thread"):
878877
if (sys.platform == "linux") or (sys.platform == "linux2"):
879-
if(config['silabs-thread']['TTY'] is None):
878+
if (config['silabs-thread']['TTY'] is None):
880879
flush_print(
881880
'The path for the serial enumeration for silabs-thread is not set. Make sure silabs-thread.TTY is set on your config.yaml file')
882881
exit(1)
883882
shell.run_cmd(
884883
f"python3 -m chip_rpc.console --device {config['silabs-thread']['TTY']} -b 115200")
885884
elif sys.platform == "darwin":
886-
if(config['silabs-thread']['CU'] is None):
885+
if (config['silabs-thread']['CU'] is None):
887886
flush_print(
888887
'The path for the serial enumeration for silabs-thread is not set. Make sure silabs-thread.CU is set on your config.yaml file')
889888
exit(1)

examples/chef/create_docker.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
import os
1817
import argparse
19-
import tarfile
18+
import os
2019
import shutil
20+
import tarfile
21+
2122
import docker
2223

2324
client = docker.from_env()

examples/chef/sample_app_util/test_zap_file_parser.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
import tempfile
1010
import unittest
1111

12+
import zap_file_parser
13+
1214
try:
1315
import yaml
1416
except ImportError:
1517
print("Missing yaml library. Install with:\npip install pyyaml")
1618
exit(1)
1719

18-
import zap_file_parser
19-
2020

2121
_HERE = os.path.abspath(os.path.dirname(__file__))
2222
_TEST_FILE = os.path.join(_HERE, "test_files", "sample_zap_file.zap")

examples/chef/sample_app_util/zap_file_parser.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,12 @@
2929
available.
3030
- Add support for .matter files.
3131
"""
32-
import copy
3332
import base64
33+
import copy
3434
import hashlib
3535
import json
3636
import os
3737
import re
38-
3938
from typing import Dict, List, Literal, Optional, Sequence, TypedDict, Union
4039

4140
try:

examples/common/pigweed/rpc_console/py/chip_rpc/console.py

+8-9
Original file line numberDiff line numberDiff line change
@@ -37,32 +37,31 @@
3737
"""
3838

3939
import argparse
40-
from typing import Callable
41-
from collections import namedtuple
42-
from inspect import cleandoc
4340
import logging
4441
import re
4542
import socket
46-
from concurrent.futures import ThreadPoolExecutor
4743
import sys
4844
import threading
49-
from typing import Any, BinaryIO, Collection
45+
from collections import namedtuple
46+
from concurrent.futures import ThreadPoolExecutor
47+
from inspect import cleandoc
48+
from typing import Any, BinaryIO, Callable, Collection
5049

50+
import pw_cli.log
5151
from chip_rpc.plugins.device_toolbar import DeviceToolbar
5252
from chip_rpc.plugins.helper_scripts import HelperScripts
53-
import pw_cli.log
5453
from pw_console import PwConsoleEmbed
5554
from pw_console.__main__ import create_temp_log_file
5655
from pw_console.pyserial_wrapper import SerialWithLogging
5756
from pw_hdlc.rpc import HdlcRpcClient, default_channels
5857
from pw_rpc import callback_client
5958
from pw_rpc.console_tools.console import ClientInfo, flattened_rpc_completions
60-
61-
from pw_tokenizer.database import LoadTokenDatabases
62-
from pw_tokenizer.detokenize import Detokenizer, detokenize_base64
6359
from pw_tokenizer import tokens
60+
from pw_tokenizer.database import LoadTokenDatabases
61+
from pw_tokenizer.detokenize import Detokenizer
6462

6563
# Protos
64+
# isort: off
6665
from attributes_service import attributes_service_pb2
6766
from button_service import button_service_pb2
6867
from descriptor_service import descriptor_service_pb2

examples/darwin-framework-tool/entitlements/codesign.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
# limitations under the License.
1616

1717
import argparse
18-
import subprocess
1918
import re
19+
import subprocess
2020

2121

2222
def run_command(command):

examples/lighting-app/python/lighting.py

+9-19
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,20 @@
1414
# limitations under the License.
1515
#
1616

17-
from chip.server import (
18-
GetLibraryHandle,
19-
NativeLibraryHandleMethodArguments,
20-
PostAttributeChangeCallback,
21-
)
22-
23-
from chip.exceptions import ChipStackError
24-
25-
from ctypes import CFUNCTYPE, c_char_p, c_int32, c_uint8
26-
27-
import sys
17+
import asyncio
2818
import os
29-
30-
import textwrap
3119
import string
32-
33-
from cmd import Cmd
34-
35-
import asyncio
20+
import sys
21+
import textwrap
3622
import threading
23+
from cmd import Cmd
24+
from ctypes import CFUNCTYPE, c_char_p, c_int32, c_uint8
3725

38-
from dali.driver.hid import tridonic
39-
from dali.gear.general import RecallMaxLevel, Off, DAPC
26+
from chip.exceptions import ChipStackError
27+
from chip.server import GetLibraryHandle, NativeLibraryHandleMethodArguments, PostAttributeChangeCallback
4028
from dali.address import Broadcast, Short
29+
from dali.driver.hid import tridonic
30+
from dali.gear.general import DAPC, Off, RecallMaxLevel
4131

4232
dali_loop = None
4333
dev = None

examples/pigweed-app/mobly_tests/echo_test.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from chip_mobly import pigweed_device
16-
from mobly import asserts
17-
from mobly import base_test
18-
from mobly import test_runner
1915
import time
2016

17+
from chip_mobly import pigweed_device
18+
from mobly import asserts, base_test, test_runner
19+
2120

2221
class PigweedEchoTest(base_test.BaseTestClass):
2322
def setup_class(self):

examples/platform/nxp/k32w/k32w0/scripts/detokenizer.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import argparse
2-
import sys
32
import os
4-
import serial
3+
import sys
4+
55
import pw_tokenizer
6+
import serial
67

78

89
def parse_args():
@@ -75,8 +76,8 @@ def decode_serial(serialport, outfile, database):
7576
if input:
7677

7778
try:
78-
while(True):
79-
if(input.in_waiting > 0):
79+
while (True):
80+
if (input.in_waiting > 0):
8081
# read line from serial port and ascii decode
8182
line = input.readline().decode('ascii').strip()
8283
# find token start and detokenize

integrations/docker/ci-only-images/chip-cirque-device-base/CHIPCirqueDaemon.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,16 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
import sys
18-
import subprocess
1917
import logging
18+
import subprocess
19+
import sys
2020
import time
21-
import click
22-
from pathlib import Path
2321
from dataclasses import dataclass
2422
from enum import Enum
25-
from multiprocessing.connection import Listener, Client
23+
from multiprocessing.connection import Client, Listener
24+
from pathlib import Path
25+
26+
import click
2627

2728
log = logging.getLogger()
2829
log.setLevel(logging.DEBUG)

integrations/mobly/build/lib/chip_mobly/pigweed_device.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import importlib
1516
import os
1617
from pathlib import Path
17-
import serial # type: ignore
18-
import importlib
1918

19+
import serial # type: ignore
2020
from pw_hdlc.rpc import HdlcRpcClient
2121

2222
# Point the script to the .proto file with our RPC services.

integrations/mobly/chip_mobly/pigweed_device.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import importlib
1516
import os
1617
from pathlib import Path
17-
import serial # type: ignore
18-
import importlib
1918

19+
import serial # type: ignore
2020
from pw_hdlc.rpc import HdlcRpcClient, default_channels
2121

2222
# Point the script to the .proto file with our RPC services.

integrations/mobly/hello_world_test.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414

1515
from chip_mobly import pigweed_device
1616
from mobly import asserts # type: ignore
17-
from mobly import base_test
18-
from mobly import test_runner
17+
from mobly import base_test, test_runner
1918

2019

2120
class HelloWorldTest(base_test.BaseTestClass):

scripts/build/build/target.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,11 @@
4242
import logging
4343
import os
4444
import re
45-
4645
from dataclasses import dataclass
47-
from typing import Any, Dict, List, Iterable, Optional
46+
from typing import Any, Dict, Iterable, List, Optional
4847

4948
from builders.builder import BuilderOptions
5049

51-
5250
report_rejected_parts = True
5351

5452

0 commit comments

Comments
 (0)