Skip to content

Commit 665dd59

Browse files
marcelveldtMartinHjelmare
andauthoredFeb 14, 2024
Adjust the linter config (#543)
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
1 parent 77ebbfb commit 665dd59

File tree

19 files changed

+333
-163
lines changed

19 files changed

+333
-163
lines changed
 

‎.github/workflows/test.yml

+7-13
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,10 @@ jobs:
2626
sudo apt-get update
2727
sudo apt-get install -y libgirepository1.0-dev
2828
python -m pip install --upgrade pip
29-
pip install -e .[server] -r requirements-test.txt
30-
- name: Flake8
31-
run: flake8 scripts/ matter_server/
32-
- name: Black
33-
run: black --check scripts/ matter_server/
34-
- name: isort
35-
run: isort --check scripts/ matter_server/
36-
- name: pylint
37-
run: pylint matter_server/
38-
- name: mypy
39-
run: mypy matter_server/
29+
pip install -e .[server]
30+
pip install -e .[test]
31+
- name: Lint/test with pre-commit
32+
run: pre-commit run --all-files
4033

4134
test:
4235
runs-on: ubuntu-latest
@@ -60,6 +53,7 @@ jobs:
6053
sudo apt-get update
6154
sudo apt-get install -y libgirepository1.0-dev
6255
python -m pip install --upgrade pip
63-
pip install -e .[server] -r requirements-test.txt
56+
pip install -e .[server]
57+
pip install -e .[test]
6458
- name: Pytest
65-
run: pytest --durations 10 --cov-report term-missing --cov=matter_server --cov-report=xml tests/server/
59+
run: pytest --durations 10 --cov-report term-missing --cov=matter_server --cov-report=xml tests/

‎.pre-commit-config.yaml

+87-37
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,101 @@
11
# See https://pre-commit.com for more information
22
# See https://pre-commit.com/hooks.html for more hooks
33
repos:
4-
- repo: https://github.com/psf/black
5-
rev: 23.1.0
6-
hooks:
7-
- id: black
8-
args:
9-
- --quiet
10-
files: ^(matter_server|scripts)/.+\.py$
11-
- repo: https://github.com/codespell-project/codespell
12-
rev: v2.2.4
4+
- repo: local
135
hooks:
6+
- id: ruff-check
7+
name: 🐶 Ruff Linter
8+
language: system
9+
types: [python]
10+
entry: scripts/run-in-env.sh ruff check --fix
11+
require_serial: true
12+
stages: [commit, push, manual]
13+
- id: ruff-format
14+
name: 🐶 Ruff Formatter
15+
language: system
16+
types: [python]
17+
entry: scripts/run-in-env.sh ruff format
18+
require_serial: true
19+
stages: [commit, push, manual]
20+
- id: check-ast
21+
name: 🐍 Check Python AST
22+
language: system
23+
types: [python]
24+
entry: scripts/run-in-env.sh check-ast
25+
- id: check-case-conflict
26+
name: 🔠 Check for case conflicts
27+
language: system
28+
entry: scripts/run-in-env.sh check-case-conflict
29+
- id: check-docstring-first
30+
name: ℹ️ Check docstring is first
31+
language: system
32+
types: [python]
33+
entry: scripts/run-in-env.sh check-docstring-first
34+
- id: check-executables-have-shebangs
35+
name: 🧐 Check that executables have shebangs
36+
language: system
37+
types: [text, executable]
38+
entry: scripts/run-in-env.sh check-executables-have-shebangs
39+
stages: [commit, push, manual]
40+
- id: check-json
41+
name: { Check JSON files
42+
language: system
43+
types: [json]
44+
entry: scripts/run-in-env.sh check-json
45+
- id: check-merge-conflict
46+
name: 💥 Check for merge conflicts
47+
language: system
48+
types: [text]
49+
entry: scripts/run-in-env.sh check-merge-conflict
50+
- id: check-symlinks
51+
name: 🔗 Check for broken symlinks
52+
language: system
53+
types: [symlink]
54+
entry: scripts/run-in-env.sh check-symlinks
55+
- id: check-toml
56+
name: ✅ Check TOML files
57+
language: system
58+
types: [toml]
59+
entry: scripts/run-in-env.sh check-toml
1460
- id: codespell
15-
args: []
16-
exclude_types: [csv, json]
17-
exclude: ^tests/fixtures/
18-
additional_dependencies:
19-
- tomli
20-
- repo: https://github.com/PyCQA/flake8
21-
rev: 6.0.0
22-
hooks:
23-
- id: flake8
24-
files: ^(matter_server|scripts)/.+\.py$
25-
- repo: https://github.com/PyCQA/isort
26-
rev: 5.12.0
27-
hooks:
28-
- id: isort
29-
files: ^(matter_server|scripts)/.+\.py$
30-
- repo: https://github.com/pre-commit/pre-commit-hooks
31-
rev: v4.4.0
32-
hooks:
61+
name: ✅ Check code for common misspellings
62+
language: system
63+
types: [text]
64+
entry: scripts/run-in-env.sh codespell
65+
- id: detect-private-key
66+
name: 🕵️ Detect Private Keys
67+
language: system
68+
types: [text]
69+
entry: scripts/run-in-env.sh detect-private-key
70+
- id: end-of-file-fixer
71+
name: ⮐ Fix End of Files
72+
language: system
73+
types: [text]
74+
entry: scripts/run-in-env.sh end-of-file-fixer
75+
stages: [commit, push, manual]
3376
- id: no-commit-to-branch
77+
name: 🛑 Don't commit to main branch
78+
language: system
79+
entry: scripts/run-in-env.sh no-commit-to-branch
80+
pass_filenames: false
81+
always_run: true
3482
args:
3583
- --branch=main
84+
- id: pylint
85+
name: 🌟 Starring code with pylint
86+
language: system
87+
types: [python]
88+
entry: scripts/run-in-env.sh pylint
3689
- id: trailing-whitespace
37-
- repo: local
38-
hooks:
90+
name: ✄ Trim Trailing Whitespace
91+
language: system
92+
types: [text]
93+
entry: scripts/run-in-env.sh trailing-whitespace-fixer
94+
stages: [commit, push, manual]
3995
- id: mypy
4096
name: mypy
4197
entry: scripts/run-in-env.sh mypy
42-
types: [python]
4398
language: script
44-
files: ^(matter_server)/.+\.py$
45-
46-
- id: pylint
47-
name: pylint
48-
entry: scripts/run-in-env.sh pylint -j 0
4999
types: [python]
50-
language: script
51-
files: ^(matter_server)/.+\.py$
100+
require_serial: true
101+
files: ^(matter_server|pylint)/.+\.py$

‎dashboard/public/index.html

-1
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,3 @@
3838
</head>
3939
<body></body>
4040
</html>
41-

‎dashboard/script/build

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#!/bin/bash -i
2+
13
# Stop on errors
24
set -e
35

@@ -7,4 +9,3 @@ rm -rf dist
79
NODE_ENV=production npm exec -- tsc
810
NODE_ENV=production npm exec -- rollup -c
911
cp -r public/* dist/web
10-

‎dashboard/script/develop

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#!/bin/bash -i
2+
13
# Stop on errors
24
set -e
35

‎matter_server/client/models/clusters.py

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from chip.tlv import float32
1414

1515
# pylint: disable=invalid-name,arguments-renamed,no-self-argument
16+
# mypy: ignore_errors=true
1617

1718

1819
@dataclass

‎matter_server/common/helpers/json.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
from base64 import b64encode
44
from typing import Any
55

6+
import orjson
67
from chip.clusters.Types import Nullable
78
from chip.tlv import float32, uint
8-
import orjson
99

1010
JSON_ENCODE_EXCEPTIONS = (TypeError, ValueError)
1111
JSON_DECODE_EXCEPTIONS = (orjson.JSONDecodeError,)
@@ -16,6 +16,7 @@ def json_encoder_default(obj: Any) -> Any:
1616
1717
Hand other objects to the original method.
1818
"""
19+
# pylint: disable=too-many-return-statements
1920
if getattr(obj, "do_not_serialize", None):
2021
return None
2122
if isinstance(obj, (set, tuple)):

‎matter_server/common/models.py

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Models that are (serializeable) shared between server and client."""
2+
23
from __future__ import annotations
34

45
from dataclasses import dataclass, field
@@ -178,6 +179,8 @@ class ServerInfoMessage:
178179
class CommissionableNodeData:
179180
"""Object that is returned on the 'discover_commissionable_nodes' command."""
180181

182+
# pylint: disable=too-many-instance-attributes
183+
181184
instance_name: str | None = None
182185
host_name: str | None = None
183186
port: int | None = None

‎matter_server/server/device_controller.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
55
from __future__ import annotations
66

77
import asyncio
8+
import logging
89
from collections import deque
910
from datetime import datetime
1011
from functools import partial
11-
import logging
1212
from typing import TYPE_CHECKING, Any, Awaitable, Callable, Iterable, TypeVar, cast
1313

1414
from chip.ChipDeviceCtrl import DeviceProxyWrapper
15-
from chip.clusters import Attribute, Objects as Clusters
15+
from chip.clusters import Attribute
16+
from chip.clusters import Objects as Clusters
1617
from chip.clusters.Attribute import ValueDecodeFailure
1718
from chip.clusters.ClusterObjects import ALL_ATTRIBUTES, ALL_CLUSTERS, Cluster
1819
from chip.exceptions import ChipStackError
@@ -93,7 +94,7 @@
9394
),
9495
)
9596

96-
# pylint: disable=too-many-lines,too-many-locals,too-many-statements,too-many-branches
97+
# pylint: disable=too-many-lines,too-many-locals,too-many-statements,too-many-branches,too-many-instance-attributes
9798

9899

99100
class MatterDeviceController:
@@ -244,7 +245,7 @@ async def commission_with_code(
244245
attempts = 0
245246
# we retry commissioning a few times as we've seen devices in the wild
246247
# that are a bit unstable.
247-
# by retrying, we increase the chances of a successful commisssion
248+
# by retrying, we increase the chances of a successful commission
248249
while attempts <= MAX_COMMISSION_RETRIES:
249250
attempts += 1
250251
LOGGER.info(
@@ -322,7 +323,7 @@ async def commission_on_network(
322323
attempts = 0
323324
# we retry commissioning a few times as we've seen devices in the wild
324325
# that are a bit unstable.
325-
# by retrying, we increase the chances of a successful commisssion
326+
# by retrying, we increase the chances of a successful commission
326327
while attempts <= MAX_COMMISSION_RETRIES:
327328
attempts += 1
328329
if ip_addr is None:

‎matter_server/server/server.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
"""Implementation of a Websocket-based server to proxy Matter support (using CHIP SDK)."""
2+
23
from __future__ import annotations
34

45
import asyncio
56
import ipaddress
67
import logging
7-
from typing import Any, Callable, Set, cast
88
import weakref
9+
from typing import Any, Callable, Set, cast
910

1011
from aiohttp import web
1112

@@ -55,6 +56,8 @@ async def _handle_shutdown(app: web.Application) -> None:
5556
class MatterServer:
5657
"""Serve Matter stack over WebSockets."""
5758

59+
# pylint: disable=too-many-instance-attributes
60+
5861
_runner: web.AppRunner | None = None
5962
_http: MultiHostTCPSite | None = None
6063

0 commit comments

Comments
 (0)