From 74246ab6222cffb7bb2827ab9a3b26e9920b217a Mon Sep 17 00:00:00 2001 From: kkaris Date: Tue, 30 Apr 2024 15:06:20 -0700 Subject: [PATCH 1/6] MWE for how to set up app to be runnable with gunicorn --- gilda/app/app.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/gilda/app/app.py b/gilda/app/app.py index ba16192..323fac6 100644 --- a/gilda/app/app.py +++ b/gilda/app/app.py @@ -298,3 +298,10 @@ def _mount_home_redirect(app): def home_redirect(): """Redirect the home url to the API documentation.""" return redirect("/apidocs") + + +if __name__ == '__main__': + app = get_app() + app.run() +else: + gunicorn_app = get_app() From 714a5a1b2ecfb1c8f3414388680f439d87ae4247 Mon Sep 17 00:00:00 2001 From: kkaris Date: Tue, 30 Apr 2024 15:20:17 -0700 Subject: [PATCH 2/6] Run app from app/__main__.py instead of app/app.py --- gilda/app/__init__.py | 13 ++++++++++--- gilda/app/__main__.py | 7 +++++-- gilda/app/app.py | 7 ------- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/gilda/app/__init__.py b/gilda/app/__init__.py index 9d460c5..35dc128 100644 --- a/gilda/app/__init__.py +++ b/gilda/app/__init__.py @@ -2,12 +2,19 @@ from .app import get_app -def main(): +def parse_args(): parser = argparse.ArgumentParser( description='Run the grounding app.') parser.add_argument('--host', default='0.0.0.0') parser.add_argument('--port', default=8001, type=int) parser.add_argument('--terms') args = parser.parse_args() - app = get_app(terms=args.terms) - app.run(host=args.host, port=args.port, threaded=False) + return args + + +if __name__ == '__main__': + _args = parse_args() + app = get_app(_args.terms) + app.run(_args.host, _args.port, threaded=False) +else: + gunicorn_app = get_app() diff --git a/gilda/app/__main__.py b/gilda/app/__main__.py index daf5509..828077d 100644 --- a/gilda/app/__main__.py +++ b/gilda/app/__main__.py @@ -1,5 +1,8 @@ -from . import main +from .app import get_app +from . import parse_args if __name__ == '__main__': - main() + args = parse_args() + app = get_app(args.terms) + app.run(args.host, args.port, threaded=False) diff --git a/gilda/app/app.py b/gilda/app/app.py index 323fac6..ba16192 100644 --- a/gilda/app/app.py +++ b/gilda/app/app.py @@ -298,10 +298,3 @@ def _mount_home_redirect(app): def home_redirect(): """Redirect the home url to the API documentation.""" return redirect("/apidocs") - - -if __name__ == '__main__': - app = get_app() - app.run() -else: - gunicorn_app = get_app() From c1bbe419836b3955e1e6ca5c4f3e1c37518270fa Mon Sep 17 00:00:00 2001 From: kkaris Date: Tue, 30 Apr 2024 15:24:43 -0700 Subject: [PATCH 3/6] Add file docstrings describing execution --- gilda/app/__init__.py | 10 ++++++++++ gilda/app/__main__.py | 6 ++++++ 2 files changed, 16 insertions(+) diff --git a/gilda/app/__init__.py b/gilda/app/__init__.py index 35dc128..b536110 100644 --- a/gilda/app/__init__.py +++ b/gilda/app/__init__.py @@ -1,3 +1,13 @@ +""" +Run the grounding app. + +Run as module: + `python -m gilda.app --host --port --terms ` + +Run with gunicorn: + `gunicorn -w -b : -t gilda.app:gunicorn_app` +""" + import argparse from .app import get_app diff --git a/gilda/app/__main__.py b/gilda/app/__main__.py index 828077d..305508a 100644 --- a/gilda/app/__main__.py +++ b/gilda/app/__main__.py @@ -1,3 +1,9 @@ +""" +Runs the Gilda grounding app as a module. Usage: + + `python -m gilda.app --host --port --terms ` +""" + from .app import get_app from . import parse_args From 9488fd7e97c8988f3ef8a5b88d6d5adeada003fc Mon Sep 17 00:00:00 2001 From: kkaris Date: Tue, 30 Apr 2024 15:28:04 -0700 Subject: [PATCH 4/6] Look for terms file in environment for gunicorn use case --- gilda/app/__init__.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/gilda/app/__init__.py b/gilda/app/__init__.py index b536110..1ecdc41 100644 --- a/gilda/app/__init__.py +++ b/gilda/app/__init__.py @@ -6,6 +6,9 @@ Run with gunicorn: `gunicorn -w -b : -t gilda.app:gunicorn_app` + +For this use case, set the `GILDA_TERMS` environment variable to the path to the +terms file. """ import argparse @@ -27,4 +30,7 @@ def parse_args(): app = get_app(_args.terms) app.run(_args.host, _args.port, threaded=False) else: - gunicorn_app = get_app() + # Assume the terms file is set in the environment + import os + terms = os.environ.get('GILDA_TERMS') + gunicorn_app = get_app(terms=terms) From 66591c651f04640ad8be9e21f3027bc4d2a20581 Mon Sep 17 00:00:00 2001 From: Ben Gyori Date: Tue, 30 Apr 2024 21:09:01 -0400 Subject: [PATCH 5/6] Eliminate redundancy between init and main --- gilda/app/__init__.py | 29 ++++++----------------------- gilda/app/__main__.py | 12 +++++++++++- 2 files changed, 17 insertions(+), 24 deletions(-) diff --git a/gilda/app/__init__.py b/gilda/app/__init__.py index 1ecdc41..9070317 100644 --- a/gilda/app/__init__.py +++ b/gilda/app/__init__.py @@ -5,32 +5,15 @@ `python -m gilda.app --host --port --terms ` Run with gunicorn: - `gunicorn -w -b : -t gilda.app:gunicorn_app` + `gunicorn -w -b : -t gilda.app:gilda_app` -For this use case, set the `GILDA_TERMS` environment variable to the path to the -terms file. +In case a non-standard set of terms is to be used, set the `GILDA_TERMS` +environment variable to the path to the terms file. """ -import argparse +import os from .app import get_app -def parse_args(): - parser = argparse.ArgumentParser( - description='Run the grounding app.') - parser.add_argument('--host', default='0.0.0.0') - parser.add_argument('--port', default=8001, type=int) - parser.add_argument('--terms') - args = parser.parse_args() - return args - - -if __name__ == '__main__': - _args = parse_args() - app = get_app(_args.terms) - app.run(_args.host, _args.port, threaded=False) -else: - # Assume the terms file is set in the environment - import os - terms = os.environ.get('GILDA_TERMS') - gunicorn_app = get_app(terms=terms) +terms = os.environ.get('GILDA_TERMS') +gilda_app = get_app(terms=terms) diff --git a/gilda/app/__main__.py b/gilda/app/__main__.py index 305508a..2189db3 100644 --- a/gilda/app/__main__.py +++ b/gilda/app/__main__.py @@ -4,8 +4,18 @@ `python -m gilda.app --host --port --terms ` """ +import argparse from .app import get_app -from . import parse_args + + +def parse_args(): + parser = argparse.ArgumentParser( + description='Run the grounding app.') + parser.add_argument('--host', default='0.0.0.0') + parser.add_argument('--port', default=8001, type=int) + parser.add_argument('--terms') + args = parser.parse_args() + return args if __name__ == '__main__': From 5f317f07a35aecc29f8a52ade570348f4e221c4a Mon Sep 17 00:00:00 2001 From: Ben Gyori Date: Tue, 30 Apr 2024 21:11:54 -0400 Subject: [PATCH 6/6] Update footer --- gilda/app/templates/base.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gilda/app/templates/base.html b/gilda/app/templates/base.html index d934d8d..91ced17 100644 --- a/gilda/app/templates/base.html +++ b/gilda/app/templates/base.html @@ -38,8 +38,8 @@

Gilda Grounding Service

Gilda is developed by the Gyori Lab for Computational Biomedicine at Northeastern University. - Its development was funded by DARPA grants W911NF-15-1-0544 and - W911NF-20-1-0255. + Its development is funded by DARPA grants W911NF-15-1-0544, + W911NF-20-1-0255, and HR00112220036. Point of contact: Benjamin M. Gyori.