Skip to content

Commit 9caed64

Browse files
authored
Merge pull request #476 from JnyJny/features/fix-webapi-extras-optional
Fix CLI to work without webapi extras
2 parents f3a791c + 67772d6 commit 9caed64

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

src/busylight/__main__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from loguru import logger
77

88
from . import __version__
9-
from .busyserve import busyserve_cli
109
from .callbacks import string_to_scaled_color
1110
from .global_options import GlobalOptions
1211
from .manager import LightManager
@@ -18,7 +17,13 @@
1817
for subcommand in subcommands:
1918
cli.add_typer(subcommand)
2019

21-
cli.add_typer(busyserve_cli)
20+
# Conditionally add busyserve CLI if webapi dependencies are available
21+
try:
22+
from .busyserve import busyserve_cli
23+
cli.add_typer(busyserve_cli)
24+
except ImportError:
25+
# webapi extras not installed, skip busyserve functionality
26+
pass
2227

2328
webcli = typer.Typer()
2429

src/busylight/busyserve.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@
55
import typer
66
from loguru import logger
77

8+
# Check if webapi dependencies are available, fail import if not
89
try:
910
import uvicorn
1011
except ImportError as error:
11-
logger.error(f"import uvicorn failed: {error}")
12-
typer.secho(
13-
"The package `uvicorn` is missing, unable to serve the busylight API.",
14-
fg="red",
15-
)
16-
raise typer.Exit(code=1) from None
12+
raise ImportError(
13+
"The package `uvicorn` is missing, unable to serve the busylight API. "
14+
"Install with webapi extras: pip install busylight-for-humans[webapi]"
15+
) from error
1716

1817
busyserve_cli = typer.Typer()
1918

0 commit comments

Comments
 (0)