Skip to content

Commit

Permalink
Add isort formatter to restyled configuration (#24148)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
2 people authored and pull[bot] committed Jul 18, 2023
1 parent fc7639f commit 1969145
Show file tree
Hide file tree
Showing 211 changed files with 763 additions and 859 deletions.
2 changes: 2 additions & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[settings]
line_length = 132
11 changes: 10 additions & 1 deletion .restyled.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ restylers:
- "**/*.sh"
- "**/*.bash"
- name: autopep8
image: 'restyled/restyler-autopep8:v1.5.7'
image: 'restyled/restyler-autopep8:v2.0.0'
command:
- autopep8
- '--in-place'
Expand All @@ -222,3 +222,12 @@ restylers:
- '**/*.py'
interpreters:
- python
- name: isort
image: 'restyled/restyler-isort:v5.11.2'
command:
- isort
arguments: []
include:
- '**/*.py'
interpreters:
- python
2 changes: 1 addition & 1 deletion build/chip/java/tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@

import json
import os
from os import path
import subprocess
import unittest
from os import path


class JavaBuildTest(unittest.TestCase):
Expand Down
2 changes: 1 addition & 1 deletion build/config/linux/pkg-config.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@

import json
import os
import re
import subprocess
import sys
import re
from optparse import OptionParser

# This script runs pkg-config, optionally filtering out some results, and
Expand Down
2 changes: 1 addition & 1 deletion config/esp32/components/chip/create_args_gn.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
# Component makefile for building CHIP within the ESP32 ESP-IDF environment.
#

import argparse
import json
import os
import argparse

# Parse the build's compile_commands.json to generate
# final args file for CHIP build.
Expand Down
15 changes: 8 additions & 7 deletions credentials/fetch-paa-certs-from-dcl.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,18 @@
# For usage please run:.
# python ./credentials/fetch-paa-certs-from-dcl.py --help

from contextlib import nullcontext
import os
import sys
import subprocess
import copy
import os
import re
from cryptography.hazmat.primitives import serialization
from cryptography import x509
import subprocess
import sys
from contextlib import nullcontext

import click
from click_option_group import optgroup, RequiredMutuallyExclusiveOptionGroup
import requests
from click_option_group import RequiredMutuallyExclusiveOptionGroup, optgroup
from cryptography import x509
from cryptography.hazmat.primitives import serialization

PRODUCTION_NODE_URL = "https://on.dcl.csa-iot.org:26657"
PRODUCTION_NODE_URL_REST = "https://on.dcl.csa-iot.org"
Expand Down
2 changes: 1 addition & 1 deletion examples/all-clusters-app/linux/entitlements/codesign.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
# limitations under the License.

import argparse
import subprocess
import re
import subprocess


def run_command(command):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
# limitations under the License.

import argparse
import subprocess
import re
import subprocess


def run_command(command):
Expand Down
9 changes: 4 additions & 5 deletions examples/chef/chef.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,16 @@
import json
import optparse
import os
import re
import shutil
import sys
import tarfile
import textwrap
from typing import Any, Dict, Sequence

import yaml
import re

import constants
import stateful_shell
import yaml
from sample_app_util import zap_file_parser

TermColors = constants.TermColors
Expand Down Expand Up @@ -876,14 +875,14 @@ def main() -> int:
f"python3 -m chip_rpc.console --device {config['esp32']['TTY']}")
elif (options.build_target == "silabs-thread"):
if (sys.platform == "linux") or (sys.platform == "linux2"):
if(config['silabs-thread']['TTY'] is None):
if (config['silabs-thread']['TTY'] is None):
flush_print(
'The path for the serial enumeration for silabs-thread is not set. Make sure silabs-thread.TTY is set on your config.yaml file')
exit(1)
shell.run_cmd(
f"python3 -m chip_rpc.console --device {config['silabs-thread']['TTY']} -b 115200")
elif sys.platform == "darwin":
if(config['silabs-thread']['CU'] is None):
if (config['silabs-thread']['CU'] is None):
flush_print(
'The path for the serial enumeration for silabs-thread is not set. Make sure silabs-thread.CU is set on your config.yaml file')
exit(1)
Expand Down
5 changes: 3 additions & 2 deletions examples/chef/create_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import argparse
import tarfile
import os
import shutil
import tarfile

import docker

client = docker.from_env()
Expand Down
4 changes: 2 additions & 2 deletions examples/chef/sample_app_util/test_zap_file_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
import tempfile
import unittest

import zap_file_parser

try:
import yaml
except ImportError:
print("Missing yaml library. Install with:\npip install pyyaml")
exit(1)

import zap_file_parser


_HERE = os.path.abspath(os.path.dirname(__file__))
_TEST_FILE = os.path.join(_HERE, "test_files", "sample_zap_file.zap")
Expand Down
3 changes: 1 addition & 2 deletions examples/chef/sample_app_util/zap_file_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,12 @@
available.
- Add support for .matter files.
"""
import copy
import base64
import copy
import hashlib
import json
import os
import re

from typing import Dict, List, Literal, Optional, Sequence, TypedDict, Union

try:
Expand Down
17 changes: 8 additions & 9 deletions examples/common/pigweed/rpc_console/py/chip_rpc/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,32 +37,31 @@
"""

