def write_datatype_py(outdir, node):
    """
    Build datatype (graph_objs) class source code and write to a file

    Parameters
    ----------
    outdir :
        Root outdir in which the graph_objs package should reside
    node :
        The datatype node (node.is_datatype must evaluate to true) for which
        to build the datatype class

    Returns
    -------
    None
    """

    # Build file path
    # ---------------
    # filepath = opath.join(outdir, "graph_objs", *node.parent_path_parts, "__init__.py")
    filepath = opath.join(outdir, "graph_objs", *node.parent_path_parts,
                          "_" + node.name_undercase + ".py")

    # Generate source code
    # --------------------
    datatype_source = build_datatype_py(node)

    # Write file
    # ----------
    write_source_py(datatype_source, filepath, leading_newlines=2)
示例#2
0
def write_figure_classes(outdir, trace_node, data_validator, layout_validator,
                         frame_validator, subplot_nodes):
    """
    Construct source code for the Figure and FigureWidget classes and
    write to graph_objs/_figure.py and graph_objs/_figurewidget.py
    respectively

    Parameters
    ----------
    outdir : str
        Root outdir in which the graph_objs package should reside
    trace_node : PlotlyNode
        Root trace node (the node that is the parent of all of the
        individual trace nodes like bar, scatter, etc.)
    data_validator : BaseDataValidator
        DataValidator instance
    layout_validator : CompoundValidator
        LayoutValidator instance
    frame_validator : CompoundArrayValidator
        FrameValidator instance
    subplot_nodes: list of str
        List of names of all of the layout subplot properties

    Returns
    -------
    None
    """

    # Validate inputs
    # ---------------
    if trace_node.node_path:
        raise ValueError(f"Expected root trace node.\n"
                         f'Received node with path "{trace_node.path_str}"')

    # Loop over figure types
    # ----------------------
    base_figures = [
        ("basewidget", "BaseFigureWidget", "FigureWidget"),
        ("basedatatypes", "BaseFigure", "Figure"),
    ]

    for base_package, base_classname, fig_classname in base_figures:

        # ### Build figure source code string ###
        figure_source = build_figure_py(
            trace_node,
            base_package,
            base_classname,
            fig_classname,
            data_validator,
            layout_validator,
            frame_validator,
            subplot_nodes,
        )

        # ### Format and write to file###
        filepath = opath.join(outdir, "graph_objs",
                              f"_{fig_classname.lower()}.py")
        write_source_py(figure_source, filepath)
示例#3
0
def write_deprecated_datatypes(outdir):
    """
    Build source code for deprecated datatype class definitions and write
    them to a file

    Parameters
    ----------
    outdir :
        Root outdir in which the graph_objs package should reside

    Returns
    -------
    None
    """
    # Generate source code
    # --------------------
    datatype_source = build_deprecated_datatypes_py()
    filepath = opath.join(outdir, "graph_objs", "_deprecations.py")

    # Write file
    # ----------
    write_source_py(datatype_source, filepath)