Beispiel #1
0
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')

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

    # Write file
    # ----------

    format_and_write_source_py(datatype_source, filepath, leading_newlines=2)
Beispiel #2
0
def write_data_validator_py(outdir, base_trace_node: TraceNode):
    """
    Construct and write out the DataValidator
    (this is the validator that inputs a list of traces)

    Parameters
    ----------
    outdir : str
        Root outdir in which the top-level validators package should reside
    base_trace_node : PlotlyNode
        PlotlyNode that is the parent of all of the individual trace nodes
    Returns
    -------
    None
    """
    # Validate inputs
    # ---------------
    if base_trace_node.node_path:
        raise ValueError('Expected root trace node.\n'
                         'Received node with path "%s"' %
                         base_trace_node.path_str)

    # Build Source
    # ------------
    source = build_data_validator_py(base_trace_node)

    # Write file
    # ----------
    filepath = opath.join(outdir, 'validators', '_data.py')
    format_and_write_source_py(source, filepath)
Beispiel #3
0
def write_validator_py(outdir, node: PlotlyNode):
    """
    Build validator source code and write to a file

    Parameters
    ----------
    outdir : str
        Root outdir in which the validators package should reside
    node : PlotlyNode
        The datatype node (node.is_datatype must evaluate to true) for which
        to build a validator class
    Returns
    -------
    None
    """
    # Generate source code
    # --------------------
    validator_source = build_validator_py(node)

    # Write file
    # ----------
    filepath = opath.join(outdir, 'validators', *node.parent_path_parts,
                          '_' + node.name_property + '.py')

    format_and_write_source_py(validator_source, filepath)
Beispiel #4
0
def write_validator_py(outdir,
                       node: PlotlyNode):
    """
    Build validator source code and write to a file

    Parameters
    ----------
    outdir : str
        Root outdir in which the validators package should reside
    node : PlotlyNode
        The datatype node (node.is_datatype must evaluate to true) for which
        to build a validator class
    Returns
    -------
    None
    """
    if node.is_mapped:
        # No validator written for mapped nodes
        # e.g. no validator for layout.titlefont since ths is mapped to
        # layout.title.font
        return

    # Generate source code
    # --------------------
    validator_source = build_validator_py(node)

    # Write file
    # ----------
    filepath = opath.join(outdir, 'validators',
                          *node.parent_path_parts,
                          '_' + node.name_property + '.py')

    format_and_write_source_py(validator_source, filepath)
Beispiel #5
0
def write_data_validator_py(outdir, base_trace_node: TraceNode):
    """
    Construct and write out the DataValidator
    (this is the validator that inputs a list of traces)

    Parameters
    ----------
    outdir : str
        Root outdir in which the top-level validators package should reside
    base_trace_node : PlotlyNode
        PlotlyNode that is the parent of all of the individual trace nodes
    Returns
    -------
    None
    """
    # Validate inputs
    # ---------------
    if base_trace_node.node_path:
        raise ValueError('Expected root trace node.\n'
                         'Received node with path "%s"'
                         % base_trace_node.path_str)

    # Build Source
    # ------------
    source = build_data_validator_py(base_trace_node)

    # Write file
    # ----------
    filepath = opath.join(outdir, 'validators', '_data.py')
    format_and_write_source_py(source, filepath)
Beispiel #6
0
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
    """
    # Generate source code
    # --------------------
    datatype_source = build_datatype_py(node)

    # Write file
    # ----------
    filepath = opath.join(outdir, 'graph_objs',
                          *node.parent_path_parts,
                          '_' + node.name_undercase + '.py')
    format_and_write_source_py(datatype_source, filepath)
Beispiel #7
0
def write_validator_py(outdir, node: PlotlyNode):
    """
    Build validator source code and write to a file

    Parameters
    ----------
    outdir : str
        Root outdir in which the validators package should reside
    node : PlotlyNode
        The datatype node (node.is_datatype must evaluate to true) for which
        to build a validator class
    Returns
    -------
    None
    """
    if node.is_mapped:
        # No validator written for mapped nodes
        # e.g. no validator for layout.titlefont since ths is mapped to
        # layout.title.font
        return

    # Generate source code
    # --------------------
    validator_source = build_validator_py(node)

    # Write file
    # ----------
    filepath = opath.join(outdir, 'validators', *node.parent_path_parts,
                          '__init__.py')

    format_and_write_source_py(validator_source, filepath, leading_newlines=2)
Beispiel #8
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')
        format_and_write_source_py(figure_source, filepath)
Beispiel #9
0
def write_figure_classes(outdir, trace_node,
                         data_validator,
                         layout_validator,
                         frame_validator):
    """
    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

    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)

        # ### Format and write to file###
        filepath = opath.join(outdir, 'graph_objs',
                              f'_{fig_classname.lower()}.py')
        format_and_write_source_py(figure_source, filepath)
Beispiel #10
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
    # ----------
    format_and_write_source_py(datatype_source, filepath)
Beispiel #11
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
    # ----------
    format_and_write_source_py(datatype_source, filepath)