Finish strict typing
This commit is contained in:
parent
d80df82173
commit
88e5cb5b44
10 changed files with 47 additions and 19 deletions
7
.github/workflows/ci.yml
vendored
7
.github/workflows/ci.yml
vendored
|
|
@ -16,10 +16,11 @@ jobs:
|
|||
- name: Install project
|
||||
run: |
|
||||
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
|
||||
run: |
|
||||
pytest -v --cov --cov-report=xml ./tests
|
||||
run: pytest -v --cov --cov-report=xml ./tests
|
||||
- name: Run mypy
|
||||
run: mypy ./src/runboat ./tests
|
||||
- uses: codecov/codecov-action@v1
|
||||
build-image:
|
||||
runs-on: ubuntu-latest
|
||||
|
|
|
|||
|
|
@ -39,4 +39,4 @@ repos:
|
|||
rev: v2.29.0
|
||||
hooks:
|
||||
- id: pyupgrade
|
||||
args: ["--py38-plus"]
|
||||
args: ["--py39-plus"]
|
||||
|
|
|
|||
|
|
@ -27,6 +27,9 @@ test = [
|
|||
"pytest-cov",
|
||||
"pytest-dotenv",
|
||||
]
|
||||
mypy = [
|
||||
"mypy",
|
||||
]
|
||||
|
||||
[project.urls]
|
||||
Home = "https://github.com/sbidoul/runboat"
|
||||
|
|
@ -39,3 +42,23 @@ env_override_existing_values = 1
|
|||
env_files = [".env.test"]
|
||||
|
||||
# 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
4
requirements-mypy.txt
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
# frozen requirements generated by pip-deepfreeze
|
||||
mypy==0.910
|
||||
mypy-extensions==0.4.3
|
||||
toml==0.10.2
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
import datetime
|
||||
from typing import Optional
|
||||
|
||||
from ansi2html import Ansi2HTMLConverter # type: ignore
|
||||
from ansi2html import Ansi2HTMLConverter
|
||||
from fastapi import APIRouter, Depends, HTTPException, status
|
||||
from fastapi.responses import HTMLResponse
|
||||
from pydantic import BaseModel
|
||||
|
|
@ -124,24 +124,24 @@ async def build(name: str) -> models.Build:
|
|||
"/builds/{name}/init-log",
|
||||
response_class=HTMLResponse,
|
||||
)
|
||||
async def init_log(name: str):
|
||||
async def init_log(name: str) -> str:
|
||||
build = await _build_by_name(name)
|
||||
log = await build.init_log()
|
||||
if not log:
|
||||
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(
|
||||
"/builds/{name}/log",
|
||||
response_class=HTMLResponse,
|
||||
)
|
||||
async def log(name: str):
|
||||
async def log(name: str) -> str:
|
||||
build = await _build_by_name(name)
|
||||
log = await build.log()
|
||||
if not log:
|
||||
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")
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ class Controller:
|
|||
"""
|
||||
|
||||
db: BuildsDb
|
||||
_tasks: list[asyncio.Task]
|
||||
_tasks: list[asyncio.Task[None]]
|
||||
_wakeup_initializer: asyncio.Event
|
||||
_wakeup_stopper: asyncio.Event
|
||||
_wakeup_undeployer: asyncio.Event
|
||||
|
|
|
|||
|
|
@ -11,12 +11,12 @@ from importlib import resources
|
|||
from pathlib import Path
|
||||
from typing import Any, Callable, Generator, Optional, TypedDict, cast
|
||||
|
||||
import urllib3 # type: ignore
|
||||
import urllib3
|
||||
from jinja2 import Template
|
||||
from kubernetes import client, config, watch # type: ignore
|
||||
from kubernetes.client.exceptions import ApiException # type: ignore
|
||||
from kubernetes.client.models.v1_deployment import V1Deployment # type: ignore
|
||||
from kubernetes.client.models.v1_job import V1Job # type: ignore
|
||||
from kubernetes import client, config, watch
|
||||
from kubernetes.client.exceptions import ApiException
|
||||
from kubernetes.client.models.v1_deployment import V1Deployment
|
||||
from kubernetes.client.models.v1_job import V1Job
|
||||
from pydantic import BaseModel
|
||||
|
||||
from .settings import settings
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import uuid
|
|||
from enum import Enum
|
||||
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 . import github, k8s
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
from uvicorn.workers import UvicornWorker # type: ignore
|
||||
from uvicorn.workers import UvicornWorker
|
||||
|
||||
from .settings import settings
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
from pathlib import Path
|
||||
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.templating import Jinja2Templates
|
||||
|
||||
|
|
@ -13,7 +13,7 @@ templates = Jinja2Templates(directory=str(Path(__file__).parent / "webui"))
|
|||
|
||||
|
||||
@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)
|
||||
if not build:
|
||||
raise HTTPException(status.HTTP_404_NOT_FOUND)
|
||||
|
|
|
|||
Loading…
Reference in a new issue