This is an automated email from the ASF dual-hosted git repository. sbp pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/tooling-atr-experiments.git
commit 7b6fc354db57c3a687cea402abc5ea33c2852561 Author: Sean B. Palmer <s...@miscoranda.com> AuthorDate: Tue Feb 18 14:16:29 2025 +0200 Reduce the amount of top level code --- atr/server.py | 69 +++++++++++++++++++++++++++----------------------- atr/static/css/atr.css | 2 +- 2 files changed, 39 insertions(+), 32 deletions(-) diff --git a/atr/server.py b/atr/server.py index 2203d78..00f5ef7 100644 --- a/atr/server.py +++ b/atr/server.py @@ -33,10 +33,17 @@ from atr.blueprints import register_blueprints from atr.config import AppConfig, config_dict from atr.db import create_database +# WARNING: Don't run with debug turned on in production! +DEBUG: bool = config("DEBUG", default=True, cast=bool) +# Determine which configuration to use +config_mode = "Debug" if DEBUG else "Production" + # Avoid OIDC asfquart.generics.OAUTH_URL_INIT = "https://oauth.apache.org/auth?state=%s&redirect_uri=%s" asfquart.generics.OAUTH_URL_CALLBACK = "https://oauth.apache.org/token?code=%s" +app: QuartApp | None = None + class ApiOnlyOpenAPIProvider(OpenAPIProvider): def generate_rules(self) -> Iterable[Rule]: @@ -52,7 +59,23 @@ def register_routes() -> str: return routes.__name__ +def create_config() -> type[AppConfig]: + try: + app_config = config_dict[config_mode] + except KeyError: + exit("Error: Invalid <config_mode>. Expected values [Debug, Production] ") + + return app_config + + def create_app(app_config: type[AppConfig]) -> QuartApp: + if not os.path.isdir(app_config.STATE_DIR): + raise RuntimeError(f"State directory not found: {app_config.STATE_DIR}") + os.chdir(app_config.STATE_DIR) + print(f"Working directory changed to: {os.getcwd()}") + + os.makedirs(app_config.RELEASE_STORAGE_DIR, exist_ok=True) + if asfquart.construct is ...: raise ValueError("asfquart.construct is not set") app = asfquart.construct(__name__) @@ -80,45 +103,29 @@ def create_app(app_config: type[AppConfig]) -> QuartApp: async def shutdown() -> None: app.background_tasks.clear() - return app - - -# WARNING: Don't run with debug turned on in production! -DEBUG: bool = config("DEBUG", default=True, cast=bool) - -# Determine which configuration to use -config_mode = "Debug" if DEBUG else "Production" - -try: - app_config = config_dict[config_mode] -except KeyError: - exit("Error: Invalid <config_mode>. Expected values [Debug, Production] ") - -if not os.path.isdir(app_config.STATE_DIR): - raise RuntimeError(f"State directory not found: {app_config.STATE_DIR}") -os.chdir(app_config.STATE_DIR) -print(f"Working directory changed to: {os.getcwd()}") - -os.makedirs(app_config.RELEASE_STORAGE_DIR, exist_ok=True) - -app = create_app(app_config) + logging.basicConfig( + format="[%(asctime)s.%(msecs)03d ] [%(process)d] [%(levelname)s] %(message)s", + level=logging.INFO, + datefmt="%Y-%m-%d %H:%M:%S", + ) -logging.basicConfig( - format="[%(asctime)s.%(msecs)03d ] [%(process)d] [%(levelname)s] %(message)s", - level=logging.INFO, - datefmt="%Y-%m-%d %H:%M:%S", -) + if DEBUG: + app.logger.info("DEBUG = " + str(DEBUG)) + app.logger.info("ENVIRONMENT = " + config_mode) + app.logger.info("STATE_DIR = " + app_config.STATE_DIR) -if DEBUG: - app.logger.info("DEBUG = " + str(DEBUG)) - app.logger.info("ENVIRONMENT = " + config_mode) - app.logger.info("STATE_DIR = " + app_config.STATE_DIR) + return app def main() -> None: """Quart debug server""" + global app + if app is None: + app = create_app(create_config()) app.run(port=8080, ssl_keyfile="key.pem", ssl_certfile="cert.pem") if __name__ == "__main__": main() +else: + app = create_app(create_config()) diff --git a/atr/static/css/atr.css b/atr/static/css/atr.css index c0e81ae..45d220f 100644 --- a/atr/static/css/atr.css +++ b/atr/static/css/atr.css @@ -35,7 +35,7 @@ input, textarea, button, select, option { font-weight: 425; } -a { font-weight: 475; } +a { font-weight: 450; } h1, h2, h3 { font-weight: 475; --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tooling.apache.org For additional commands, e-mail: dev-h...@tooling.apache.org