vertex.cli SourceΒΆ

 1# -- IMPORTS --
 2
 3# -- Standard libraries --
 4import pathlib
 5
 6# -- 3rd party libraries --
 7import click
 8
 9# -- Internal libraries --
10from vertex import __version__  # pragma: no cover
11from vertex.io import (
12    get_project_data,
13    save_insight_panel_visuals,
14    save_public_outputs,
15)
16from vertex.layout.insight_panels import (
17    get_public_visuals,
18)
19from vertex.logging.logger import setup_logger
20
21logger = setup_logger(__name__)
22
23
24@click.group("vertex-cli")
25def vertex_cli(): ...
26
27
28@vertex_cli.command("version", short_help="Displays the current VERTEX (GitHub) release version.")  # pragma: no cover
29def version() -> str:
30    """Displays the current VERTEX (GitHub) release version.
31
32    Returns
33    -------
34    str
35        The latest VERTEX (GitHub) release version.
36    """
37    click.echo(__version__)
38
39
40@vertex_cli.command(
41    "descriptive-analytics",
42    short_help="Exports all project insight panel figures and tables to a local project subfolder (named `output`).",
43)
44@click.option("--project-path", required=True, help="The (absolute or relative) path to the project.")  # pragma: no cover
45def descriptive_analytics(project_path: str) -> None:
46    """Exports all project insight panel figures and tables to a local project subfolder (named `output`).
47
48    Parameters
49    ----------
50    project_path : str
51        The project path as a plain string or :py:class:`pathlib.Path` object.
52
53    """
54    project_path = pathlib.Path(project_path).resolve()
55
56    # 1. Get project data from the project path, which includes buttons,
57    #    insight_panels, df_map, df_countries, df_forms_dict, dictionary,
58    #    quality_report, project_path, config_dict
59    logger.info(f'Loading project data from project path: "{project_path}"')
60    project_data = get_project_data(project_path)
61
62    # 2. Save the public outputs to file (to an outputs subfolder inside
63    #    the project path)
64    project_outputs_path = project_path.joinpath(project_data["config_dict"]["outputs_path"])
65    logger.info(f'Saving public outputs to "{project_outputs_path}"')
66    save_public_outputs(**project_data)
67
68    logger.info(f'Saving all figures to "{project_outputs_path}"')
69    insight_panels, _ = get_public_visuals(project_outputs_path, project_data["buttons"])
70    save_insight_panel_visuals(insight_panels, project_outputs_path, project_outputs_path.joinpath("visuals"))