diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fc377d8..066b8b6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,80 +6,60 @@ on: pull_request: jobs: - pylint: + ci: + name: ${{ matrix.name }} runs-on: ubuntu-latest + strategy: + matrix: + include: + - id: flake8 + name: Lint with flake8 + - id: pylint + name: Lint with pylint + - id: black + name: Check formatting with black + - id: isort + name: Check import order with isort + - id: mypy + name: Check typing with mypy steps: - uses: actions/checkout@v2 - name: Set up Python uses: actions/setup-python@v2 + id: python with: python-version: '3.7' - - name: Set up Python environment + + - name: Get pip cache dir + id: pip-cache run: | - pip3 install -e . - pip3 install -r requirements_test.txt - - name: Register problem matcher - run: | - echo "::add-matcher::.github/workflows/matchers/pylint.json" - - run: pylint aioesphomeapi - flake8: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Set up Python - uses: actions/setup-python@v2 + echo "::set-output name=dir::$(pip cache dir)" + - name: Restore PIP cache + uses: actions/cache@v2 with: - python-version: '3.7' + path: ${{ steps.pip-cache.outputs.dir }} + key: pip-${{ steps.python.outputs.python-version }}-${{ hashFiles('requirements.txt', 'requirements_test.txt') }} + restore-keys: | + pip-${{ steps.python.outputs.python-version }}- - name: Set up Python environment run: | + pip3 install -r requirements.txt -r requirements_test.txt pip3 install -e . - pip3 install -r requirements_test.txt - - name: Register problem matcher + + - name: Register problem matchers run: | echo "::add-matcher::.github/workflows/matchers/flake8.json" - - run: flake8 aioesphomeapi - black: - 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: black --safe --exclude 'api_pb2.py|api_options_pb2.py' aioesphomeapi - isort: - 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 - - name: Register problem matcher - run: | + echo "::add-matcher::.github/workflows/matchers/pylint.json" echo "::add-matcher::.github/workflows/matchers/isort.json" - - run: isort --check aioesphomeapi - mypy: - 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 - - name: Register problem matcher - run: | echo "::add-matcher::.github/workflows/matchers/mypy.json" - - run: mypy --strict aioesphomeapi + + - run: flake8 aioesphomeapi + if: ${{ matrix.id == 'flake8' }} + - run: pylint aioesphomeapi + if: ${{ matrix.id == 'pylint' }} + - run: black --check --diff --color aioesphomeapi + if: ${{ matrix.id == 'black' }} + - run: isort --check --diff aioesphomeapi + if: ${{ matrix.id == 'isort' }} + - run: mypy aioesphomeapi + if: ${{ matrix.id == 'mypy' }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e98abd9..eb7a626 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -5,25 +5,9 @@ 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/mypy.ini b/mypy.ini new file mode 100644 index 0000000..1a9998a --- /dev/null +++ b/mypy.ini @@ -0,0 +1,7 @@ +[mypy] +python_version = 3.7 +show_error_codes = true + +strict = true +warn_unreachable = true + diff --git a/pylintrc b/pylintrc deleted file mode 100644 index caca6a3..0000000 --- a/pylintrc +++ /dev/null @@ -1,18 +0,0 @@ -[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, - raise-missing-from, - bad-mcs-classmethod-argument, - duplicate-code, diff --git a/pyproject.toml b/pyproject.toml index 59441a4..06ed47e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,3 +2,29 @@ profile = "black" multi_line_output = 3 extend_skip = ["api_pb2.py", "api_options_pb2.py"] + +[tool.black] +exclude = 'api_pb2.py|api_options_pb2.py' +target-version = ['py37'] + +[tool.pylint.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", + "raise-missing-from", + "bad-mcs-classmethod-argument", + "duplicate-code", +] diff --git a/script/lint b/script/lint index 75db083..466b77b 100755 --- a/script/lint +++ b/script/lint @@ -3,8 +3,8 @@ cd "$(dirname "$0")/.." set -euxo pipefail -black --safe --exclude 'api_pb2.py|api_options_pb2.py' aioesphomeapi +black --safe aioesphomeapi pylint aioesphomeapi flake8 aioesphomeapi isort aioesphomeapi -mypy --strict aioesphomeapi +mypy aioesphomeapi