Coverage for packages / dqm-ml / src / dqm_ml / __main__.py: 92%
40 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-15 10:11 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-15 10:11 +0000
1"""Main CLI entry point for DQM-ML v2.
3This module provides the command-line interface for running DQM-ML
4commands including version display, listing available plugins, and
5processing data quality assessment jobs.
6"""
8import argparse
9from collections.abc import Iterable
10import logging
11from typing import Any
13from typing_extensions import override
15from dqm_ml.cli_tools import CustomFormatter
16from dqm_ml.dependency import get_available_command
18logger = logging.getLogger(__name__)
21class _HelpAction(argparse._HelpAction):
22 """Custom help action to support command-specific help."""
24 @override
25 def __call__(
26 self,
27 parser: argparse.ArgumentParser,
28 namespace: argparse.Namespace,
29 values: str | Iterable[Any] | None,
30 option_string: str | None = None,
31 ) -> None:
32 if namespace.command:
33 # print help for the specific command
34 command_list = get_available_command()
35 if namespace.command in command_list and command_list[namespace.command] is not None:
36 command_list[namespace.command](["-h"])
37 else:
38 raise ValueError(f"Unknown command {namespace.command}")
39 else:
40 parser.print_help()
41 parser.exit()
44def parse_args(arg_list: list[str] | None, command_list: Iterable[str]) -> Any:
45 parser = argparse.ArgumentParser(
46 prog="dqm-ml",
47 description="DQM-ML Job client",
48 epilog="for more informations see README",
49 add_help=False,
50 )
52 parser.add_argument("-h", "--help", action=_HelpAction, help="help for help if you need some help")
54 parser.add_argument("command", choices=command_list, help="Available command for your dqm-ml installation")
56 parser.add_argument("-v", "--verbose", action="store_true")
57 parser.add_argument("-q", "--quiet", action="store_true")
59 cli_args, remaining = parser.parse_known_args(arg_list)
61 return cli_args, remaining
64# TODO get parameters, logs, ...
65def execute(arg_list: list[str] | None = None) -> None:
66 # Exemple of other optional dependencies command
67 # with optional_dependencies(optional_dep_mode):
68 # import dqm_ml_dummy_command.cli
69 # command_list["dqm_ml_dummy_command"] = dqm_ml_dummy_command.cli
70 command_list = get_available_command()
72 args, remaining = parse_args(arg_list, command_list)
74 if args.verbose:
75 CustomFormatter.init_log(format="%(name)s - %(message)s (%(filename)s:%(lineno)d)", level=logging.DEBUG) # noqa: E501
76 elif args.quiet: 76 ↛ 77line 76 didn't jump to line 77 because the condition on line 76 was never true
77 CustomFormatter.init_log(format="%(message)s", level=logging.ERROR)
78 else:
79 CustomFormatter.init_log(format="%(message)s", level=logging.INFO)
81 logger.debug(f"Execution dqm-ml with {arg_list}")
83 if args.command in command_list and command_list[args.command] is not None:
84 command_list[args.command](remaining)
85 else:
86 raise ValueError(f"Unknown command {args.command}")
89if __name__ == "__main__": 89 ↛ 90line 89 didn't jump to line 90 because the condition on line 89 was never true
90 execute()