Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Map "chip" Python imports as first-party #37138

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/.wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1162,6 +1162,7 @@ PyFunction
pylint
PyObject
pypi
pyproject
PyRun
pytest
QEMU
Expand Down
2 changes: 0 additions & 2 deletions .isort.cfg

This file was deleted.

2 changes: 0 additions & 2 deletions .restyled.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,6 @@ restylers:
command:
- autopep8
- "--in-place"
- "--max-line-length"
- "132"
arguments: []
include:
- "**/*.py"
Expand Down
30 changes: 14 additions & 16 deletions docs/style/CODING_STYLE_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,20 @@ be removed.

We use the following auto-formatters on code:

| Language | Formatter | Style File |
| ----------- | ------------------ | ------------------------------------------------------------------------------------------ |
| C++ | clang-format | [.clang-format](https://github.com/project-chip/connectedhomeip/blob/master/.clang-format) |
| Objective-C | clang-format | [.clang-format](https://github.com/project-chip/connectedhomeip/blob/master/.clang-format) |
| java | google-java-format | N/A |
| Python | pep8, isort, ruff | [.restyled.yaml][restyle_link] (command line), [isort][isort_link], [ruff][ruff_link] |
| YAML | prettier | None |
| JSON | prettier | None |
| markdown | prettier | None |

[restyle_link]:
https://github.com/project-chip/connectedhomeip/blob/master/.restyled.yaml
[isort_link]:
https://github.com/project-chip/connectedhomeip/blob/master/.isort.cfg
[ruff_link]:
https://github.com/project-chip/connectedhomeip/blob/master/ruff.toml
| Language | Formatter | Style File |
| ----------- | ------------------ | ---------------------------------- |
| C++ | clang-format | [.clang-format][clang_format_link] |
| Objective-C | clang-format | [.clang-format][clang_format_link] |
| java | google-java-format | N/A |
| Python | pep8, isort, ruff | [pyproject.toml][pyproject_link] |
| YAML | prettier | None |
| JSON | prettier | None |
| markdown | prettier | None |

[clang_format_link]:
https://github.com/project-chip/connectedhomeip/blob/master/.clang-format
[pyproject_link]:
https://github.com/project-chip/connectedhomeip/blob/master/pyproject.toml

All pull requests run formatting checks using these tools before merge is
allowed. Generated code is not run through restyle.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
"""

from prompt_toolkit.layout import WindowAlign

from pw_console.plugin_mixin import PluginMixin
from pw_console.widgets import ToolbarButton, WindowPaneToolbar

Expand Down
3 changes: 2 additions & 1 deletion examples/lighting-app/python/lighting.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@
import threading
from cmd import Cmd

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

from chip.server import GetLibraryHandle, PostAttributeChangeCallback

dali_loop = None
dev = None

Expand Down
17 changes: 12 additions & 5 deletions ruff.toml → pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
[tool.autopep8]
max_line_length = 132

[tool.isort]
line_length = 132
known_first_party = "chip"

[tool.ruff]
line-length = 132
target-version = "py310"
exclude = [
".environment",
".git",
Expand All @@ -8,12 +18,9 @@ exclude = [
"third_party",
"examples/common/QRCode/",
]
target-version = "py310"

line-length = 132

[lint]
[tool.ruff.lint]
select = ["E4", "E7", "E9", "F"]
ignore = [
"E721" # We use it for good reasons
"E721", # We use it for good reasons
]
4 changes: 2 additions & 2 deletions scripts/py_matter_idl/matter_idl/zapxml/handlers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from matter_idl.matter_idl_types import Idl

from .base import BaseHandler
from .context import Context
from .handlers import ConfiguratorHandler

from matter_idl.matter_idl_types import Idl


class ZapXmlHandler(BaseHandler):
"""Handles the top level (/) of a zap xml file.
Expand Down
7 changes: 4 additions & 3 deletions scripts/tests/chiptest/yamltest_with_chip_repl_tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,14 @@
__ALL__ = (matter_idl_types)


import click
from matter_yamltests.definitions import SpecDefinitionsFromPaths
from matter_yamltests.parser import PostProcessCheckStatus, TestParser, TestParserConfig

import chip.CertificateAuthority
import chip.native
import click
from chip.ChipStack import ChipStack
from chip.yaml.runner import ReplTestRunner
from matter_yamltests.definitions import SpecDefinitionsFromPaths
from matter_yamltests.parser import PostProcessCheckStatus, TestParser, TestParserConfig

_DEFAULT_CHIP_ROOT = os.path.abspath(
os.path.join(os.path.dirname(__file__), "..", "..", ".."))
Expand Down
3 changes: 2 additions & 1 deletion scripts/tests/run_python_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@

import click
import coloredlogs
from colorama import Fore, Style

from chip.testing.metadata import Metadata, MetadataReader
from chip.testing.tasks import Subprocess
from colorama import Fore, Style

DEFAULT_CHIP_ROOT = os.path.abspath(
os.path.join(os.path.dirname(__file__), '..', '..'))
Expand Down
7 changes: 4 additions & 3 deletions src/controller/python/chip/ChipReplStartup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
import os
import pathlib

import coloredlogs
from rich import inspect, pretty
from rich.console import Console

import chip.CertificateAuthority
import chip.FabricAdmin
import chip.logging
import chip.native
import coloredlogs
from chip.ChipStack import ChipStack
from rich import inspect, pretty
from rich.console import Console

_fabricAdmins = None

Expand Down
5 changes: 3 additions & 2 deletions src/controller/python/chip/clusters/Attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@
from enum import Enum, unique
from typing import Any, Callable, Dict, List, Optional, Set, Tuple, Union

import construct # type: ignore
from rich.pretty import pprint # type: ignore

import chip
import chip.exceptions
import chip.interaction_model
import chip.tlv
import construct # type: ignore
from chip.interaction_model import PyWriteAttributeData
from chip.native import ErrorSDKPart, PyChipError
from rich.pretty import pprint # type: ignore

from .ClusterObjects import Cluster, ClusterAttributeDescriptor, ClusterEvent

Expand Down
3 changes: 2 additions & 1 deletion src/controller/python/chip/clusters/ClusterObjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
from dataclasses import asdict, dataclass, field, make_dataclass
from typing import Any, ClassVar, Dict, List, Mapping, Union

from dacite import from_dict # type: ignore

from chip import ChipUtility, tlv
from chip.clusters.Types import Nullable, NullValue
from dacite import from_dict # type: ignore


def GetUnionUnderlyingType(typeToCheck, matchingType=None):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@
import base64
import logging

from cryptography import x509
from cryptography.hazmat.primitives import serialization

import chip.credentials.cert
import chip.crypto.fabric
from chip import ChipDeviceCtrl
from chip import clusters as Clusters
from chip import commissioning
from cryptography import x509
from cryptography.hazmat.primitives import serialization


class CommissioningFlowBlocks:
Expand Down
3 changes: 2 additions & 1 deletion src/controller/python/chip/crypto/p256keypair.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@
string_at)
from typing import TYPE_CHECKING

from chip import native
from ecdsa import ECDH, NIST256p, SigningKey # type: ignore

from chip import native

# WORKAROUND: Create a subscriptable pointer type (with square brackets) to ensure compliance of type hinting with ctypes
if not TYPE_CHECKING:
class pointer_fix:
Expand Down
3 changes: 2 additions & 1 deletion src/controller/python/chip/interaction_model/delegate.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@
from dataclasses import dataclass
from typing import Any, Dict, Optional

from construct import Int8ul, Int16ul, Int32ul, Int64ul, Struct # type: ignore

import chip.exceptions
import chip.native
import chip.tlv
from construct import Int8ul, Int16ul, Int32ul, Int64ul, Struct # type: ignore

# The type should match CommandStatus in interaction_model/Delegate.h
# CommandStatus should not contain padding
Expand Down
3 changes: 2 additions & 1 deletion src/controller/python/chip/native/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@
import typing
from dataclasses import dataclass

import chip.exceptions
import construct # type: ignore

import chip.exceptions


class Library(enum.Enum):
CONTROLLER = "_ChipDeviceCtrl.so"
Expand Down
3 changes: 2 additions & 1 deletion src/controller/python/chip/yaml/format_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
import typing
from dataclasses import dataclass

from matter_idl import matter_idl_types

from chip.clusters.enum import MatterIntEnum
from chip.clusters.Types import Nullable, NullValue
from chip.tlv import float32, uint
from chip.yaml.errors import ValidationError
from matter_idl import matter_idl_types


@dataclass
Expand Down
5 changes: 3 additions & 2 deletions src/controller/python/chip/yaml/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
from enum import Enum, IntEnum
from typing import Any, Optional, Tuple

from matter_idl.generators.filters import to_pascal_case, to_snake_case
from matter_yamltests.pseudo_clusters.pseudo_clusters import get_default_pseudo_clusters

import chip.interaction_model
import chip.yaml.format_converter as Converter
from chip.ChipDeviceCtrl import ChipDeviceController, discovery
Expand All @@ -31,8 +34,6 @@
from chip.exceptions import ChipStackError
from chip.yaml.data_model_lookup import DataModelLookup
from chip.yaml.errors import ActionCreationError, UnexpectedActionCreationError
from matter_idl.generators.filters import to_pascal_case, to_snake_case
from matter_yamltests.pseudo_clusters.pseudo_clusters import get_default_pseudo_clusters

from .data_model_lookup import PreDefinedDataModelLookup

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from chip.yaml.runner import ReplTestRunner
from matter_yamltests.adapter import TestAdapter

from chip.yaml.runner import ReplTestRunner


class Adapter(TestAdapter):
def __init__(self, specifications):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@

# isort: on

from matter_yamltests.runner import TestRunner

import chip.CertificateAuthority
import chip.logging
import chip.native
from chip.ChipStack import ChipStack
from chip.yaml.runner import ReplTestRunner
from matter_yamltests.runner import TestRunner


class Runner(TestRunner):
Expand Down
5 changes: 3 additions & 2 deletions src/controller/python/test/test_scripts/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
from dataclasses import dataclass
from typing import Any

from cirque_restart_remote_device import restartRemoteDevice
from ecdsa import NIST256p

import chip.CertificateAuthority
import chip.clusters as Clusters
import chip.clusters.Attribute as Attribute
Expand All @@ -43,8 +46,6 @@
from chip.crypto import p256keypair
from chip.exceptions import ChipStackException
from chip.utils import CommissioningBuildingBlocks
from cirque_restart_remote_device import restartRemoteDevice
from ecdsa import NIST256p

logger = logging.getLogger('PythonMatterControllerTEST')
logger.setLevel(logging.INFO)
Expand Down
1 change: 1 addition & 0 deletions src/controller/python/test/test_scripts/cluster_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import pprint

import base

import chip.clusters as Clusters
import chip.exceptions
import chip.interaction_model
Expand Down
5 changes: 3 additions & 2 deletions src/controller/python/test/test_scripts/mobile-device-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,15 @@
import os

import base
import chip.logging
import click
import coloredlogs
from base import BaseTestHelper, FailIfNot, SetTestSet, TestFail, TestTimeout, logger
from chip.tracing import TracingContext
from cluster_objects import ClusterObjectTests
from network_commissioning import NetworkCommissioningTests

import chip.logging
from chip.tracing import TracingContext

# The thread network dataset tlv for testing, splitted into T-L-V.

TEST_THREAD_NETWORK_DATASET_TLV = "0e080000000000010000" + \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import random

import base

import chip.clusters as Clusters
import chip.interaction_model
from chip.clusters.Types import NullValue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import example_python_commissioning_flow
from base import BaseTestHelper, TestFail, TestTimeout, logger

from chip import ChipDeviceCtrl
from chip import clusters as Clusters
from chip import commissioning
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from optparse import OptionParser

from base import BaseTestHelper, FailIfNot, TestFail, TestTimeout, logger

from chip import clusters as Clusters

TEST_DISCRIMINATOR = 3840
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import unittest

from rich.pretty import pprint

import chip.clusters as Clusters
from chip.clusters.Types import NullValue
from rich.pretty import pprint

'''
This file contains tests for validating the generated cluster objects by running encoding and decoding
Expand Down
Loading
Loading