Skip to content

Commit

Permalink
Document server (#112)
Browse files Browse the repository at this point in the history
* Rename app to apps

* Typehint files in / and /utils

* Add mypy (still finicky)

* Fix mypy pre-commit hook, remove unused/obsolete files, minor type hint fixes/ignore import fixes

* Fix mypy issues

* Add pre-commit.ci configuration, remove black workflow
  • Loading branch information
krishnans2006 authored Nov 11, 2022
1 parent ec3915f commit 1852d64
Show file tree
Hide file tree
Showing 21 changed files with 140 additions and 193 deletions.
13 changes: 0 additions & 13 deletions .github/workflows/black.yml

This file was deleted.

36 changes: 0 additions & 36 deletions TCP_client_image.py

This file was deleted.

37 changes: 0 additions & 37 deletions TCP_server_image.py

This file was deleted.

2 changes: 1 addition & 1 deletion client/public/slippy_map_getter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import math
import os
import requests
import requests # type: ignore[import]
import time

# window position and zoom for the auvsi suas base, webster field
Expand Down
12 changes: 11 additions & 1 deletion server/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,14 @@ repos:
args: [-l, '99']
language_version: python3.10
verbose: true
exclude: .*auvsi_suas.*
exclude: ^server/auvsi_suas.*
- repo: https://github.com/pre-commit/mirrors-mypy
rev: ''
hooks:
- id: mypy
exclude: ^(server/auvsi_suas.*|server/utils/(params|decorators).py)$
verbose: true
args: ["--ignore-missing-imports", "--show-error-codes", "--follow-imports", "skip"]

ci:
autofix_prs: false
43 changes: 22 additions & 21 deletions server/app.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import json
import logging
import traceback
from typing import Type

from flask import Flask, jsonify, send_file
from flask import Flask, jsonify, send_file, Response
from flask_cors import CORS

from app import interop, uav, ugv
from apps import interop, uav, ugv
from groundstation import GroundStation
from utils.errors import (
InvalidRequestError,
Expand All @@ -15,29 +16,29 @@
)
from utils.logging_setup import LOG_STREAM, TELEM_STREAM

log = logging.getLogger("werkzeug")
log: logging.Logger = logging.getLogger("werkzeug")
log.setLevel(logging.ERROR)

with open("config.json", "r", encoding="utf-8") as file:
config = json.load(file)
config: dict = json.load(file)

app = Flask(__name__)
app: Flask = Flask(__name__)
app.config["JSONIFY_PRETTYPRINT_REGULAR"] = True
CORS(app)

app.register_blueprint(interop, url_prefix="/interop")
app.register_blueprint(uav, url_prefix="/uav")
app.register_blueprint(ugv, url_prefix="/ugv")

logger = logging.getLogger("groundstation")
logger: logging.Logger = logging.getLogger("groundstation")

gs = GroundStation(config=config)
gs: GroundStation = GroundStation(config=config)
app.gs = gs
app.gs_config = config


@app.errorhandler(Exception)
def handle_error(e):
def handle_error(e: Exception) -> tuple[Response, int]:
logger.error(type(e).__name__)
logger.info("Traceback of %s : ", type(e).__name__, exc_info=e)
return (
Expand All @@ -54,7 +55,7 @@ def handle_error(e):


@app.errorhandler(InvalidRequestError)
def handle_400(e):
def handle_400(e: InvalidRequestError) -> tuple[Response, int]:
logger.error(type(e).__name__)
logger.info("Traceback of %s : ", type(e).__name__, exc_info=e)
return (
Expand All @@ -71,7 +72,7 @@ def handle_400(e):


@app.errorhandler(InvalidStateError)
def handle_409(e):
def handle_409(e: InvalidStateError) -> tuple[Response, int]:
logger.error(type(e).__name__)
logger.info("Traceback of %s : ", type(e).__name__, exc_info=e)
return (
Expand All @@ -88,7 +89,7 @@ def handle_409(e):


@app.errorhandler(GeneralError)
def handle_500(e):
def handle_500(e: GeneralError) -> tuple[Response, int]:
logger.error(type(e).__name__)
logger.info("Traceback of %s : ", type(e).__name__, exc_info=e)
return (
Expand All @@ -105,7 +106,7 @@ def handle_500(e):


@app.errorhandler(ServiceUnavailableError)
def handle_503(e):
def handle_503(e: ServiceUnavailableError) -> tuple[Response, int]:
logger.error(type(e).__name__)
logger.info("Traceback of %s : ", type(e).__name__, exc_info=e)
return (
Expand All @@ -122,20 +123,20 @@ def handle_503(e):


@app.route("/")
def index():
def index() -> str:
return "TJ UAV Ground Station Backend homepage"


@app.route("/log/<string:type_>")
def create_log(type_):
def create_log(type_: str) -> str:
if type_ == "debug":
logger.debug("This is for debugging")
elif type_ == "info":
logger.info("This is info")
elif type_ == "warning":
logger.warning("This is a warning")
elif type_ == "important":
logger.important("This is important")
logger.important("This is important") # type: ignore[attr-defined]
elif type_ == "error":
logger.error("This is an error")
elif type_ == "critical":
Expand All @@ -146,32 +147,32 @@ def create_log(type_):


@app.route("/favicon.ico")
def favicon():
def favicon() -> str:
return ""


@app.route("/logs")
def logs():
def logs() -> dict:
return {"result": LOG_STREAM.getvalue().split("\n")}


@app.route("/telemetry")
def telemetry_data():
def telemetry_data() -> dict:
return {"result": TELEM_STREAM.getvalue().split("\n")}


@app.route("/file/infolog")
def logfile():
def logfile() -> Response:
return send_file("logs/info.log")


@app.route("/file/debuglog")
def debuglogfile():
def debuglogfile() -> Response:
return send_file("logs/debug.log")


@app.route("/file/telemlog")
def telemlogfile():
def telemlogfile() -> Response:
return send_file("logs/telem.log")


Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 1852d64

Please sign in to comment.