Finish strict typing

This commit is contained in:
Stéphane Bidoul 2021-11-14 14:42:02 +01:00
parent d80df82173
commit 88e5cb5b44
No known key found for this signature in database
GPG key ID: BCAB2555446B5B92
10 changed files with 47 additions and 19 deletions

View file

@ -16,10 +16,11 @@ jobs:
- name: Install project - name: Install project
run: | run: |
pip install -U "pip>=21.3.1" pip install -U "pip>=21.3.1"
pip install -e .[test] -c requirements.txt -c requirements-test.txt pip install -e .[test,mypy] -c requirements.txt -c requirements-test.txt -c requirements-mypy.txt
- name: Run tests - name: Run tests
run: | run: pytest -v --cov --cov-report=xml ./tests
pytest -v --cov --cov-report=xml ./tests - name: Run mypy
run: mypy ./src/runboat ./tests
- uses: codecov/codecov-action@v1 - uses: codecov/codecov-action@v1
build-image: build-image:
runs-on: ubuntu-latest runs-on: ubuntu-latest

View file

@ -39,4 +39,4 @@ repos:
rev: v2.29.0 rev: v2.29.0
hooks: hooks:
- id: pyupgrade - id: pyupgrade
args: ["--py38-plus"] args: ["--py39-plus"]

View file

@ -27,6 +27,9 @@ test = [
"pytest-cov", "pytest-cov",
"pytest-dotenv", "pytest-dotenv",
] ]
mypy = [
"mypy",
]
[project.urls] [project.urls]
Home = "https://github.com/sbidoul/runboat" Home = "https://github.com/sbidoul/runboat"
@ -39,3 +42,23 @@ env_override_existing_values = 1
env_files = [".env.test"] env_files = [".env.test"]
# flake8 config is in .flake8 # flake8 config is in .flake8
[tool.mypy]
strict = true
show_error_codes = true
[[tool.mypy.overrides]]
module = "uvicorn.*"
ignore_missing_imports = true
[[tool.mypy.overrides]]
module = "urllib3.*"
ignore_missing_imports = true
[[tool.mypy.overrides]]
module = "kubernetes.*"
ignore_missing_imports = true
[[tool.mypy.overrides]]
module = "ansi2html"
ignore_missing_imports = true

4
requirements-mypy.txt Normal file
View file

@ -0,0 +1,4 @@
# frozen requirements generated by pip-deepfreeze
mypy==0.910
mypy-extensions==0.4.3
toml==0.10.2

View file

@ -1,7 +1,7 @@
import datetime import datetime
from typing import Optional from typing import Optional
from ansi2html import Ansi2HTMLConverter # type: ignore from ansi2html import Ansi2HTMLConverter
from fastapi import APIRouter, Depends, HTTPException, status from fastapi import APIRouter, Depends, HTTPException, status
from fastapi.responses import HTMLResponse from fastapi.responses import HTMLResponse
from pydantic import BaseModel from pydantic import BaseModel
@ -124,24 +124,24 @@ async def build(name: str) -> models.Build:
"/builds/{name}/init-log", "/builds/{name}/init-log",
response_class=HTMLResponse, response_class=HTMLResponse,
) )
async def init_log(name: str): async def init_log(name: str) -> str:
build = await _build_by_name(name) build = await _build_by_name(name)
log = await build.init_log() log = await build.init_log()
if not log: if not log:
raise HTTPException(status_code=HTTP_404_NOT_FOUND, detail="No log found.") raise HTTPException(status_code=HTTP_404_NOT_FOUND, detail="No log found.")
return Ansi2HTMLConverter().convert(log) return Ansi2HTMLConverter().convert(log) # type: ignore [no-any-return]
@router.get( @router.get(
"/builds/{name}/log", "/builds/{name}/log",
response_class=HTMLResponse, response_class=HTMLResponse,
) )
async def log(name: str): async def log(name: str) -> str:
build = await _build_by_name(name) build = await _build_by_name(name)
log = await build.log() log = await build.log()
if not log: if not log:
raise HTTPException(status_code=HTTP_404_NOT_FOUND, detail="No log found.") raise HTTPException(status_code=HTTP_404_NOT_FOUND, detail="No log found.")
return Ansi2HTMLConverter().convert(log) return Ansi2HTMLConverter().convert(log) # type: ignore [no-any-return]
@router.post("/builds/{name}/start") @router.post("/builds/{name}/start")

View file

@ -30,7 +30,7 @@ class Controller:
""" """
db: BuildsDb db: BuildsDb
_tasks: list[asyncio.Task] _tasks: list[asyncio.Task[None]]
_wakeup_initializer: asyncio.Event _wakeup_initializer: asyncio.Event
_wakeup_stopper: asyncio.Event _wakeup_stopper: asyncio.Event
_wakeup_undeployer: asyncio.Event _wakeup_undeployer: asyncio.Event

View file

@ -11,12 +11,12 @@ from importlib import resources
from pathlib import Path from pathlib import Path
from typing import Any, Callable, Generator, Optional, TypedDict, cast from typing import Any, Callable, Generator, Optional, TypedDict, cast
import urllib3 # type: ignore import urllib3
from jinja2 import Template from jinja2 import Template
from kubernetes import client, config, watch # type: ignore from kubernetes import client, config, watch
from kubernetes.client.exceptions import ApiException # type: ignore from kubernetes.client.exceptions import ApiException
from kubernetes.client.models.v1_deployment import V1Deployment # type: ignore from kubernetes.client.models.v1_deployment import V1Deployment
from kubernetes.client.models.v1_job import V1Job # type: ignore from kubernetes.client.models.v1_job import V1Job
from pydantic import BaseModel from pydantic import BaseModel
from .settings import settings from .settings import settings

View file

@ -4,7 +4,7 @@ import uuid
from enum import Enum from enum import Enum
from typing import Optional from typing import Optional
from kubernetes.client.models.v1_deployment import V1Deployment # type: ignore from kubernetes.client.models.v1_deployment import V1Deployment
from pydantic import BaseModel from pydantic import BaseModel
from . import github, k8s from . import github, k8s

View file

@ -1,4 +1,4 @@
from uvicorn.workers import UvicornWorker # type: ignore from uvicorn.workers import UvicornWorker
from .settings import settings from .settings import settings

View file

@ -1,7 +1,7 @@
from pathlib import Path from pathlib import Path
from typing import Optional from typing import Optional
from fastapi import APIRouter, HTTPException, Request, status from fastapi import APIRouter, HTTPException, Request, Response, status
from fastapi.responses import HTMLResponse, RedirectResponse from fastapi.responses import HTMLResponse, RedirectResponse
from fastapi.templating import Jinja2Templates from fastapi.templating import Jinja2Templates
@ -13,7 +13,7 @@ templates = Jinja2Templates(directory=str(Path(__file__).parent / "webui"))
@router.get("/builds/{name}", response_class=HTMLResponse) @router.get("/builds/{name}", response_class=HTMLResponse)
async def build(request: Request, name: str, live: Optional[str] = None): async def build(request: Request, name: str, live: Optional[str] = None) -> Response:
build = controller.db.get(name) build = controller.db.get(name)
if not build: if not build:
raise HTTPException(status.HTTP_404_NOT_FOUND) raise HTTPException(status.HTTP_404_NOT_FOUND)