Coverage for src / rhiza / __main__.py: 100%

17 statements  

« prev     ^ index     » next       coverage.py v7.14.0, created at 2026-07-16 12:51 +0000

1"""Rhiza module entry point. 

2 

3This module allows running the Rhiza CLI with `python -m rhiza` by 

4delegating execution to the Typer application defined in `rhiza.cli`. 

5""" 

6 

7from importlib.metadata import entry_points 

8 

9import typer 

10from loguru import logger 

11 

12from rhiza.cli import app 

13 

14 

15def load_plugins(app: typer.Typer) -> None: 

16 """Load plugins from entry points.""" 

17 # Any installed package that registers a `rhiza.plugins` entry point is 

18 # mounted as a subcommand. 

19 plugin_entries = entry_points(group="rhiza.plugins") 

20 

21 for entry in plugin_entries: 

22 try: 

23 plugin_app = entry.load() 

24 # This adds the plugin as a subcommand, e.g., 'rhiza <plugin>' 

25 app.add_typer(plugin_app, name=entry.name) 

26 except Exception as e: # noqa: BLE001 # third-party plugin code may raise anything; a broken plugin must not crash the CLI 

27 logger.warning(f"Failed to load plugin {entry.name}: {e}") 

28 

29 

30def main() -> None: 

31 """Console-script entry point: load plugins, then run the CLI. 

32 

33 Used by both the ``rhiza`` console script (``project.scripts``) and 

34 ``python -m rhiza`` so that entry-point plugins load identically for 

35 either invocation. 

36 """ 

37 load_plugins(app) 

38 app() 

39 

40 

41if __name__ == "__main__": 

42 main()