Skip to content

Commit

Permalink
Merge pull request #1015 from koordinates/mypy
Browse files Browse the repository at this point in the history
Add type hints and mypy config
  • Loading branch information
craigds authored Nov 11, 2024
2 parents 718e8c4 + ce49e47 commit 3f93dfd
Show file tree
Hide file tree
Showing 62 changed files with 804 additions and 630 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@ env:
AWS_NO_SIGN_REQUEST: "1"

jobs:
type-checking:
name: Run Type Checking
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.11"
cache: 'pip' # caching pip dependencies
- run: pip install -r requirements/requirements.txt -r requirements/test.txt -r requirements/dev.txt
- name: Run mypy
run: mypy

# Increase rate limits for public registry
amazon-ecr-auth:
runs-on: ubuntu-latest
Expand Down
8 changes: 8 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,11 @@ repos:
- id: cmake-lint
args:
- --suppress-decorations
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.13.0
hooks:
- id: mypy
name: Check types with mypy
language: system
entry: build/venv/bin/mypy
pass_filenames: false
11 changes: 5 additions & 6 deletions kart/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import importlib
import logging
import os
import platform
import sys


Expand Down Expand Up @@ -41,17 +40,17 @@
)

try:
import _kart_env
import _kart_env # type: ignore[import]

L.debug("Found _kart_env configuration module")
except ImportError:
L.debug("No _kart_env configuration module found")
_kart_env = None

is_frozen = getattr(sys, "frozen", None) and hasattr(sys, "_MEIPASS")
is_darwin = platform.system() == "Darwin"
is_linux = platform.system() == "Linux"
is_windows = platform.system() == "Windows"
is_darwin = sys.platform == "darwin"
is_linux = sys.platform == "linux"
is_windows = sys.platform == "win32"

if is_darwin:
libsuffix = "dylib"
Expand Down Expand Up @@ -147,7 +146,7 @@ def _env_path(path):
os.environ["PATH"] = (
os.pathsep.join(path_extras) + os.pathsep + os.environ.get("PATH", "")
)
if is_windows:
if sys.platform == "win32":
os.add_dll_directory(prefix if is_frozen else os.path.join(prefix, "lib"))
# FIXME: git2.dll is in the package directory, but isn't setup for ctypes to use
_pygit2_spec = importlib.util.find_spec("pygit2")
Expand Down
6 changes: 4 additions & 2 deletions kart/annotations/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import json
import logging
import threading

from typing import TypeAlias
import sqlalchemy

from kart.sqlalchemy.sqlite import sqlite_engine
Expand All @@ -13,7 +13,9 @@
from sqlalchemy.schema import CreateTable

L = logging.getLogger(__name__)
Base = declarative_base()

# TODO: remove this type ignore when we upgrade sqlalchemy to 2.0 and replace with DeclarativeBase
Base: TypeAlias = declarative_base() # type: ignore[valid-type]


class KartAnnotation(Base):
Expand Down
2 changes: 1 addition & 1 deletion kart/apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ def apply_patch(
"--ref",
default="HEAD",
help="Which ref to apply the patch onto.",
shell_complete=ref_completer,
shell_complete=ref_completer, # type: ignore[call-arg]
)
@click.option(
"--amend",
Expand Down
Loading

0 comments on commit 3f93dfd

Please sign in to comment.