Skip to content

Commit

Permalink
Add to flake8 in workflow and fix python files (#25272)
Browse files Browse the repository at this point in the history
  • Loading branch information
DamMicSzm authored and pull[bot] committed Jun 27, 2023
1 parent 29d2797 commit 1078806
Show file tree
Hide file tree
Showing 18 changed files with 267 additions and 87 deletions.
145 changes: 145 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -1,2 +1,147 @@
[flake8]
max-line-length = 132
exclude = third_party
.*
out/*
scripts/idl/*
./examples/common/QRCode/*
# temporarily scan only directories with fixed files
# TODO: Remove the paths below when all bugs are fixed
src/tools/chip-cert/*
src/test_driver/openiotsdk/*
src/test_driver/mbed/*
src/test_driver/linux-cirque/*
src/test_driver/esp32/*
src/test_driver/efr32/*
build/chip/java/tests/*
build/chip/linux/*
build/config/linux/*
credentials/fetch-paa-certs-from-dcl.py
docs/_extensions/external_content.py
examples/chef/chef.py
examples/chef/sample_app_util/zap_file_parser.py
examples/common/pigweed/rpc_console/py/chip_rpc/console.py
examples/lighting-app/python/lighting.py
examples/platform/mbed/ota/generate_ota_list_image.py
examples/platform/nxp/k32w/k32w0/scripts/detokenizer.py
scripts/build/build/target.py
scripts/build/build/targets.py
scripts/build/builders/android.py
scripts/build/builders/bouffalolab.py
scripts/build/builders/cc13x2x7_26x2x7.py
scripts/build/builders/efr32.py
scripts/build/builders/esp32.py
scripts/build/builders/genio.py
scripts/build/builders/gn.py
scripts/build/builders/imx.py
scripts/build/builders/infineon.py
scripts/build/builders/nrf.py
scripts/build/test.py
scripts/codegen.py
scripts/codepregen.py
scripts/error_table.py
scripts/examples/gn_to_cmakelists.py
scripts/examples/tests/test.py
scripts/flashing/bouffalolab_firmware_utils.py
scripts/flashing/cyw30739_firmware_utils.py
scripts/flashing/nrfconnect_firmware_utils.py
scripts/gen_chip_version.py
scripts/gen_test_driver.py
scripts/helpers/bloat_check.py
scripts/pregenerate/using_codegen.py
scripts/pregenerate/using_zap.py
scripts/py_matter_yamltests/matter_yamltests/constraints.py
scripts/py_matter_yamltests/matter_yamltests/definitions.py
scripts/py_matter_yamltests/matter_yamltests/fixes.py
scripts/py_matter_yamltests/matter_yamltests/parser.py
scripts/py_matter_yamltests/matter_yamltests/pics_checker.py
scripts/py_matter_yamltests/matter_yamltests/pseudo_clusters/pseudo_clusters.py
scripts/py_matter_yamltests/matter_yamltests/yaml_loader.py
scripts/py_matter_yamltests/test_pics_checker.py
scripts/py_matter_yamltests/test_spec_definitions.py
scripts/py_matter_yamltests/test_yaml_loader.py
scripts/py_matter_yamltests/test_yaml_parser.py
scripts/run-clang-tidy-on-compile-commands.py
scripts/setup/nrfconnect/update_ncs.py
scripts/tests/chiptest/__init__.py
scripts/tests/chiptest/runner.py
scripts/tests/chiptest/test_definition.py
scripts/tests/chiptest/yamltest_with_chip_repl_tester.py
scripts/tests/java/base.py
scripts/tests/java/commissioning_test.py
scripts/tests/java/discover_test.py
scripts/tests/run_java_test.py
scripts/tests/run_python_test.py
scripts/tests/run_test_suite.py
scripts/tools/check_zcl_file_sync.py
scripts/tools/convert_ini.py
scripts/tools/generate_esp32_chip_factory_bin.py
scripts/tools/memory/memdf/__init__.py
scripts/tools/memory/report_summary.py
scripts/tools/nrfconnect/generate_nrfconnect_chip_factory_data.py
scripts/tools/nrfconnect/nrfconnect_generate_partition.py
scripts/tools/nrfconnect/tests/test_generate_factory_data.py
scripts/tools/nxp/factory_data_generator/custom.py
scripts/tools/nxp/factory_data_generator/default.py
scripts/tools/nxp/factory_data_generator/generate.py
scripts/tools/silabs/FactoryDataProvider.py
scripts/tools/telink/mfg_tool.py
scripts/tools/zap/generate.py
scripts/tools/zap/prune_outputs.py
scripts/tools/zap/test_generate.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/tests/suites/certification/information.py
src/app/zap_cluster_list.py
src/controller/python/build-chip-wheel.py
src/controller/python/chip-device-ctrl.py
src/controller/python/chip/CertificateAuthority.py
src/controller/python/chip/ChipBleUtility.py
src/controller/python/chip/ChipBluezMgr.py
src/controller/python/chip/ChipCommissionableNodeCtrl.py
src/controller/python/chip/ChipCoreBluetoothMgr.py
src/controller/python/chip/ChipDeviceCtrl.py
src/controller/python/chip/ChipReplStartup.py
src/controller/python/chip/ChipStack.py
src/controller/python/chip/ChipUtility.py
src/controller/python/chip/FabricAdmin.py
src/controller/python/chip/ble/scan_devices.py
src/controller/python/chip/clusters/Attribute.py
src/controller/python/chip/clusters/CHIPClusters.py
src/controller/python/chip/clusters/ClusterObjects.py
src/controller/python/chip/clusters/Command.py
src/controller/python/chip/clusters/Objects.py
src/controller/python/chip/clusters/__init__.py
src/controller/python/chip/discovery/__init__.py
src/controller/python/chip/interaction_model/__init__.py
src/controller/python/chip/interaction_model/delegate.py
src/controller/python/chip/internal/commissioner.py
src/controller/python/chip/setup_payload/setup_payload.py
src/controller/python/chip/storage/__init__.py
src/controller/python/chip/tlv/__init__.py
src/controller/python/chip/utils/CommissioningBuildingBlocks.py
src/controller/python/chip/yaml/__init__.py
src/controller/python/chip/yaml/format_converter.py
src/controller/python/chip/yaml/runner.py
src/controller/python/test/test_scripts/base.py
src/controller/python/test/test_scripts/cluster_objects.py
src/controller/python/test/test_scripts/mobile-device-test.py
src/controller/python/test/test_scripts/network_commissioning.py
src/controller/python/test/unit_tests/test_cluster_objects.py
src/controller/python/test/unit_tests/test_tlv.py
src/lib/asn1/gen_asn1oid.py
src/pybindings/pycontroller/build-chip-wheel.py
src/pybindings/pycontroller/pychip/__init__.py
src/python_testing/TC_ACE_1_3.py
src/python_testing/TC_ACE_1_4.py
src/python_testing/TC_CGEN_2_4.py
src/python_testing/TC_DA_1_7.py
src/python_testing/TC_RR_1_1.py
src/python_testing/TC_SC_3_6.py
src/python_testing/TC_TestEventTrigger.py
src/python_testing/hello_test.py
src/python_testing/matter_testing_support.py
src/setup_payload/python/generate_setup_payload.py
src/setup_payload/tests/run_python_setup_payload_gen_test.py
7 changes: 7 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,10 @@ jobs:
if: always()
run: |
git grep -n 'emberAfWriteAttribute' -- './*' ':(exclude).github/workflows/lint.yml' ':(exclude)src/app/util/af.h' ':(exclude)zzz_generated/app-common/app-common/zap-generated/attributes/Accessors.cpp' ':(exclude)src/app/zap-templates/templates/app/attributes/Accessors-src.zapt' ':(exclude)src/app/util/attribute-table.cpp' ':(exclude)examples/common/pigweed/rpc_services/Attributes.h' ':(exclude)src/app/util/attribute-table.h' ':(exclude)src/app/util/ember-compatibility-functions.cpp' && exit 1 || exit 0
# Run python Linter (flake8) and verify python files
# ignore some style errors, restyler should do that
- name: Check for errors using flake8 Python linter
if: always()
run: |
flake8 --extend-ignore=E501,W391
23 changes: 16 additions & 7 deletions scripts/py_matter_idl/examples/matter_idl_plugin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@
# limitations under the License.

import os
from typing import List

import jinja2
from matter_idl.generators import CodeGenerator, GeneratorStorage
from matter_idl.matter_idl_types import Attribute, Cluster, ClusterSide, Command, Field, Idl
from matter_idl.matter_idl_types import Cluster, ClusterSide, Command, Field, Idl


def toUpperSnakeCase(s):
Expand Down Expand Up @@ -57,9 +56,18 @@ def toEnumEntryName(enumEntry, enumName):

def toProtobufType(zapType: str) -> str:
""" Convert zap type to protobuf type """
u32Types = ["uint32", "enum8", "enum16", "enum32", "bitmap8", "bitmap16", "bitmap32", "cluster_id", "attrib_id", "event_id", "command_id",
"endpoint_no", "group_id", "devtype_id", "fabric_idx", "vendor_id", "status_code", "faulttype", "levelcontroloptions", "percent100ths", "percent"]
u64Types = ["uint64", "enum64", "bitmap64", "node_id", "fabric_id", "int40u", "int48u", "int56u", "int64u"]
u32Types = [
"uint32", "enum8", "enum16", "enum32", "bitmap8",
"bitmap16", "bitmap32", "cluster_id", "attrib_id",
"event_id", "command_id", "endpoint_no", "group_id",
"devtype_id", "fabric_idx", "vendor_id", "status_code",
"faulttype", "levelcontroloptions", "percent100ths",
"percent"
]
u64Types = [
"uint64", "enum64", "bitmap64", "node_id", "fabric_id",
"int40u", "int48u", "int56u", "int64u"
]
i32Types = ["int32", "int8s", "int16s", "int24s", "int32s"]
i64Types = ["int64", "int40s", "int48s", "int56s", "int64s"]
floatTypes = ["float", "double"]
Expand Down Expand Up @@ -149,7 +157,7 @@ def commandResponseArgs(command: Command, cluster: Cluster):

def toEncodedTag(tag, typeNum: EncodingDataType):
""" Return the final encoded tag from the given field number and field encoded data type.
The Matter field type information is encoded into the upper range of the protobuf field
The Matter field type information is encoded into the upper range of the protobuf field
tag for stateless translation to Matter TLV. """
tag = (int(typeNum) << 19) | int(tag)
return tag
Expand Down Expand Up @@ -228,7 +236,8 @@ def internal_render_all(self):
if cluster.side != ClusterSide.CLIENT:
continue

filename = "proto/%s_cluster.proto" % toLowerSnakeCase(cluster.name)
filename = "proto/%s_cluster.proto" % toLowerSnakeCase(
cluster.name)

# Header containing a macro to initialize all cluster plugins
self.internal_render_one_output(
Expand Down
10 changes: 5 additions & 5 deletions scripts/py_matter_idl/matter_idl/generators/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import logging
import jinja2

import os
from typing import Dict

import jinja2
from matter_idl.matter_idl_types import Idl

from .filters import RegisterCommonFilters
Expand Down Expand Up @@ -102,7 +102,7 @@ class CodeGenerator:
'render' will perform a rendering of all files.
As special optimizations, CodeGenerators generally will try to read
existing data and will not re-write content if not changed (so that
existing data and will not re-write content if not changed (so that
write time of files do not change and rebuilds are not triggered).
"""

Expand Down Expand Up @@ -146,7 +146,7 @@ def internal_render_one_output(self, template_path: str, output_file_name: str,
if dry-run was requested during `render`.
NOTE: to make this method suitable for rebuilds, this file will NOT alter
the timestamp of the output file if the file content would not
the timestamp of the output file if the file content would not
change (i.e. no write will be invoked in that case.)
Args:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import enum
import logging
import re
from typing import List, Set, Union

from matter_idl import matter_idl_types
from matter_idl.generators import CodeGenerator, GeneratorStorage
from matter_idl.generators.types import (BasicInteger, BasicString, FundamentalType, IdlBitmapType, IdlEnumType, IdlType,
ParseDataType, TypeLookupContext)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import enum
import logging
from typing import List, Set, Union
from typing import List

from matter_idl import matter_idl_types
from matter_idl.generators import CodeGenerator, GeneratorStorage
from matter_idl.generators.types import (BasicInteger, BasicString, FundamentalType, IdlBitmapType, IdlEnumType, IdlType,
ParseDataType, TypeLookupContext)
from matter_idl.matter_idl_types import Attribute, Cluster, ClusterSide, Command, DataType, Field, FieldQuality, Idl
from stringcase import capitalcase
from matter_idl.matter_idl_types import Cluster, ClusterSide, Idl


def serverClustersOnly(clusters: List[Cluster]) -> List[Cluster]:
Expand Down
9 changes: 4 additions & 5 deletions scripts/py_matter_idl/matter_idl/generators/java/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import logging
from typing import List, Set, Union

from matter_idl import matter_idl_types
from matter_idl.generators import CodeGenerator, GeneratorStorage
from matter_idl.generators.types import (BasicInteger, BasicString, FundamentalType, IdlBitmapType, IdlEnumType, IdlType,
ParseDataType, TypeLookupContext)
Expand Down Expand Up @@ -76,7 +75,7 @@ def CallbackName(attr: Attribute, cluster: Cluster, context: TypeLookupContext)
Figure out what callback name to use when a variable requires a read callback.
These are split into native types, like Boolean/Float/Double/CharString, where
one callback type can support anything.
one callback type can support anything.
For specific types (e.g. A struct) codegen will generate its own callback name
specific to that type.
Expand Down Expand Up @@ -240,7 +239,7 @@ def boxed_java_type(self):
elif t == FundamentalType.DOUBLE:
return "Double"
else:
raise Error("Unknown fundamental type")
raise Exception("Unknown fundamental type")
elif type(t) == BasicInteger:
if t.byte_count >= 4:
return "Long"
Expand Down Expand Up @@ -277,7 +276,7 @@ def boxed_java_signature(self):
elif t == FundamentalType.DOUBLE:
return "Ljava/lang/Double;"
else:
raise Error("Unknown fundamental type")
raise Exception("Unknown fundamental type")
elif type(t) == BasicInteger:
if t.byte_count >= 4:
return "Ljava/lang/Long;"
Expand All @@ -301,7 +300,7 @@ def EncodableValueFrom(field: Field, context: TypeLookupContext) -> EncodableVal
Filter to convert a standard field to an EncodableValue.
This converts the AST information (field name/info + lookup context) into
a java-generator specific wrapper that can be manipulated and
a java-generator specific wrapper that can be manipulated and
queried for properties like java native name or JNI string signature.
"""
attrs = set()
Expand Down
17 changes: 9 additions & 8 deletions scripts/py_matter_idl/matter_idl/generators/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
# limitations under the License.

import enum
import logging
from dataclasses import dataclass
from typing import List, Optional, Union
from typing import Optional, Union

from matter_idl import matter_idl_types # to explicitly say 'Enum'
from matter_idl.matter_idl_types import DataType
Expand Down Expand Up @@ -80,7 +81,7 @@ def idl_name(self):
elif self == FundamentalType.DOUBLE:
return "double"
else:
raise Error("Type not handled: %r" % self)
raise Exception("Type not handled: %r" % self)

@property
def byte_count(self):
Expand All @@ -91,7 +92,7 @@ def byte_count(self):
elif self == FundamentalType.DOUBLE:
return 8
else:
raise Error("Type not handled: %r" % self)
raise Exception("Type not handled: %r" % self)

@property
def bits(self):
Expand All @@ -109,11 +110,11 @@ class IdlEnumType:

@property
def byte_count(self):
return base_type.byte_count()
return self.base_type.byte_count()

@property
def bits(self):
return base_type.bits()
return self.base_type.bits()


@dataclass
Expand All @@ -128,11 +129,11 @@ class IdlBitmapType:

@property
def byte_count(self):
return base_type.byte_count()
return self.base_type.byte_count()

@property
def bits(self):
return base_type.bits()
return self.base_type.bits()


class IdlItemType(enum.Enum):
Expand Down Expand Up @@ -399,7 +400,7 @@ def ParseDataType(data_type: DataType, lookup: TypeLookupContext) -> Union[Basic
if lookup.find_struct(data_type.name):
result.item_type = IdlItemType.STRUCT
else:
logging.warn(
logging.warning(
"Data type %s is NOT known, but treating it as a generic IDL type." % data_type)

return result
2 changes: 2 additions & 0 deletions scripts/py_matter_idl/matter_idl/lint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@
# limitations under the License.

from .lint_rules_parser import CreateParser

__all__ = [CreateParser]
Loading

0 comments on commit 1078806

Please sign in to comment.