Coverage for src/backoffice/_cli.py: 0%

28 statements  

« prev     ^ index     » next       coverage.py v7.15.4, created at 2026-08-13 03:07 +0000

1from __future__ import annotations 

2 

3import sys 

4 

5from pydantic import BaseModel 

6from pydantic_settings import BaseSettings, CliSubCommand 

7 

8from ._summarize import summarize_reports, summarize_reports_parallel 

9from .index import create_index 

10 

11 

12class CmdBase(BaseModel, use_attribute_docstrings=True, cli_implicit_flags=True): 

13 pass 

14 

15 

16class IndexCmd(CmdBase): 

17 def run(self): 

18 """Index the bioimage.io collection""" 

19 _ = create_index() 

20 

21 

22class SummarizeCmd(CmdBase): 

23 max_workers: int | None = None 

24 """Maximum number of worker threads to use for parallel processing.""" 

25 

26 def run(self): 

27 """Conflate tool summaries""" 

28 if self.max_workers == 0: 

29 summarize_reports() 

30 else: 

31 summarize_reports_parallel(max_workers=self.max_workers) 

32 

33 

34class Backoffice( 

35 BaseSettings, 

36 cli_implicit_flags=True, 

37 cli_parse_args=True, 

38 cli_kebab_case=True, 

39 cli_prog_name="backoffice", 

40 cli_use_class_docs_for_groups=True, 

41 use_attribute_docstrings=True, 

42): 

43 """backoffice - manage the bioimage.io collection""" 

44 

45 index: CliSubCommand[IndexCmd] 

46 """index the bioimage.io collection""" 

47 

48 summarize: CliSubCommand[SummarizeCmd] 

49 """conflate tool summaries""" 

50 

51 def run(self): 

52 cmd = self.index or self.summarize 

53 if cmd is None: 

54 raise ValueError( 

55 "No command specified. Use 'backoffice --help' to see available commands." 

56 ) 

57 else: 

58 sys.exit(cmd.run())