import argparse
from typing import Callable
from collections import namedtuple
from inspect import cleandoc
import logging
import re
import socket
from concurrent.futures import ThreadPoolExecutor
import sys
import threading
from typing import Any, BinaryIO, Collection
from collections import namedtuple
from concurrent.futures import ThreadPoolExecutor
from inspect import cleandoc
from typing import Any, BinaryIO, Callable, Collection

import pw_cli.log
from chip_rpc.plugins.device_toolbar import DeviceToolbar
from chip_rpc.plugins.helper_scripts import HelperScripts
import pw_cli.log
from pw_console import PwConsoleEmbed
from pw_console.__main__ import create_temp_log_file
from pw_console.pyserial_wrapper import SerialWithLogging
from pw_hdlc.rpc import HdlcRpcClient, default_channels
from pw_rpc import callback_client
from pw_rpc.console_tools.console import ClientInfo, flattened_rpc_completions

from pw_tokenizer.database import LoadTokenDatabases
from pw_tokenizer.detokenize import Detokenizer, detokenize_base64
from pw_tokenizer import tokens
from pw_tokenizer.database import LoadTokenDatabases
from pw_tokenizer.detokenize import Detokenizer

# Protos
# isort: off
from attributes_service import attributes_service_pb2
from button_service import button_service_pb2
from descriptor_service import descriptor_service_pb2
Expand Down
2 changes: 1 addition & 1 deletion examples/darwin-framework-tool/entitlements/codesign.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
# limitations under the License.

import argparse
import subprocess
import re
import subprocess


def run_command(command):
Expand Down
28 changes: 9 additions & 19 deletions examples/lighting-app/python/lighting.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,20 @@
# limitations under the License.
#

from chip.server import (
GetLibraryHandle,
NativeLibraryHandleMethodArguments,
PostAttributeChangeCallback,
)

from chip.exceptions import ChipStackError

from ctypes import CFUNCTYPE, c_char_p, c_int32, c_uint8

import sys
import asyncio
import os

import textwrap
import string

from cmd import Cmd

import asyncio
import sys
import textwrap
import threading
from cmd import Cmd
from ctypes import CFUNCTYPE, c_char_p, c_int32, c_uint8

from dali.driver.hid import tridonic
from dali.gear.general import RecallMaxLevel, Off, DAPC
from chip.exceptions import ChipStackError
from chip.server import GetLibraryHandle, NativeLibraryHandleMethodArguments, PostAttributeChangeCallback
from dali.address import Broadcast, Short
from dali.driver.hid import tridonic
from dali.gear.general import DAPC, Off, RecallMaxLevel

dali_loop = None
dev = None
Expand Down
7 changes: 3 additions & 4 deletions examples/pigweed-app/mobly_tests/echo_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from chip_mobly import pigweed_device
from mobly import asserts
from mobly import base_test
from mobly import test_runner
import time

from chip_mobly import pigweed_device
from mobly import asserts, base_test, test_runner


class PigweedEchoTest(base_test.BaseTestClass):
def setup_class(self):
Expand Down
9 changes: 5 additions & 4 deletions examples/platform/nxp/k32w/k32w0/scripts/detokenizer.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import argparse
import sys
import os
import serial
import sys

import pw_tokenizer
import serial


def parse_args():
Expand Down Expand Up @@ -75,8 +76,8 @@ def decode_serial(serialport, outfile, database):
if input:

try:
while(True):
if(input.in_waiting > 0):
while (True):
if (input.in_waiting > 0):
# read line from serial port and ascii decode
line = input.readline().decode('ascii').strip()
# find token start and detokenize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import sys
import subprocess
import logging
import subprocess
import sys
import time
import click
from pathlib import Path
from dataclasses import dataclass
from enum import Enum
from multiprocessing.connection import Listener, Client
from multiprocessing.connection import Client, Listener
from pathlib import Path

import click

log = logging.getLogger()
log.setLevel(logging.DEBUG)
Expand Down
4 changes: 2 additions & 2 deletions integrations/mobly/build/lib/chip_mobly/pigweed_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import importlib
import os
from pathlib import Path
import serial # type: ignore
import importlib

import serial # type: ignore
from pw_hdlc.rpc import HdlcRpcClient

# Point the script to the .proto file with our RPC services.
Expand Down
4 changes: 2 additions & 2 deletions integrations/mobly/chip_mobly/pigweed_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import importlib
import os
from pathlib import Path
import serial # type: ignore
import importlib

import serial # type: ignore
from pw_hdlc.rpc import HdlcRpcClient, default_channels

# Point the script to the .proto file with our RPC services.
Expand Down
3 changes: 1 addition & 2 deletions integrations/mobly/hello_world_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@

from chip_mobly import pigweed_device
from mobly import asserts # type: ignore
from mobly import base_test
from mobly import test_runner
from mobly import base_test, test_runner


class HelloWorldTest(base_test.BaseTestClass):
Expand Down
4 changes: 1 addition & 3 deletions scripts/build/build/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,11 @@
import logging
import os
import re

from dataclasses import dataclass
from typing import Any, Dict, List, Iterable, Optional
from typing import Any, Dict, Iterable, List, Optional

from builders.builder import BuilderOptions


report_rejected_parts = True


Expand Down
Loading

0 comments on commit 1969145

Please sign in to comment.