Skip to content

Commit

Permalink
only load parts of cli if it's relevant to the app
Browse files Browse the repository at this point in the history
  • Loading branch information
niquerio committed Jan 24, 2025
1 parent 125aa4d commit d6282b9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
34 changes: 24 additions & 10 deletions aim/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions aim/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ class Services:
Global Configuration Services
"""

#: The application name
app_name: str

#: The structured logger
logger: structlog.stdlib.BoundLogger

Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit d6282b9

Please sign in to comment.