Source code for mendevi.plot.printer

#!/usr/bin/env python3

"""Generate a Python code that allows you to plot the graph."""

import ast
import datetime
import itertools
import logging
import pathlib

from .axis import get_label_extractor
from .extract import SqlLinker


[docs] def printer(**kwargs) -> str: """Create an excecutable python code. Parameters ---------- database : pathlib.Path The database path. x, y : tuple[str] The name of the var along each axis. """ # create code code: list[str] = [] code.extend(print_header()) code.extend(print_import()) code.extend(print_cst(**kwargs)) if kwargs["filter"] is not None: code.extend(print_selector(**kwargs)) code.extend(print_read_sql(**kwargs)) code.extend(print_fill_axe(**kwargs)) code.extend(print_main(**kwargs)) code.extend(print_entry()) code = "\n".join(code) # format code try: import black except ImportError: logging.warning("failed to import black, please install it (uv pip install black)") else: code = black.format_str(code, mode=black.FileMode(line_length=100)) return code
[docs] def print_entry() -> list[str]: """Return the code of the entry point.""" return [ 'if __name__ == "__main__":', " values: dict[str] = read_sql(DATABASE)", " main(values)", "", ]