readmes added comments and some links to the openapi docs mds :)
All checks were successful
checks-impure / test (pull_request) Successful in 29s
checks / test (pull_request) Successful in 3m29s

This commit is contained in:
Georg-Stahn
2024-01-16 22:25:05 +01:00
parent 01e98d363b
commit 3052015a51
15 changed files with 215 additions and 97 deletions

View File

@@ -2,25 +2,55 @@ import argparse
import logging
from typing import Callable, NoReturn, Optional
# Get the logger for this module
log = logging.getLogger(__name__)
# Initialize variables for server startup and potential ImportError
start_server: Optional[Callable] = None
ServerImportError: Optional[ImportError] = None
# Try importing the start_server function from the server module
try:
from .server import start_server
except ImportError as e:
# If ImportError occurs, log the exception and store it in ServerImportError
log.exception(e)
ServerImportError = e
# Function to be called when FastAPI is not installed
##########################################################################################
# usage: clan webui [-h] [--port PORT] [--host HOST] [--populate] [--emulate] [--no-open] [--dev]
# [--dev-port DEV_PORT] [--dev-host DEV_HOST] [--reload]
# [--log-level {critical,error,warning,info,debug,trace}]
# [sub_url]
#
# positional arguments:
# sub_url Sub URL to open in the browser
#
# options:
# -h, --help show this help message and exit
# --port PORT Port to listen on
# --host HOST Host to listen on
# --populate Populate the database with dummy data
# --emulate Emulate two entities c1 and c2 + dlg and ap
# --no-open Don't open the browser
# --dev Run in development mode
# --dev-port DEV_PORT Port to listen on for the dev server
# --dev-host DEV_HOST Host to listen on
# --reload Don't reload on changes
# --log-level {critical,error,warning,info,debug,trace}
# Log level
##########################################################################################
def fastapi_is_not_installed(_: argparse.Namespace) -> NoReturn:
assert ServerImportError is not None
print(
f"Dependencies for the webserver is not installed. The webui command has been disabled ({ServerImportError})"
f"Dependencies for the webserver are not installed. The webui command has been disabled ({ServerImportError})"
)
exit(1)
# Function to register command-line arguments for the webserver
def register_parser(parser: argparse.ArgumentParser) -> None:
parser.add_argument("--port", type=int, default=2979, help="Port to listen on")
parser.add_argument(
@@ -69,10 +99,10 @@ def register_parser(parser: argparse.ArgumentParser) -> None:
type=str,
default="/",
nargs="?",
help="Sub url to open in the browser",
help="Sub URL to open in the browser",
)
# Set the args.func variable in args
# Set the args.func variable in args based on whether FastAPI is installed
if start_server is None:
parser.set_defaults(func=fastapi_is_not_installed)
else: