This is an automated email from the ASF dual-hosted git repository.

gstein pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/steve.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 2fe46a1  rebuild to run standalone, or under hypercorn/etc
2fe46a1 is described below

commit 2fe46a1d59d46ebb5ed30cecbd68cbd5ce22fb29
Author: Greg Stein <[email protected]>
AuthorDate: Sun Feb 22 23:26:49 2026 -0600

    rebuild to run standalone, or under hypercorn/etc
---
 v3/server/main.py | 79 ++++++++++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 63 insertions(+), 16 deletions(-)

diff --git a/v3/server/main.py b/v3/server/main.py
index 3656fed..b8c0239 100755
--- a/v3/server/main.py
+++ b/v3/server/main.py
@@ -28,21 +28,8 @@ THIS_DIR = pathlib.Path(__file__).resolve().parent
 CERTS_DIR = THIS_DIR / 'certs'
 
 
-def main():
-    logging.basicConfig(
-        level=logging.DEBUG,
-        style='{',
-        format='[{asctime}|{levelname}|{name}] {message}',
-        datefmt=DATE_FORMAT,
-    )
-
-    # Switch some loggers to INFO, rather than DEBUG
-    logging.getLogger('selector_events').setLevel(logging.INFO)
-    logging.getLogger('hpack').setLevel(logging.INFO)
-    logging.getLogger('sslproto').setLevel(logging.INFO)
-    ### above is good, but leaks stuff. This quiets things. too much?
-    ### other way to approach: what in asyncio do we need to observe?
-    logging.getLogger('asyncio').setLevel(logging.INFO)
+def create_app():
+    "Create the asfquart app and its endpoints."
 
     ### is this really needed right now?
     # Avoid OIDC
@@ -60,6 +47,30 @@ def main():
     import pages  # noqa: F401
     import api  # noqa: F401
 
+    return app  # also available as asfquart.APP now
+
+
+def run_standalone():
+    "Run as a standalone server."
+
+    logging.basicConfig(
+        level=logging.DEBUG,
+        style='{',
+        format='[{asctime}|{levelname}|{name}] {message}',
+        datefmt=DATE_FORMAT,
+    )
+
+    # Switch some loggers to INFO, rather than DEBUG
+    logging.getLogger('selector_events').setLevel(logging.INFO)
+    logging.getLogger('hpack').setLevel(logging.INFO)
+    logging.getLogger('sslproto').setLevel(logging.INFO)
+    ### above is good, but leaks stuff. This quiets things. too much?
+    ### other way to approach: what in asyncio do we need to observe?
+    logging.getLogger('asyncio').setLevel(logging.INFO)
+
+    # Set up the STeVe app, then we'll start it up.
+    app = create_app()
+
     # Note: "pages" imports "steve.election". Pull that package into
     # our local namespace.
     steve = sys.modules['steve']
@@ -82,5 +93,41 @@ def main():
     # print(_LOGGER.manager.loggerDict['sslproto'])
 
 
+def run_asgi():
+    "Run as an ASGI process; eg. Hypercorn"
+
+    # NOTE: no-op if Hypercorn has set up the root logger.
+    logging.basicConfig(
+        level=logging.DEBUG,
+        style='{',
+        format='[{asctime}|{levelname}|{name}] {message}',
+        datefmt=DATE_FORMAT,
+    )
+
+    # Make some loggers explicitly INFO, rather than default to DEBUG.
+    logging.getLogger('watchfiles.main').setLevel(logging.INFO)
+
+    # Configure our app's loggers (rather than root logger default).
+    _LOGGER.setLevel(logging.DEBUG)
+
+    # Okay. Time to be a Hypercorn-based ASGI app.
+
+    _LOGGER.info('we must be an ASGI app!')
+
+    global steve_app
+    steve_app = create_app()
+
+
 if __name__ == '__main__':
-    main()
+    # $ ./main.py
+    run_standalone()
+else:
+    # Using Hypercorn:
+    #
+    #   $ uv run python -m hypercorn main:steve_app
+    #
+    # NOTE: without our extended shutdown_trigger, we cannot reload
+    # or restart on .py changes, extra_files changes, or respond to
+    # SIGUSR2 to restart. Hypercorn will respond to SIGTERM/SIGINT
+    # and shutdown.
+    run_asgi()

Reply via email to