From 2348815ed63131d287cbcad700dbd55bf1e4c7b1 Mon Sep 17 00:00:00 2001 From: Frank Bessou <frank.bessou@logilab.fr> Date: Wed, 4 Sep 2024 15:33:31 +0200 Subject: [PATCH] chore: add mypy type checking --- .github/workflows/lint.yml | 10 ++++++++-- .github/workflows/test.yml | 4 +++- git_hg_sync/__main__.py | 5 ++++- pyproject.toml | 8 ++++++++ tests/utils.py | 3 ++- tox.ini | 4 ++++ 6 files changed, 29 insertions(+), 5 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index acebe2f..9821e0a 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -5,5 +5,11 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: chartboost/ruff-action@v1 - - uses: psf/black@stable + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: 3.11 + - name: Install tox + run: pip install tox + - name: Lint with ruff, black and mypy + run: tox -e lint diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7d480e7..a00ce10 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,8 +1,10 @@ name: Python -on: [push, pull_request] +on: [pull_request] jobs: Pytest: runs-on: ubuntu-latest + permissions: + pull-requests: write steps: - uses: actions/checkout@v4 - name: Set up Python 3.10 diff --git a/git_hg_sync/__main__.py b/git_hg_sync/__main__.py index 5b773ae..334469f 100644 --- a/git_hg_sync/__main__.py +++ b/git_hg_sync/__main__.py @@ -1,5 +1,6 @@ import argparse import sys +import logging from pathlib import Path import sentry_sdk @@ -45,7 +46,9 @@ def get_queue(config): ) -def start_app(config, logger, *, one_shot=False): +def start_app( + config: Config, logger: logging.Logger, *, one_shot: bool = False +) -> None: pulse_config = config.pulse connection = get_connection(pulse_config) diff --git a/pyproject.toml b/pyproject.toml index 90b60c2..b76d206 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,3 +11,11 @@ dependencies = ['kombu', 'mozillapulse', 'GitPython', 'mozlog', "pydantic", "sen [tool.ruff] line-length = 100 + +[[tool.mypy.overrides]] +module = [ + 'kombu.*', + 'mozlog' +] + +ignore_missing_imports = true diff --git a/tests/utils.py b/tests/utils.py index c32a216..bd085ed 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -1,7 +1,8 @@ +from pathlib import Path import subprocess -def hg_export_tip(repo_path: str): +def hg_export_tip(repo_path: Path): process = subprocess.run( ["hg", "export", "tip"], cwd=repo_path, diff --git a/tox.ini b/tox.ini index f05ed26..baf2429 100644 --- a/tox.ini +++ b/tox.ini @@ -19,6 +19,10 @@ description = lint source code deps = ruff black + mypy + pytest # dev dependency +ignore_errors = true # Run commands even if an earlier command failed commands = ruff check git_hg_sync/ tests/ black --check git_hg_sync tests + mypy git_hg_sync/ tests/