From 8bf95336d612f422ed6ea209aa017dbb575f36fe Mon Sep 17 00:00:00 2001 From: Otto Winter Date: Tue, 14 Jul 2020 20:00:12 +0200 Subject: [PATCH] Add pylint --- .github/workflows/ci.yml | 22 ++++++++++++++++++++++ .github/workflows/release.yml | 16 ++++++++++++++++ aioesphomeapi/__init__.py | 8 ++++---- aioesphomeapi/client.py | 3 +++ aioesphomeapi/connection.py | 5 +++-- aioesphomeapi/util.py | 1 + pylintrc | 15 +++++++++++++++ requirements_test.txt | 1 + 8 files changed, 65 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 pylintrc create mode 100644 requirements_test.txt diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..7764f0f --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,22 @@ +name: CI + +on: + push: + branches: [master] + pull_request: + +jobs: + pylint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.7' + - name: Set up python environment + run: | + pip3 install -e . + pip3 install -r requirements_test.txt + + - run: pylint aioesphomeapi diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index eb7a626..8efd55d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -5,9 +5,25 @@ on: types: [published] jobs: + pylint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.7' + - name: Set up python environment + run: | + pip3 install -e . + pip3 install -r requirements_test.txt + + - run: pylint aioesphomeapi + deploy-pypi: name: Build and publish to PyPi runs-on: ubuntu-latest + needs: [pylint] steps: - uses: actions/checkout@v2 - name: Set up Python diff --git a/aioesphomeapi/__init__.py b/aioesphomeapi/__init__.py index 573689e..b7b7cd3 100644 --- a/aioesphomeapi/__init__.py +++ b/aioesphomeapi/__init__.py @@ -1,5 +1,5 @@ -from .client import * -from .connection import * -from .core import * +from .client import APIClient +from .connection import ConnectionParams, APIConnection +from .core import APIConnectionError, MESSAGE_TYPE_TO_PROTO from .model import * -from .util import * +from .util import resolve_ip_address_getaddrinfo, resolve_ip_address diff --git a/aioesphomeapi/client.py b/aioesphomeapi/client.py index 2cb2a90..4a0f00f 100644 --- a/aioesphomeapi/client.py +++ b/aioesphomeapi/client.py @@ -166,6 +166,7 @@ class APIClient: return kwargs = {} + # pylint: disable=undefined-loop-variable for key, _ in attr.fields_dict(cls).items(): kwargs[key] = getattr(msg, key) on_state(cls(**kwargs)) @@ -380,6 +381,7 @@ class APIClient: UserServiceArgType.FLOAT_ARRAY: 'float_array', UserServiceArgType.STRING_ARRAY: 'string_array', } + # pylint: disable=redefined-outer-name if arg_desc.type_ in map_array: attr = getattr(arg, map_array[arg_desc.type_]) attr.extend(val) @@ -387,6 +389,7 @@ class APIClient: setattr(arg, map_single[arg_desc.type_], val) args.append(arg) + # pylint: disable=no-member req.args.extend(args) await self._connection.send_message(req) diff --git a/aioesphomeapi/connection.py b/aioesphomeapi/connection.py index 0154532..98f511c 100644 --- a/aioesphomeapi/connection.py +++ b/aioesphomeapi/connection.py @@ -146,7 +146,7 @@ class APIConnection: resp.api_version_major, resp.api_version_minor) if self._api_version.major > 2: _LOGGER.error("%s: Incompatible version %s! Closing connection", - self._api_version.major) + self._params.address, self._api_version.major) await self._on_error() raise APIConnectionError("Incompatible API version.") self._connected = True @@ -205,6 +205,7 @@ class APIConnection: self._params.address, type(msg), str(msg)) req = bytes([0]) req += _varuint_to_bytes(len(encoded)) + # pylint: disable=undefined-loop-variable req += _varuint_to_bytes(message_type) req += encoded await self._write(req) @@ -313,7 +314,7 @@ class APIConnection: self._params.address, err) await self._on_error() break - except Exception as err: + except Exception as err: # pylint: disable=broad-except _LOGGER.info("%s: Unexpected error while reading incoming messages: %s", self._params.address, err) await self._on_error() diff --git a/aioesphomeapi/util.py b/aioesphomeapi/util.py index 56858bb..a946017 100644 --- a/aioesphomeapi/util.py +++ b/aioesphomeapi/util.py @@ -2,6 +2,7 @@ import asyncio import socket from typing import Optional, Tuple, Any +# pylint: disable=cyclic-import from aioesphomeapi.core import APIConnectionError diff --git a/pylintrc b/pylintrc new file mode 100644 index 0000000..4c9373a --- /dev/null +++ b/pylintrc @@ -0,0 +1,15 @@ +[MASTER] +reports=no +ignore=api_pb2.py,api_options_pb2.py + +disable= + missing-docstring, + too-few-public-methods, + too-many-instance-attributes, + wildcard-import, + invalid-name, + too-many-arguments, + line-too-long, + protected-access, + unused-wildcard-import, + import-outside-toplevel, diff --git a/requirements_test.txt b/requirements_test.txt new file mode 100644 index 0000000..36d944e --- /dev/null +++ b/requirements_test.txt @@ -0,0 +1 @@ +pylint==2.5.3