From 30cdde8605880a76d28b682713273d1b2bd1ab27 Mon Sep 17 00:00:00 2001 From: Doug Hoskisson Date: Tue, 16 Apr 2024 14:03:30 -0700 Subject: [PATCH] CI: pyright in github actions (#3121) * CI: strict mypy check in github actions mypy_files.txt is a list of files that will fail the CI if mypy finds errors in them * don't need these * `Any` should be a way to silence the type checker * restrict return Any * CI: pyright in github actions * fix mistake in translating from mypy * missed another change from mypy to pyright * pin pyright version * add more paths that should trigger check * use Python instead of bash * type error for testing CI * Revert "type error for testing CI" This reverts commit 99f65f3dadf67fb18b6bbee90bd77d8dbd10f9f9. * oops * don't need to redirect output --- .github/pyright-config.json | 27 ++++++++++++++++++++ .github/type_check.py | 15 +++++++++++ .github/workflows/strict-type-check.yml | 33 +++++++++++++++++++++++++ ModuleUpdate.py | 2 +- typings/kivy/uix/widget.pyi | 2 +- worlds/LauncherComponents.py | 2 +- 6 files changed, 78 insertions(+), 3 deletions(-) create mode 100644 .github/pyright-config.json create mode 100644 .github/type_check.py create mode 100644 .github/workflows/strict-type-check.yml diff --git a/.github/pyright-config.json b/.github/pyright-config.json new file mode 100644 index 000000000000..6ad7fa5f19b5 --- /dev/null +++ b/.github/pyright-config.json @@ -0,0 +1,27 @@ +{ + "include": [ + "type_check.py", + "../worlds/AutoSNIClient.py", + "../Patch.py" + ], + + "exclude": [ + "**/__pycache__" + ], + + "stubPath": "../typings", + + "typeCheckingMode": "strict", + "reportImplicitOverride": "error", + "reportMissingImports": true, + "reportMissingTypeStubs": true, + + "pythonVersion": "3.8", + "pythonPlatform": "Windows", + + "executionEnvironments": [ + { + "root": ".." + } + ] +} diff --git a/.github/type_check.py b/.github/type_check.py new file mode 100644 index 000000000000..90d41722c9a5 --- /dev/null +++ b/.github/type_check.py @@ -0,0 +1,15 @@ +from pathlib import Path +import subprocess + +config = Path(__file__).parent / "pyright-config.json" + +command = ("pyright", "-p", str(config)) +print(" ".join(command)) + +try: + result = subprocess.run(command) +except FileNotFoundError as e: + print(f"{e} - Is pyright installed?") + exit(1) + +exit(result.returncode) diff --git a/.github/workflows/strict-type-check.yml b/.github/workflows/strict-type-check.yml new file mode 100644 index 000000000000..bafd572a26ae --- /dev/null +++ b/.github/workflows/strict-type-check.yml @@ -0,0 +1,33 @@ +name: type check + +on: + pull_request: + paths: + - "**.py" + - ".github/pyright-config.json" + - ".github/workflows/strict-type-check.yml" + - "**.pyi" + push: + paths: + - "**.py" + - ".github/pyright-config.json" + - ".github/workflows/strict-type-check.yml" + - "**.pyi" + +jobs: + pyright: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-python@v5 + with: + python-version: "3.11" + + - name: "Install dependencies" + run: | + python -m pip install --upgrade pip pyright==1.1.358 + python ModuleUpdate.py --append "WebHostLib/requirements.txt" --force --yes + + - name: "pyright: strict check on specific files" + run: python .github/type_check.py diff --git a/ModuleUpdate.py b/ModuleUpdate.py index c3dc8c8a87b2..ed041bef4604 100644 --- a/ModuleUpdate.py +++ b/ModuleUpdate.py @@ -70,7 +70,7 @@ def install_pkg_resources(yes=False): subprocess.call([sys.executable, "-m", "pip", "install", "--upgrade", "setuptools"]) -def update(yes=False, force=False): +def update(yes: bool = False, force: bool = False) -> None: global update_ran if not update_ran: update_ran = True diff --git a/typings/kivy/uix/widget.pyi b/typings/kivy/uix/widget.pyi index 54e3b781ea01..bf736fae72fc 100644 --- a/typings/kivy/uix/widget.pyi +++ b/typings/kivy/uix/widget.pyi @@ -1,7 +1,7 @@ """ FillType_* is not a real kivy type - just something to fill unknown typing. """ from typing import Any, Optional, Protocol -from ..graphics import FillType_Drawable, FillType_Vec +from ..graphics.texture import FillType_Drawable, FillType_Vec class FillType_BindCallback(Protocol): diff --git a/worlds/LauncherComponents.py b/worlds/LauncherComponents.py index 41c0bb83295f..78ec14b4a4f5 100644 --- a/worlds/LauncherComponents.py +++ b/worlds/LauncherComponents.py @@ -64,7 +64,7 @@ class SuffixIdentifier: def __init__(self, *args: str): self.suffixes = args - def __call__(self, path: str): + def __call__(self, path: str) -> bool: if isinstance(path, str): for suffix in self.suffixes: if path.endswith(suffix):