Skip to content

Commit

Permalink
Adjust the linter config (#543)
Browse files Browse the repository at this point in the history
Co-authored-by: Martin Hjelmare <[email protected]>
  • Loading branch information
marcelveldt and MartinHjelmare authored Feb 14, 2024
1 parent 77ebbfb commit 665dd59
Show file tree
Hide file tree
Showing 19 changed files with 333 additions and 163 deletions.
20 changes: 7 additions & 13 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,10 @@ jobs:
sudo apt-get update
sudo apt-get install -y libgirepository1.0-dev
python -m pip install --upgrade pip
pip install -e .[server] -r requirements-test.txt
- name: Flake8
run: flake8 scripts/ matter_server/
- name: Black
run: black --check scripts/ matter_server/
- name: isort
run: isort --check scripts/ matter_server/
- name: pylint
run: pylint matter_server/
- name: mypy
run: mypy matter_server/
pip install -e .[server]
pip install -e .[test]
- name: Lint/test with pre-commit
run: pre-commit run --all-files

test:
runs-on: ubuntu-latest
Expand All @@ -60,6 +53,7 @@ jobs:
sudo apt-get update
sudo apt-get install -y libgirepository1.0-dev
python -m pip install --upgrade pip
pip install -e .[server] -r requirements-test.txt
pip install -e .[server]
pip install -e .[test]
- name: Pytest
run: pytest --durations 10 --cov-report term-missing --cov=matter_server --cov-report=xml tests/server/
run: pytest --durations 10 --cov-report term-missing --cov=matter_server --cov-report=xml tests/
124 changes: 87 additions & 37 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,51 +1,101 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/psf/black
rev: 23.1.0
hooks:
- id: black
args:
- --quiet
files: ^(matter_server|scripts)/.+\.py$
- repo: https://github.com/codespell-project/codespell
rev: v2.2.4
- repo: local
hooks:
- id: ruff-check
name: 🐶 Ruff Linter
language: system
types: [python]
entry: scripts/run-in-env.sh ruff check --fix
require_serial: true
stages: [commit, push, manual]
- id: ruff-format
name: 🐶 Ruff Formatter
language: system
types: [python]
entry: scripts/run-in-env.sh ruff format
require_serial: true
stages: [commit, push, manual]
- id: check-ast
name: 🐍 Check Python AST
language: system
types: [python]
entry: scripts/run-in-env.sh check-ast
- id: check-case-conflict
name: 🔠 Check for case conflicts
language: system
entry: scripts/run-in-env.sh check-case-conflict
- id: check-docstring-first
name: ℹ️ Check docstring is first
language: system
types: [python]
entry: scripts/run-in-env.sh check-docstring-first
- id: check-executables-have-shebangs
name: 🧐 Check that executables have shebangs
language: system
types: [text, executable]
entry: scripts/run-in-env.sh check-executables-have-shebangs
stages: [commit, push, manual]
- id: check-json
name: { Check JSON files
language: system
types: [json]
entry: scripts/run-in-env.sh check-json
- id: check-merge-conflict
name: 💥 Check for merge conflicts
language: system
types: [text]
entry: scripts/run-in-env.sh check-merge-conflict
- id: check-symlinks
name: 🔗 Check for broken symlinks
language: system
types: [symlink]
entry: scripts/run-in-env.sh check-symlinks
- id: check-toml
name: ✅ Check TOML files
language: system
types: [toml]
entry: scripts/run-in-env.sh check-toml
- id: codespell
args: []
exclude_types: [csv, json]
exclude: ^tests/fixtures/
additional_dependencies:
- tomli
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
hooks:
- id: flake8
files: ^(matter_server|scripts)/.+\.py$
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort
files: ^(matter_server|scripts)/.+\.py$
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
name: ✅ Check code for common misspellings
language: system
types: [text]
entry: scripts/run-in-env.sh codespell
- id: detect-private-key
name: 🕵️ Detect Private Keys
language: system
types: [text]
entry: scripts/run-in-env.sh detect-private-key
- id: end-of-file-fixer
name: ⮐ Fix End of Files
language: system
types: [text]
entry: scripts/run-in-env.sh end-of-file-fixer
stages: [commit, push, manual]
- id: no-commit-to-branch
name: 🛑 Don't commit to main branch
language: system
entry: scripts/run-in-env.sh no-commit-to-branch
pass_filenames: false
always_run: true
args:
- --branch=main
- id: pylint
name: 🌟 Starring code with pylint
language: system
types: [python]
entry: scripts/run-in-env.sh pylint
- id: trailing-whitespace
- repo: local
hooks:
name: ✄ Trim Trailing Whitespace
language: system
types: [text]
entry: scripts/run-in-env.sh trailing-whitespace-fixer
stages: [commit, push, manual]
- id: mypy
name: mypy
entry: scripts/run-in-env.sh mypy
types: [python]
language: script
files: ^(matter_server)/.+\.py$

- id: pylint
name: pylint
entry: scripts/run-in-env.sh pylint -j 0
types: [python]
language: script
files: ^(matter_server)/.+\.py$
require_serial: true
files: ^(matter_server|pylint)/.+\.py$
1 change: 0 additions & 1 deletion dashboard/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,3 @@
</head>
<body></body>
</html>

3 changes: 2 additions & 1 deletion dashboard/script/build
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash -i

# Stop on errors
set -e

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

2 changes: 2 additions & 0 deletions dashboard/script/develop
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash -i

# Stop on errors
set -e

Expand Down
1 change: 1 addition & 0 deletions matter_server/client/models/clusters.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from chip.tlv import float32

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


@dataclass
Expand Down
3 changes: 2 additions & 1 deletion matter_server/common/helpers/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
from base64 import b64encode
from typing import Any

import orjson
from chip.clusters.Types import Nullable
from chip.tlv import float32, uint
import orjson

JSON_ENCODE_EXCEPTIONS = (TypeError, ValueError)
JSON_DECODE_EXCEPTIONS = (orjson.JSONDecodeError,)
Expand All @@ -16,6 +16,7 @@ def json_encoder_default(obj: Any) -> Any:
Hand other objects to the original method.
"""
# pylint: disable=too-many-return-statements
if getattr(obj, "do_not_serialize", None):
return None
if isinstance(obj, (set, tuple)):
Expand Down
3 changes: 3 additions & 0 deletions matter_server/common/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Models that are (serializeable) shared between server and client."""

from __future__ import annotations

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

# pylint: disable=too-many-instance-attributes

instance_name: str | None = None
host_name: str | None = None
port: int | None = None
Expand Down
11 changes: 6 additions & 5 deletions matter_server/server/device_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
from __future__ import annotations

import asyncio
import logging
from collections import deque
from datetime import datetime
from functools import partial
import logging
from typing import TYPE_CHECKING, Any, Awaitable, Callable, Iterable, TypeVar, cast

from chip.ChipDeviceCtrl import DeviceProxyWrapper
from chip.clusters import Attribute, Objects as Clusters
from chip.clusters import Attribute
from chip.clusters import Objects as Clusters
from chip.clusters.Attribute import ValueDecodeFailure
from chip.clusters.ClusterObjects import ALL_ATTRIBUTES, ALL_CLUSTERS, Cluster
from chip.exceptions import ChipStackError
Expand Down Expand Up @@ -93,7 +94,7 @@
),
)

