python-kasa/.github/workflows/ci.yml
Steven B 416d3118bf
Configure mypy to run in virtual environment and fix resulting issues (#989)
For some time I've noticed that my IDE is reporting mypy errors that the
pre-commit hook is not picking up. This is because [mypy
mirror](https://github.com/pre-commit/mirrors-mypy) runs in an isolated
pre-commit environment which does not have dependencies installed and it
enables `--ignore-missing-imports` to avoid errors.

This is [advised against by
mypy](https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-library-stubs-or-py-typed-marker)
for obvious reasons:

> We recommend avoiding --ignore-missing-imports if possible: it’s
equivalent to adding a # type: ignore to all unresolved imports in your
codebase.

This PR configures the mypy pre-commit hook to run in the virtual
environment and addresses the additional errors identified as a result.
It also introduces a minimal mypy config into the `pyproject.toml`

[mypy errors identified without the fixes in this
PR](https://github.com/user-attachments/files/15896693/mypyerrors.txt)
2024-06-19 15:07:59 +02:00

116 lines
3.6 KiB
YAML

name: CI
on:
push:
branches: ["master"]
pull_request:
branches: ["master"]
workflow_dispatch: # to allow manual re-runs
env:
POETRY_VERSION: 1.8.2
jobs:
linting:
name: "Perform linting checks"
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.12"]
steps:
- uses: "actions/checkout@v4"
- name: Setup environment
uses: ./.github/actions/setup
with:
python-version: ${{ matrix.python-version }}
cache-pre-commit: true
poetry-version: ${{ env.POETRY_VERSION }}
poetry-install-options: "--all-extras"
- name: "Check supported device md files are up to date"
run: |
poetry run pre-commit run generate-supported --all-files
- name: "Linting and code formating (ruff)"
run: |
poetry run pre-commit run ruff --all-files
- name: "Typing checks (mypy)"
run: |
poetry run pre-commit run mypy --all-files
- name: "Run trailing-whitespace"
run: |
poetry run pre-commit run trailing-whitespace --all-files
- name: "Run end-of-file-fixer"
run: |
poetry run pre-commit run end-of-file-fixer --all-files
- name: "Run check-docstring-first"
run: |
poetry run pre-commit run check-docstring-first --all-files
- name: "Run debug-statements"
run: |
poetry run pre-commit run debug-statements --all-files
- name: "Run check-ast"
run: |
poetry run pre-commit run check-ast --all-files
tests:
name: Python ${{ matrix.python-version}} on ${{ matrix.os }}${{ fromJSON('[" (extras)", ""]')[matrix.extras == ''] }}
needs: linting
runs-on: ${{ matrix.os }}
continue-on-error: ${{ startsWith(matrix.python-version, 'pypy') }}
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "pypy-3.9", "pypy-3.10"]
os: [ubuntu-latest, macos-latest, windows-latest]
extras: [false, true]
exclude:
- os: macos-latest
extras: true
# setup-python not currently working with macos-latest
# https://github.com/actions/setup-python/issues/808
- os: macos-latest
python-version: "3.8"
- os: macos-latest
python-version: "3.9"
- os: windows-latest
extras: true
- os: ubuntu-latest
python-version: "pypy-3.9"
extras: true
- os: ubuntu-latest
python-version: "pypy-3.10"
extras: true
- os: ubuntu-latest
python-version: "3.8"
extras: true
- os: ubuntu-latest
python-version: "3.9"
extras: true
- os: ubuntu-latest
python-version: "3.10"
extras: true
steps:
- uses: "actions/checkout@v4"
- name: Setup environment
uses: ./.github/actions/setup
with:
python-version: ${{ matrix.python-version }}
poetry-version: ${{ env.POETRY_VERSION }}
poetry-install-options: ${{ matrix.extras == true && '--all-extras' || '' }}
- name: "Run tests (no coverage)"
if: ${{ startsWith(matrix.python-version, 'pypy') }}
run: |
poetry run pytest
- name: "Run tests (with coverage)"
if: ${{ !startsWith(matrix.python-version, 'pypy') }}
run: |
poetry run pytest --cov kasa --cov-report xml
- name: "Upload coverage to Codecov"
if: ${{ !startsWith(matrix.python-version, 'pypy') }}
uses: "codecov/codecov-action@v4"
with:
token: ${{ secrets.CODECOV_TOKEN }}