Skip to content

Commit a0f4057

Browse files
committed
Allow not having a typer.Typer app instance
- Remove "app" from plugins/bill-teams/cli.py for when the necessary dependencies aren't found - Yield "None" for when no "app" is found in cli.py - Only add "app" that is not None to main app in src/elapi/cli/elapi.py
1 parent a9b558c commit a0f4057

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

src/elapi/cli/_plugin_handler.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ def get_typer_apps(self) -> Generator[typer.Typer, None, None]:
3838
) # Python will find module relative to __package__ path,
3939
# without this module.__package__ change Python will throw an ImportError.
4040
spec.loader.exec_module(module)
41-
yield getattr(module, INTERNAL_PLUGIN_TYPER_APP_VAR_NAME)
41+
try:
42+
yield getattr(module, INTERNAL_PLUGIN_TYPER_APP_VAR_NAME)
43+
except AttributeError:
44+
yield
4245

4346

4447
internal_plugin_typer_apps = InternalPluginHandler().get_typer_apps()

src/elapi/cli/elapi.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,13 @@ def cli_startup_for_plugins(
174174

175175

176176
for _app in internal_plugin_typer_apps:
177-
COMMANDS_TO_SKIP_CLI_STARTUP.append(_app.info.name)
178-
app.add_typer(
179-
_app,
180-
rich_help_panel="Plugins",
181-
callback=cli_startup_for_plugins,
182-
)
177+
if _app is not None:
178+
COMMANDS_TO_SKIP_CLI_STARTUP.append(_app.info.name)
179+
app.add_typer(
180+
_app,
181+
rich_help_panel="Plugins",
182+
callback=cli_startup_for_plugins,
183+
)
183184

184185
typer.rich_utils.STYLE_HELPTEXT = (
185186
"" # fixes https://github.com/tiangolo/typer/issues/437

src/elapi/plugins/bill_teams/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
PLUGIN_NAME: str = "bill-teams"
66

77
if not (find_spec("tenacity") and find_spec("dateutil")):
8-
app = typer.Typer()
8+
...
99
else:
1010
from typing import Annotated, Optional
1111

0 commit comments

Comments
 (0)