Skip to content

Conversation

JnyJny
Copy link
Owner

@JnyJny JnyJny commented Aug 9, 2025

Summary

  • Fixes CLI to work without webapi extras installed
  • Resolves uvx --with busylight-for-humans busylight failure
  • Maintains full functionality when webapi extras are installed

Problem

The CLI was failing when used via uvx --with busylight-for-humans busylight because it attempted to import busyserve_cli unconditionally, which depends on uvicorn from the optional [webapi] extras group. This created a hard dependency on webapi components even for basic light control operations.

Solution

Implemented conditional imports and import-time validation:

  1. Conditional CLI registration in __main__.py:

    • Wrapped busyserve_cli import in try/except block
    • Only adds busyserve subcommand when webapi dependencies are available
    • Gracefully degrades when extras are missing
  2. Import-time validation in busyserve.py:

    • Moved dependency check to import time
    • Provides clear error message with installation instructions
    • Prevents module loading when dependencies are missing

Changes Made

/src/busylight/__main__.py

  • Removed unconditional import of busyserve_cli
  • Added conditional import with try/except handling
  • CLI gracefully excludes busyserve functionality when webapi extras unavailable

/src/busylight/busyserve.py

  • Moved uvicorn import check to module level
  • Converted runtime error to ImportError for proper exception handling
  • Enhanced error message with clear installation instructions

Testing

  • ✅ CLI works without webapi extras: uvx --with busylight-for-humans busylight --help
  • ✅ CLI works with webapi extras: full busyserve functionality available
  • ✅ Clear error messages guide users when extras needed
  • ✅ No regression in existing functionality

User Impact

  • Before: CLI failed completely without webapi extras installed
  • After: CLI works for all light control operations; webapi features gracefully unavailable
  • Users get clear guidance on installing extras when attempting to use web functionality
  • Maintains backwards compatibility for existing installations with webapi extras

🤖 Generated with Claude Code

- Conditionally import busyserve_cli in __main__.py
- Fail busyserve import if uvicorn not available (at import time)
- Provides clear error message with installation instructions
- Resolves 'uvx --with busylight-for-humans busylight' failure

This allows the base CLI to work without [webapi] extras while still
providing the serve command when extras are installed.

Fixes:
- CLI loads successfully without webapi dependencies
- 'serve' command only appears when webapi extras are installed
- Clear error messages guide users to install extras when needed
@JnyJny
Copy link
Owner Author

JnyJny commented Aug 9, 2025

LGTM.

@JnyJny JnyJny merged commit 9caed64 into master Aug 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant