Skip to content

Commit

Permalink
ci: Enable static type checking with mypy (meltano#6707)
Browse files Browse the repository at this point in the history
* ci: Enable static type checking with mypy

* List modules in meltano.core individually
  • Loading branch information
edgarrmondragon committed Sep 6, 2022
1 parent bc97d63 commit 565c254
Show file tree
Hide file tree
Showing 8 changed files with 145 additions and 3 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -255,3 +255,46 @@ jobs:
- name: Upload coverage report
uses: codecov/codecov-action@v3.1.0

mypy:
name: "Static type checking"
runs-on: ubuntu-latest
env:
FORCE_COLOR: 1

steps:
- name: Check out the repository
uses: actions/checkout@v3.0.2

- name: Setup Python 3.9
uses: actions/setup-python@v4.2.0
with:
python-version: '3.9'
architecture: x64
cache: 'pip'
cache-dependency-path: 'poetry.lock'

- name: Install Poetry
env:
PIP_CONSTRAINT: .github/workflows/resources/constraints.txt
run: |
pipx install poetry
poetry --version
- name: Upgrade pip
env:
PIP_CONSTRAINT: .github/workflows/resources/constraints.txt
run: |
pip install pip
pip --version
- name: Install Nox
env:
PIP_CONSTRAINT: .github/workflows/resources/constraints.txt
run: |
pipx install nox
pipx inject nox nox-poetry
- name: Run mypy
run: |
nox -rs mypy
3 changes: 2 additions & 1 deletion docs/src/_contribute/style.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ Python:
Flake8 is a python tool that glues together `pycodestyle`, `pyflakes`, `mccabe`, and third-party plugins to check the style and quality of python code,
and `wemake-python-styleguide` is a plugin for Flake8 that offers an extensive set of opinionated rules that encourage clean and correct code.

[MyPy is currently not executed in CI](https://github.com/meltano/meltano/issues/6491). It currently raises many issues when run. We intend to address them over time.
[MyPy is being adopted incrementally by this codebase](https://github.com/meltano/meltano/issues/6491). If you are adding new code, please use type hints.
To enable type checks for an existing module, _de-glob_ it in the whitelist in `pyproject.toml` and fix any errors.

Javascript:

Expand Down
14 changes: 14 additions & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,17 @@ def coverage(session: Session) -> None:
session.run("coverage", "combine")

session.run("coverage", *args)


@nox_session(python=main_python_version)
def mypy(session: Session) -> None:
"""Run mypy type checking.
Args:
session: Nox session.
"""
args = session.posargs or ["src/meltano"]

session.install(".")
session.install("mypy", "sqlalchemy2-stubs")
session.run("mypy", *args)
78 changes: 78 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,84 @@ version_files = [
'docs/package.json:^ "version":',
]

[tool.mypy]
files = "src"

# The following whitelist is used to allow for incremental adoption
# of MyPy. Modules should be removed from this whitelist as and when
# their respective type errors have been addressed. No new modules
# should be added to this whitelist.
[[tool.mypy.overrides]]
module = [
"meltano.api.*",
"meltano.cli.*",
"meltano.migrations.*",
"meltano.oauth.*",
# Way too many modules at the root of meltano.core to tackle them all at once
# so listing them individually here.
"meltano.core.cli_messages",
"meltano.core.config_service",
"meltano.core.connection_service",
"meltano.core.db",
"meltano.core.discovery_file",
"meltano.core.elt_context",
"meltano.core.environment",
"meltano.core.environment_service",
"meltano.core.error",
"meltano.core.extract_utils",
"meltano.core.extractor",
"meltano.core.meltano_file",
"meltano.core.meltano_invoker",
"meltano.core.migration_service",
"meltano.core.models",
"meltano.core.plugin_discovery_service",
"meltano.core.plugin_install_service",
"meltano.core.plugin_invoker",
"meltano.core.plugin_location_remove",
"meltano.core.plugin_lock_service",
"meltano.core.plugin_remove_service",
"meltano.core.plugin_test_service",
"meltano.core.project",
"meltano.core.project_add_service",
"meltano.core.project_files",
"meltano.core.project_init_service",
"meltano.core.project_plugins_service",
"meltano.core.project_settings_service",
"meltano.core.schedule",
"meltano.core.schedule_service",
"meltano.core.select_service",
"meltano.core.setting",
"meltano.core.setting_definition",
"meltano.core.settings_service",
"meltano.core.settings_store",
"meltano.core.sqlalchemy",
"meltano.core.state_service",
"meltano.core.task_sets",
"meltano.core.task_sets_service",
"meltano.core.transform_add_service",
"meltano.core.upgrade_service",
"meltano.core.validation_service",
"meltano.core.venv_service",
"meltano.core.yaml",
# Meltano Core submodules
"meltano.core.behavior.*",
"meltano.core.block.*",
"meltano.core.bundle.*",
"meltano.core.compiler.*",
"meltano.core.container.*",
"meltano.core.hub.*",
"meltano.core.job.*",
"meltano.core.legacy_tracking.*",
"meltano.core.logging.*",
"meltano.core.m5o.*",
"meltano.core.plugin.*",
"meltano.core.runner.*",
"meltano.core.sql.*",
"meltano.core.tracking.*",
"meltano.core.utils.*",
]
ignore_errors = true

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
2 changes: 1 addition & 1 deletion src/meltano/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@

from __future__ import annotations

# Managed by bumpversion
# Managed by commitizen
__version__ = "2.5.0"
3 changes: 3 additions & 0 deletions src/meltano/core/container/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""Handling of plugin container commands."""

from __future__ import annotations
2 changes: 1 addition & 1 deletion src/meltano/core/container/container_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from structlog.stdlib import get_logger

from .container_spec import ContainerSpec
from meltano.core.container.container_spec import ContainerSpec

if TYPE_CHECKING:
from aiodocker.containers import DockerContainer
Expand Down
3 changes: 3 additions & 0 deletions src/meltano/migrations/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""SQL migration utilities."""

from __future__ import annotations

0 comments on commit 565c254

Please sign in to comment.