# pylint: disable=too-many-lines,too-many-locals,too-many-statements,too-many-branches
# pylint: disable=too-many-lines,too-many-locals,too-many-statements,too-many-branches,too-many-instance-attributes


class MatterDeviceController:
Expand Down Expand Up @@ -244,7 +245,7 @@ async def commission_with_code(
attempts = 0
# we retry commissioning a few times as we've seen devices in the wild
# that are a bit unstable.
# by retrying, we increase the chances of a successful commisssion
# by retrying, we increase the chances of a successful commission
while attempts <= MAX_COMMISSION_RETRIES:
attempts += 1
LOGGER.info(
Expand Down Expand Up @@ -322,7 +323,7 @@ async def commission_on_network(
attempts = 0
# we retry commissioning a few times as we've seen devices in the wild
# that are a bit unstable.
# by retrying, we increase the chances of a successful commisssion
# by retrying, we increase the chances of a successful commission
while attempts <= MAX_COMMISSION_RETRIES:
attempts += 1
if ip_addr is None:
Expand Down
5 changes: 4 additions & 1 deletion matter_server/server/server.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
"""Implementation of a Websocket-based server to proxy Matter support (using CHIP SDK)."""

from __future__ import annotations

import asyncio
import ipaddress
import logging
from typing import Any, Callable, Set, cast
import weakref
from typing import Any, Callable, Set, cast

from aiohttp import web

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

# pylint: disable=too-many-instance-attributes

_runner: web.AppRunner | None = None
_http: MultiHostTCPSite | None = None

Expand Down
Loading

0 comments on commit 665dd59

Please sign in to comment.