Skip to content

Commit

Permalink
build: remove type checking CI from pre-commit. (#2462)
Browse files Browse the repository at this point in the history
* build: remove type checking CI from pre-commit.

* Adds mypy and pyright commands.

* Add "Running type checkers" contribution guide.
  • Loading branch information
peterschutt authored Oct 19, 2023
1 parent 3a2089a commit 7c3d24f
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 135 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,56 @@ jobs:
- name: Execute Pre-Commit
run: pre-commit run --show-diff-on-failure --color=always --all-files

mypy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v4
with:
python-version: "3.12"
allow-prereleases: true

- uses: pdm-project/setup-pdm@v3
name: Set up PDM
with:
python-version: "3.12"
allow-python-prereleases: false
cache: true
cache-dependency-path: |
./pdm.lock
- name: Install dependencies
run: pdm install -G:all

- name: Run mypy
run: pdm run mypy

pyright:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v4
with:
python-version: "3.12"
allow-prereleases: true

- uses: pdm-project/setup-pdm@v3
name: Set up PDM
with:
python-version: "3.12"
allow-python-prereleases: false
cache: true
cache-dependency-path: |
./pdm.lock
- name: Install dependencies
run: pdm install -G:all

- name: Run pyright
run: pdm run pyright

test:
name: "test (${{ matrix.python-version }}, pydantic@${{ matrix.pydantic-version }})"
strategy:
Expand Down
132 changes: 0 additions & 132 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,138 +57,6 @@ repos:
hooks:
- id: slotscheck
exclude: "test_*|docs"
- repo: https://github.com/pre-commit/mirrors-mypy
rev: "v1.6.0"
hooks:
- id: mypy
exclude: "docs.*|test_apps.*|tests/examples.*"
files: "^litestar/.*|^tests/.*"
additional_dependencies:
[
"advanced_alchemy>=0.2.2,<0.4.0",
aiosqlite,
annotated_types,
anyio>=3,
asyncpg,
asyncpg_stubs,
attrs,
beanie>=1.21.0,
beautifulsoup4,
brotli,
click,
cryptography,
fast-query-parsers>=1.0.2,
fsspec,
greenlet,
httpx>=0.22,
httpx_sse,
hypothesis,
jinja2>=3.1.2,
jsbeautifier,
mako>=1.2.4,
minijinja>=1.0.0,
msgspec>=0.18.2,
multidict>=6.0.2,
opentelemetry-instrumentation-asgi,
opentelemetry-sdk,
piccolo,
picologging,
polyfactory>=2.6.3,
prometheus_client,
"pydantic[email]>=2",
pydantic-extra-types,
pytest,
pytest-asyncio,
pytest-cov,
pytest-lazy-fixture,
pytest-mock,
pytest-rerunfailures,
pytest-timeout,
pytest-xdist,
python-dotenv,
python-jose,
pyyaml,
"redis[hiredis]>=4.4.4",
rich-click,
rich>=13.0.0,
starlette,
structlog,
time-machine,
trio,
types-beautifulsoup4,
types-pytest-lazy-fixture,
types-python-jose,
types-pyyaml,
types-redis,
typing-extensions,
"uvicorn[standard]",
uvloop>=0.18.0,
]
- repo: https://github.com/RobertCraigie/pyright-python
rev: v1.1.331
hooks:
- id: pyright
additional_dependencies:
[
"advanced_alchemy>=0.2.2,<0.4.0",
aiosqlite,
annotated_types,
anyio>=3,
asyncpg,
asyncpg_stubs,
attrs,
beanie>=1.21.0,
beautifulsoup4,
brotli,
click,
cryptography,
fast-query-parsers>=1.0.2,
fsspec,
greenlet,
httpx>=0.22,
httpx_sse,
hypothesis,
jinja2>=3.1.2,
jsbeautifier,
mako>=1.2.4,
minijinja>=1.0.0,
msgspec>=0.18.2,
multidict>=6.0.2,
opentelemetry-instrumentation-asgi,
opentelemetry-sdk,
piccolo,
picologging,
polyfactory>=2.6.3,
prometheus_client,
"pydantic[email]>=2",
pydantic-extra-types,
pytest,
pytest-asyncio,
pytest-cov,
pytest-lazy-fixture,
pytest-mock,
pytest-rerunfailures,
pytest-timeout,
pytest-xdist,
python-dotenv,
python-jose,
pyyaml,
"redis[hiredis]>=4.4.4",
rich-click,
rich>=13.0.0,
starlette,
structlog,
time-machine,
trio,
types-beautifulsoup4,
types-pytest-lazy-fixture,
types-python-jose,
types-pyyaml,
types-redis,
typing-extensions,
"uvicorn[standard]",
uvloop>=0.18.0,
]
- repo: https://github.com/sphinx-contrib/sphinx-lint
rev: "v0.6.8"
hooks:
Expand Down
12 changes: 12 additions & 0 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,18 @@ or ``make coverage``. Due to the nature of pytest-xdist, attaching a debugger is
straightforward. For debugging, it's recommended to run the tests individually with
``pytest <test name>`` or via an IDE, which will skip pytest-xdist.

Running type checkers
+++++++++++++++++++++

We use `mypy <https://mypy.readthedocs.io/en/stable/>`_ and `pyright <https://microsoft.github.io/pyright/#/>`_ to
enforce type safety. You can run them with:

- ``make mypy``
- ``make pyright``
- ``make typecheck`` to run both
- ``make lint`` to run pre-commit hooks and type checkers.

Our type checkers are run on Python 3.12 in CI, so you should make sure to run them on the same version locally as well.

Project documentation
---------------------
Expand Down
22 changes: 20 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,30 @@ lock: ## Rebuild lockfiles from scra
# =============================================================================
# Tests, Linting, Coverage
# =============================================================================
.PHONY: lint
lint: ## Runs pre-commit hooks; includes ruff linting, codespell, black
.PHONY: mypy
mypy: ## Run mypy
@echo "=> Running mypy"
@$(ENV_PREFIX)mypy
@echo "=> mypy complete"

.PHONY: pyright
pyright: ## Run pyright
@echo "=> Running pyright"
@$(ENV_PREFIX)pyright
@echo "=> pyright complete"

.PHONY: type-check
type-check: mypy pyright ## Run all type checking

.PHONY: pre-commit
pre-commit: ## Runs pre-commit hooks; includes ruff linting, codespell, black
@echo "=> Running pre-commit process"
@$(ENV_PREFIX)pre-commit run --all-files
@echo "=> Pre-commit complete"

.PHONY: lint
lint: pre-commit type-check ## Run all linting

.PHONY: coverage
coverage: ## Run the tests and generate coverage report
@echo "=> Running tests with coverage"
Expand Down
2 changes: 1 addition & 1 deletion tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ def get_exception_group() -> type[BaseException]:
try:
return ExceptionGroup
except NameError:
from exceptiongroup import ExceptionGroup as _ExceptionGroup # pyright: ignore[reportMissingImports]
from exceptiongroup import ExceptionGroup as _ExceptionGroup # type: ignore[import-not-found]

return cast("type[BaseException]", _ExceptionGroup)

0 comments on commit 7c3d24f

Please sign in to comment.