Skip to content

Commit

Permalink
Add typechecking tests using Mypy and Pytype
Browse files Browse the repository at this point in the history
* New tasks are marked optional and will not stop CI even if they fail
* Added Makefile targets and GitHub Actions steps
* Added caching for `pip` in GitHub Actions workflow
  • Loading branch information
mbrukman committed Aug 19, 2024
1 parent 37b4e74 commit 784b6b3
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,27 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
cache: 'pip'

- name: Run tests
run: make test VERBOSE=1

- name: Install Python deps for typechecking tests
run: python -m pip install -r requirements-test.txt

- name: Check types with Mypy
run: make mypy-test
# Mark this check optional for now, in case it starts out failing.
# We will make it required once we've fixed any existing issues.
continue-on-error: true

- name: Check types with PyType
run: make pytype-test
# Mark this check optional for now, in case it starts out failing.
# We will make it required once we've fixed any existing issues.
continue-on-error: true
# https://github.com/google/pytype/issues/1475
#
# PyType does not yet support Python 3.12; if this step is enabled, it
# fails with an error: "Python versions > 3.11 are not yet supported."
if: ${{ matrix.python != '3.12' }}
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,11 @@ autopep8:
$(VERB) find . -name \*\.py \
| xargs -I {} python $(THIRD_PARTY_PYTHON)/autopep8.py --in-place {}

mypy-test:
$(VERB) python -m mypy --ignore-missing-imports `find . -name 'third_party' -prune -o -name '*.py' -print`

pytype-test:
$(VERB) python -m pytype -k `find . -name 'third_party' -prune -o -name '*.py' -print`

clean:
$(VERB) rm -rf `find . -name \*\.pyc` $(THIRD_PARTY_PYTHON)/*
3 changes: 3 additions & 0 deletions requirements-test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Type checking.
mypy ~= 1.9.0
pytype ~= 2024.3.19
8 changes: 8 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# We don't need any content here, but the absence of this file breaks
# actions/setup-python in GitHub Actions, e.g.,
#
# https://github.com/mbrukman/csv2txf/actions/runs/10437183622/job/28903088310?pr=29
#
# > Error: No file in /Users/runner/work/csv2txf/csv2txf matched to
# > [**/requirements.txt or **/pyproject.toml], make sure you have checked out
# > the target repository

0 comments on commit 784b6b3

Please sign in to comment.