You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tooling.apache.org by sb...@apache.org on 2025/02/18 12:21:44 UTC
(tooling-atr-experiments) branch main updated (b3d2c88 -> 9c37477)
This is an automated email from the ASF dual-hosted git repository.
sbp pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/tooling-atr-experiments.git
from b3d2c88 remove obsolete files
new 7b6fc35 Reduce the amount of top level code
new 9c37477 Prevent the startup logs from being shown twice
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
atr/server.py | 73 +++++++++++++++++++++++++++++---------------------
atr/static/css/atr.css | 2 +-
2 files changed, 43 insertions(+), 32 deletions(-)
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tooling.apache.org
For additional commands, e-mail: dev-help@tooling.apache.org
(tooling-atr-experiments) 01/02: Reduce the amount of top level code
Posted by sb...@apache.org.
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 <se...@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-unsubscribe@tooling.apache.org
For additional commands, e-mail: dev-help@tooling.apache.org
(tooling-atr-experiments) 02/02: Prevent the startup logs from being shown twice
Posted by sb...@apache.org.
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 9c37477e56b6473432ba85226c693affbda6f2ef
Author: Sean B. Palmer <se...@miscoranda.com>
AuthorDate: Tue Feb 18 14:21:22 2025 +0200
Prevent the startup logs from being shown twice
---
atr/server.py | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/atr/server.py b/atr/server.py
index 00f5ef7..8b4cb8f 100644
--- a/atr/server.py
+++ b/atr/server.py
@@ -103,16 +103,20 @@ def create_app(app_config: type[AppConfig]) -> QuartApp:
async def shutdown() -> None:
app.background_tasks.clear()
+ # Configure logging
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)
+ # Only log in the worker process
+ @app.before_serving
+ async def log_debug_info() -> None:
+ 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
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tooling.apache.org
For additional commands, e-mail: dev-help@tooling.apache.org