Skip to content

Commit a64a1df

Browse files
arkqrestyled-commitsandy31415
authored
Install Python matter IDL module in matter namespace (#37298)
* Install Python matter IDL module in matter namespace * Keep Python formatters/checkers configuration in one place * Map "matter" Python imports as first-party * Fix spelling warning * Restyled by prettier-markdown * Fix import in IDL linter script * More path updates * Fix importing matter.idl directly from scripts dir * Revert ZAP modification * Fix regression --------- Co-authored-by: Restyled.io <commits@restyled.io> Co-authored-by: Andrei Litvin <andy314@gmail.com>
1 parent 742fc61 commit a64a1df

File tree

126 files changed

+304
-304
lines changed

Some content is hidden

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

126 files changed

+304
-304
lines changed

.github/.wordlist.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1171,6 +1171,7 @@ PyFunction
11711171
pylint
11721172
PyObject
11731173
pypi
1174+
pyproject
11741175
PyRun
11751176
pytest
11761177
PYTHONPATH

.github/workflows/lint.yml

+7-7
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,13 @@ jobs:
151151
if [ "$idl_file" = './examples/lighting-app-data-mode-no-unique-id/lighting-common/lighting-app.matter' ]; then continue; fi
152152
153153
# Test files are intentionally small and not spec-compilant, just parse-compliant
154-
if [ "$idl_file" = "./scripts/py_matter_idl/matter_idl/tests/inputs/cluster_struct_attribute.matter" ]; then continue; fi
155-
if [ "$idl_file" = "./scripts/py_matter_idl/matter_idl/tests/inputs/global_struct_attribute.matter" ]; then continue; fi
156-
if [ "$idl_file" = "./scripts/py_matter_idl/matter_idl/tests/inputs/optional_argument.matter" ]; then continue; fi
157-
if [ "$idl_file" = "./scripts/py_matter_idl/matter_idl/tests/inputs/several_clusters.matter" ]; then continue; fi
158-
if [ "$idl_file" = "./scripts/py_matter_idl/matter_idl/tests/inputs/simple_attribute.matter" ]; then continue; fi
159-
if [ "$idl_file" = "./scripts/py_matter_idl/matter_idl/tests/inputs/large_lighting_app.matter" ]; then continue; fi
160-
if [ "$idl_file" = "./scripts/py_matter_idl/matter_idl/tests/inputs/large_all_clusters_app.matter" ]; then continue; fi
154+
if [ "$idl_file" = "./scripts/py_matter_idl/matter/idl/tests/inputs/cluster_struct_attribute.matter" ]; then continue; fi
155+
if [ "$idl_file" = "./scripts/py_matter_idl/matter/idl/tests/inputs/global_struct_attribute.matter" ]; then continue; fi
156+
if [ "$idl_file" = "./scripts/py_matter_idl/matter/idl/tests/inputs/optional_argument.matter" ]; then continue; fi
157+
if [ "$idl_file" = "./scripts/py_matter_idl/matter/idl/tests/inputs/several_clusters.matter" ]; then continue; fi
158+
if [ "$idl_file" = "./scripts/py_matter_idl/matter/idl/tests/inputs/simple_attribute.matter" ]; then continue; fi
159+
if [ "$idl_file" = "./scripts/py_matter_idl/matter/idl/tests/inputs/large_lighting_app.matter" ]; then continue; fi
160+
if [ "$idl_file" = "./scripts/py_matter_idl/matter/idl/tests/inputs/large_all_clusters_app.matter" ]; then continue; fi
161161
162162
./scripts/run_in_build_env.sh "./scripts/idl_lint.py --log-level warn $idl_file" >/dev/null || exit 1
163163
done

.github/workflows/tests.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ jobs:
8888
#
8989
run: |
9090
./scripts/run_in_build_env.sh \
91-
"./scripts/py_matter_idl/matter_idl/zapxml_parser.py \
91+
"./scripts/py_matter_idl/matter/idl/zapxml_parser.py \
9292
--no-print \
9393
--log-level info \
9494
src/app/zap-templates/zcl/data-model/chip/global-attributes.xml \

.isort.cfg

-2
This file was deleted.

.restyled.yaml

+1-3
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ exclude:
6868
- "third_party/android_deps/gradlew" # gradle wrapper generated file
6969
- "src/controller/python/chip/clusters/Objects.py" # generated file, no point to restyle
7070
- "src/controller/python/chip/clusters/CHIPClusters.py" # generated file, no point to restyle
71-
- "scripts/py_matter_idl/matter_idl/tests/outputs/**/*" # Matches generated output 1:1
71+
- "scripts/py_matter_idl/matter/idl/tests/outputs/**/*" # Matches generated output 1:1
7272
- "scripts/tools/zap/tests/outputs/**/*" # Matches generated output 1:1
7373
- "examples/chef/sample_app_util/test_files/*.yaml"
7474
- "examples/chef/zzz_generated/**/*"
@@ -228,8 +228,6 @@ restylers:
228228
command:
229229
- autopep8
230230
- "--in-place"
231-
- "--max-line-length"
232-
- "132"
233231
arguments: []
234232
include:
235233
- "**/*.py"

docs/guides/matter_idl_tooling.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Since it is designed to be easy for both machine and humans to read, it is the
77
basis of some tools to make validating zap-based cluster definitions easier.
88

99
More details on the format in
10-
[matter_idl/README.md](../../scripts/py_matter_idl/matter_idl/README.md).
10+
[matter/idl/README.md](../../scripts/py_matter_idl/matter/idl/README.md).
1111

1212
## Parsing CSA XML Data definitions
1313

@@ -20,12 +20,12 @@ information available in [data_model/README.md](../../data_model/README.md).
2020
NOTE: scraper is a work in progress, XML data may be incomplete or have errors
2121
still.
2222

23-
The script `./scripts/py_matter_idl/matter_idl/data_model_xml_parser.py` has the
23+
The script `./scripts/py_matter_idl/matter/idl/data_model_xml_parser.py` has the
2424
ability to parse one or more CSA data model XML files and output their content
2525
in `.matter` format. For example:
2626

2727
```sh
28-
./scripts/py_matter_idl/matter_idl/data_model_xml_parser.py data_model/clusters/BooleanState.xml
28+
./scripts/py_matter_idl/matter/idl/data_model_xml_parser.py data_model/clusters/BooleanState.xml
2929
```
3030

3131
The tool supports several options that are useful for development:
@@ -54,7 +54,7 @@ specification:
5454
As such one can run compares such as:
5555

5656
```sh
57-
./scripts/py_matter_idl/matter_idl/data_model_xml_parser.py \
57+
./scripts/py_matter_idl/matter/idl/data_model_xml_parser.py \
5858
-o out/spec.matter \
5959
--compare-output out/sdk.matter \
6060
--compare src/controller/data_model/controller-clusters.matter \

docs/style/CODING_STYLE_GUIDE.md

+14-16
Original file line numberDiff line numberDiff line change
@@ -60,22 +60,20 @@ be removed.
6060

6161
We use the following auto-formatters on code:
6262

63-
| Language | Formatter | Style File |
64-
| ----------- | ------------------ | ------------------------------------------------------------------------------------------ |
65-
| C++ | clang-format | [.clang-format](https://github.com/project-chip/connectedhomeip/blob/master/.clang-format) |
66-
| Objective-C | clang-format | [.clang-format](https://github.com/project-chip/connectedhomeip/blob/master/.clang-format) |
67-
| java | google-java-format | N/A |
68-
| Python | pep8, isort, ruff | [.restyled.yaml][restyle_link] (command line), [isort][isort_link], [ruff][ruff_link] |
69-
| YAML | prettier | None |
70-
| JSON | prettier | None |
71-
| markdown | prettier | None |
72-
73-
[restyle_link]:
74-
https://github.com/project-chip/connectedhomeip/blob/master/.restyled.yaml
75-
[isort_link]:
76-
https://github.com/project-chip/connectedhomeip/blob/master/.isort.cfg
77-
[ruff_link]:
78-
https://github.com/project-chip/connectedhomeip/blob/master/ruff.toml
63+
| Language | Formatter | Style File |
64+
| ----------- | ------------------ | ---------------------------------- |
65+
| C++ | clang-format | [.clang-format][clang_format_link] |
66+
| Objective-C | clang-format | [.clang-format][clang_format_link] |
67+
| java | google-java-format | N/A |
68+
| Python | pep8, isort, ruff | [pyproject.toml][pyproject_link] |
69+
| YAML | prettier | None |
70+
| JSON | prettier | None |
71+
| markdown | prettier | None |
72+
73+
[clang_format_link]:
74+
https://github.com/project-chip/connectedhomeip/blob/master/.clang-format
75+
[pyproject_link]:
76+
https://github.com/project-chip/connectedhomeip/blob/master/pyproject.toml
7977

8078
All pull requests run formatting checks using these tools before merge is
8179
allowed. Generated code is not run through restyle.

docs/zap_and_codegen/code_generation.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ specific codegen.
9191
`*.matter` files are both human and machine readable. Code that can process
9292
these files is available at `scripts/py_matter_idl` and `scripts/codegen.py`.
9393
You can read the
94-
[scripts/py_matter_idl/matter_idl/README.md](../scripts/py_matter_idl/matter_idl/README.md)
94+
[scripts/py_matter_idl/matter/idl/README.md](../scripts/py_matter_idl/matter/idl/README.md)
9595
for details of how things work.
9696

9797
`scripts/codegen.py` can generate various outputs based on an input `*.matter`
@@ -222,7 +222,7 @@ Code pre-generation can be used:
222222
generation at build time or to save the code generation time at the expense
223223
of running code generation for every possible zap/generation type
224224
- To check changes in generated code across versions, beyond the comparisons
225-
of golden image tests in `scripts/py_matter_idl/matter_idl/tests`
225+
of golden image tests in `scripts/py_matter_idl/matter/idl/tests`
226226

227227
The script to trigger code pre-generation is `scripts/codepregen.py` and
228228
requires the pre-generation output directory as an argument

ruff.toml pyproject.toml

+12-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
[tool.autopep8]
2+
max_line_length = 132
3+
4+
[tool.isort]
5+
line_length = 132
6+
known_first_party = "matter"
7+
8+
[tool.ruff]
9+
line-length = 132
10+
target-version = "py310"
111
exclude = [
212
".environment",
313
".git",
@@ -10,12 +20,9 @@ exclude = [
1020
# TODO(#37698)
1121
"docs/development_controllers/chip-repl/*.ipynb",
1222
]
13-
target-version = "py310"
14-
15-
line-length = 132
1623

17-
[lint]
24+
[tool.ruff.lint]
1825
select = ["E4", "E7", "E9", "F"]
1926
ignore = [
20-
"E721" # We use it for good reasons
27+
"E721", # We use it for good reasons
2128
]

scripts/backwards_compatibility_checker.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@
2626
_has_coloredlogs = False
2727

2828
try:
29-
from matter_idl.matter_idl_parser import CreateParser
29+
from matter.idl.matter_idl_parser import CreateParser
3030
except ImportError:
3131
import os
3232
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), 'py_matter_idl')))
33-
from matter_idl.matter_idl_parser import CreateParser
33+
from matter.idl.matter_idl_parser import CreateParser
3434

35-
from matter_idl.backwards_compatibility import is_backwards_compatible
35+
from matter.idl.backwards_compatibility import is_backwards_compatible
3636

3737
# Supported log levels, mapping string values required for argument
3838
# parsing into logging constants

scripts/codegen.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@
2525
_has_coloredlogs = False
2626

2727
try:
28-
from matter_idl.matter_idl_parser import CreateParser
28+
from matter.idl.matter_idl_parser import CreateParser
2929
except ImportError:
3030
import os
3131
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), 'py_matter_idl')))
32-
from matter_idl.matter_idl_parser import CreateParser
32+
from matter.idl.matter_idl_parser import CreateParser
3333

3434
# isort: off
35-
from matter_idl.generators import FileSystemGeneratorStorage, GeneratorStorage
36-
from matter_idl.generators.registry import CodeGenerator, GENERATORS
35+
from matter.idl.generators import FileSystemGeneratorStorage, GeneratorStorage
36+
from matter.idl.generators.registry import CodeGenerator, GENERATORS
3737

3838

3939
class ListGeneratedFilesStorage(GeneratorStorage):

scripts/idl_lint.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121
import coloredlogs
2222

2323
try:
24-
from matter_idl import matter_idl_parser
24+
from matter.idl import matter_idl_parser
2525
except ImportError:
2626
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), 'py_matter_idl')))
27-
from matter_idl import matter_idl_parser
27+
from matter.idl import matter_idl_parser
2828

2929
# isort: off
30-
import matter_idl.lint
30+
import matter.idl.lint
3131

3232

3333
# Supported log levels, mapping string values required for argument
@@ -64,7 +64,7 @@ def main(log_level, rules, idl_path):
6464

6565
lint_rules = []
6666
logging.info("Loading rules from %s" % rules)
67-
lint_rules.extend(matter_idl.lint.CreateParser(rules).parse())
67+
lint_rules.extend(matter.idl.lint.CreateParser(rules).parse())
6868

6969
logging.info("Parsing idl from %s" % idl_path)
7070
idl_tree = matter_idl_parser.CreateParser().parse(open(idl_path, "rt").read(), file_name=idl_path)

scripts/py_matter_idl/BUILD.gn

+23-23
Original file line numberDiff line numberDiff line change
@@ -29,37 +29,37 @@ pw_python_package("matter_idl") {
2929
inputs = matter_idl_generator_templates
3030
inputs += [
3131
# Dependency grammar
32-
"matter_idl/matter_grammar.lark",
32+
"matter/idl/matter_grammar.lark",
3333

34-
#marker file to indicate to mypy that matter_idl is type-annotated
35-
"matter_idl/py.typed",
34+
# Marker file to indicate to mypy that matter_idl is type-annotated
35+
"matter/idl/py.typed",
3636

3737
# Unit test data
38-
"matter_idl/tests/available_tests.yaml",
39-
"matter_idl/tests/inputs/cluster_struct_attribute.matter",
40-
"matter_idl/tests/inputs/global_struct_attribute.matter",
41-
"matter_idl/tests/inputs/optional_argument.matter",
42-
"matter_idl/tests/inputs/several_clusters.matter",
43-
"matter_idl/tests/inputs/simple_attribute.matter",
44-
"matter_idl/tests/outputs/several_clusters/java/ChipClusters.java",
45-
"matter_idl/tests/outputs/several_clusters/java/ChipEventStructs.java",
46-
"matter_idl/tests/outputs/several_clusters/java/ChipStructs.java",
47-
"matter_idl/tests/outputs/several_clusters/java/ClusterInfoMapping.java",
48-
"matter_idl/tests/outputs/several_clusters/java/ClusterIDMapping.java",
49-
"matter_idl/tests/outputs/several_clusters/java/ClusterWriteMapping.java",
38+
"matter/idl/tests/available_tests.yaml",
39+
"matter/idl/tests/inputs/cluster_struct_attribute.matter",
40+
"matter/idl/tests/inputs/global_struct_attribute.matter",
41+
"matter/idl/tests/inputs/optional_argument.matter",
42+
"matter/idl/tests/inputs/several_clusters.matter",
43+
"matter/idl/tests/inputs/simple_attribute.matter",
44+
"matter/idl/tests/outputs/several_clusters/java/ChipClusters.java",
45+
"matter/idl/tests/outputs/several_clusters/java/ChipEventStructs.java",
46+
"matter/idl/tests/outputs/several_clusters/java/ChipStructs.java",
47+
"matter/idl/tests/outputs/several_clusters/java/ClusterInfoMapping.java",
48+
"matter/idl/tests/outputs/several_clusters/java/ClusterIDMapping.java",
49+
"matter/idl/tests/outputs/several_clusters/java/ClusterWriteMapping.java",
5050
]
5151

5252
sources = matter_idl_generator_sources
5353

5454
tests = [
55-
"matter_idl/test_backwards_compatibility.py",
56-
"matter_idl/test_case_conversion.py",
57-
"matter_idl/test_data_model_xml.py",
58-
"matter_idl/test_matter_idl_parser.py",
59-
"matter_idl/test_generators.py",
60-
"matter_idl/test_idl_generator.py",
61-
"matter_idl/test_supported_types.py",
62-
"matter_idl/test_zapxml.py",
55+
"matter/idl/test_backwards_compatibility.py",
56+
"matter/idl/test_case_conversion.py",
57+
"matter/idl/test_data_model_xml.py",
58+
"matter/idl/test_matter_idl_parser.py",
59+
"matter/idl/test_generators.py",
60+
"matter/idl/test_idl_generator.py",
61+
"matter/idl/test_supported_types.py",
62+
"matter/idl/test_zapxml.py",
6363
]
6464

6565
# TODO: at a future time consider enabling all (* or missing) here to get

scripts/py_matter_idl/examples/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ scripts/py_matter_idl/examples/matter_idl_plugin:
1616
`--generator custom:<plugin_path>:<plugin_module_name>` argument and package
1717
name like `--option package:com.example.matter.proto`
1818

19-
```
19+
```shell
2020
# From top-of-tree in this example
2121
./scripts/codegen.py \
2222
--generator custom:./scripts/py_matter_idl/examples:matter_idl_plugin \

scripts/py_matter_idl/examples/matter_idl_plugin/__init__.py

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

1515
import os
1616

17-
from matter_idl.generators import CodeGenerator, GeneratorStorage
18-
from matter_idl.matter_idl_types import Cluster, Command, Field, Idl
17+
from matter.idl.generators import CodeGenerator, GeneratorStorage
18+
from matter.idl.matter_idl_types import Cluster, Command, Field, Idl
1919

2020

2121
def toUpperSnakeCase(s):

0 commit comments

Comments
 (0)