From 5bfc0bbf384f0dd18c080c6660343a9b761d1c8f Mon Sep 17 00:00:00 2001 From: Nathan Weinberg Date: Wed, 5 Jun 2024 10:41:44 -0400 Subject: [PATCH] Add mypy to new lint action Signed-off-by: Nathan Weinberg --- .github/workflows/lint.yml | 10 ++++++++-- pyproject.toml | 11 ++++++++++- tox.ini | 12 +++++++++++- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index fd1c0f70..72af9aff 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -1,6 +1,6 @@ # SPDX-License-Identifier: Apache-2.0 -name: Lint and Format +name: Lint, Format, and MyPy on: push: @@ -50,6 +50,7 @@ jobs: **/requirements*.txt - name: Install dependencies + id: deps run: | python -m pip install --upgrade pip python -m pip install tox @@ -59,7 +60,12 @@ jobs: tox -e ruff -- check - name: Run linting - if: success() || failure() + if: ${{ !cancelled() && (steps.deps.outcome == 'success') }} run: | echo "::add-matcher::.github/workflows/matchers/pylint.json" tox -e lint + + - name: Run mypy type checks + if: ${{ !cancelled() && (steps.deps.outcome == 'success') }} + run: | + tox -e mypy diff --git a/pyproject.toml b/pyproject.toml index 933291bb..8588d2be 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -38,7 +38,7 @@ source = "https://github.com/instructlab/sdg" issues = "https://github.com/instructlab/sdg/issues" [tool.setuptools_scm] -version_file = "src/sdg/_version.py" +version_file = "src/instructlab_sdg/_version.py" # do not include +gREV local version, required for Test PyPI upload local_scheme = "no-local-version" @@ -103,3 +103,12 @@ from-first = true # import-heading-firstparty=First Party # import-heading-localfolder=Local known-local-folder = ["tuning"] + +[tool.mypy] +disable_error_code = ["import-not-found", "import-untyped"] +exclude = [ + "^src/instructlab_sdg/generate_data\\.py$", + "^src/instructlab_sdg/utils\\.py$", +] +# honor excludes by not following there through imports +follow_imports = "silent" diff --git a/tox.ini b/tox.ini index 3f44fe83..c722f0e4 100644 --- a/tox.ini +++ b/tox.ini @@ -3,7 +3,7 @@ [tox] # py3-unit runs unit tests with 'python3' # py311-unit runs the same tests with 'python3.11' -envlist = ruff, lint, spellcheck +envlist = ruff, lint, mypy, spellcheck minversion = 4.4 # format, check, and linting targets don't build and install the project to @@ -49,3 +49,13 @@ commands = sh -c 'command -v aspell || (echo "aspell is not installed. Please install it." && exit 1)' {envpython} -m pyspelling --config {toxinidir}/.spellcheck.yml --spellchecker aspell allowlist_externals = sh + +[testenv:mypy] +description = Python type checking with mypy +deps = + mypy>=1.10.0,<2.0 + types-tqdm + types-PyYAML + pytest +commands = + mypy src