From d6282b90bb992f58856bf97cb55f87b172d6d3dd Mon Sep 17 00:00:00 2001 From: Monique Rio Date: Fri, 24 Jan 2025 18:52:15 +0000 Subject: [PATCH] only load parts of cli if it's relevant to the app --- aim/cli/main.py | 34 ++++++++++++++++++++++++---------- aim/services.py | 4 ++++ 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/aim/cli/main.py b/aim/cli/main.py index 8d51016..855a5a8 100644 --- a/aim/cli/main.py +++ b/aim/cli/main.py @@ -5,18 +5,32 @@ """ import typer -import aim.cli.digifeeds as digifeeds -import aim.cli.hathifiles as hathifiles +from aim.services import S + + +def should_load(app_name: str): + return S.app_name == "aim" or S.app_name == app_name + app = typer.Typer() -app.add_typer( - digifeeds.app, name="digifeeds", help="Commands related to the digifeeds process" -) -app.add_typer( - hathifiles.app, - name="hathifiles", - help="Commands related to the hathifiles database", -) +if should_load("digifeeds"): + import aim.cli.digifeeds as digifeeds + + app.add_typer( + digifeeds.app, + name="digifeeds", + help="Commands related to the digifeeds process", + ) + + +if should_load("hathifiles"): + import aim.cli.hathifiles as hathifiles + + app.add_typer( + hathifiles.app, + name="hathifiles", + help="Commands related to the hathifiles database", + ) if __name__ == "__main__": # pragma: no cover diff --git a/aim/services.py b/aim/services.py index 6fca556..c293758 100644 --- a/aim/services.py +++ b/aim/services.py @@ -39,6 +39,9 @@ class Services: Global Configuration Services """ + #: The application name + app_name: str + #: The structured logger logger: structlog.stdlib.BoundLogger @@ -97,6 +100,7 @@ class Services: S = Services( + app_name=os.getenv("APP_NAME") or "aim", logger=structlog.get_logger(), mysql_database=sa.engine.URL.create( drivername="mysql+mysqldb",