Exemplo n.º 1
0
def main(args=None):
    args = parse_args(args)

    zettels = parse_zettels(args.zettel_paths)

    # Fail in case we didn't find a zettel
    if not zettels:
        raise FileNotFoundError("I'm sorry, I couldn't find any files.")

    if args.use_graphviz:
        from zkviz.graphviz import NetworkGraphviz
        import graphviz

        try:
            graphviz.version()
        except graphviz.ExecutableNotFound:
            raise FileNotFoundError(
                fill("The Graphviz application must be installed for the"
                     " --use-graphviz option to work. Please see"
                     " https://graphviz.org/download/ for installation"
                     " instructions."))
        graph = NetworkGraphviz()
    else:
        from network_plotly import NetworkPlotly

        graph = NetworkPlotly()

    graph = create_graph(
        zettels,
        graph,
        include_self_references=args.include_self_references,
        only_listed=args.only_listed,
    )
    graph.render(args.output)
def test_version_parsefail_mocked(mock_run):
    mock_run.return_value = subprocess.CompletedProcess(
        _common.INVALID_CMD,
        returncode=0,
        stdout='nonversioninfo',
        stderr=None)

    with pytest.raises(RuntimeError, match=r'nonversioninfo'):
        graphviz.version()

    mock_run.assert_called_once_with([_common.EXPECTED_DOT_BINARY, '-V'],
                                     stdout=subprocess.PIPE,
                                     stderr=subprocess.STDOUT,
                                     startupinfo=_common.StartupinfoMatcher(),
                                     encoding='ascii')
Exemplo n.º 3
0
def visualize(metadata, path=None, names=True, details=True):
    """Plot metadata usign graphviz.

    Try to generate a plot using graphviz.
    If a ``path`` is provided save the output into a file.

    Args:
        metadata (Metadata):
            Metadata object to plot.
        path (str):
            Output file path to save the plot, it requires a graphviz
            supported extension. If ``None`` do not save the plot.
            Defaults to ``None``.
    """
    filename, graphviz_extension = _get_graphviz_extension(path)
    digraph = graphviz.Digraph(
        'Metadata',
        format=graphviz_extension,
        node_attr={
            "shape": "Mrecord",
            "fillcolor": "lightgoldenrod1",
            "style": "filled"
        },
    )

    _add_nodes(metadata, digraph, names, details)
    _add_edges(metadata, digraph, names, details)

    if filename:
        digraph.render(filename=filename,
                       cleanup=True,
                       format=graphviz_extension)
    else:
        try:
            graphviz.version()
        except graphviz.ExecutableNotFound:
            warning_message = (
                'Graphviz does not seem to be installed on this system. For full '
                'metadata visualization capabilities, please make sure to have its '
                'binaries propertly installed: https://graphviz.gitlab.io/download/'
            )
            warnings.warn(warning_message, RuntimeWarning)

        return digraph
def test_version_mocked(mock_run, stdout, expected):
    mock_run.return_value = subprocess.CompletedProcess(_common.INVALID_CMD,
                                                        returncode=0,
                                                        stdout=stdout,
                                                        stderr=None)

    assert graphviz.version() == expected

    mock_run.assert_called_once_with([_common.EXPECTED_DOT_BINARY, '-V'],
                                     stdout=subprocess.PIPE,
                                     stderr=subprocess.STDOUT,
                                     startupinfo=_common.StartupinfoMatcher(),
                                     encoding='ascii')
Exemplo n.º 5
0
def render(board,adp,filename):
    print(graphviz.version())
    graph = graphviz.Digraph('adp-viz', \
                           filename=filename, \
                           graph_attr={
                               "overlap":'false',
                               "splines":'true', \
                           })
    for cfg in adp.configs:
        render_instance(board,graph,cfg,scale=True,source=True)
        render_config_info(board,graph,cfg)

    for conn in adp.conns:
        render_conn(graph,conn)
    graph.node("time_const", "tau:%f" % adp.tau)
    graph.render()
Exemplo n.º 6
0
class TestPlot:
    """ test that the graph structures are plotted when graphviz """

    # skip these test cases if graphviz is not installed
    pytest.importorskip("graphviz", "you gotta install graphviz bro")
    import graphviz  # checks for python graphviz

    try:
        graphviz.version()  # checks for C library
    except graphviz.ExecutableNotFound:
        pytest.skip("graphviz is not installed")

    file_name = ".deleteme"

    # fixtures
    @pytest.fixture(autouse=True)
    def cleanup_pdf(self):
        """ delete pdf file """
        yield
        if os.path.exists(self.file_name):
            os.remove(self.file_name)

    def test_plot_all_pypes(self, pype_object):
        """ test that all the valid pypes can be plotted """
        pype_object.plot(view=False)

    def test_basic_plot(self, forked_aggregated_pype):
        """ensure calling plot creates the expected pdf from graphviz """
        forked_aggregated_pype.plot(file_name=self.file_name, view=False)

    def test_if_plot(self, iff_pype):
        """ ensure the conditional pype get plotted """
        iff_pype.plot(file_name=self.file_name, view=False)

    def test_fan_plot(self):
        """ plots a simple fan """
        pype = pype_input << add1
        pype.plot(file_name=self.file_name, view=False)

    def test_aggregate_plot(self):
        """ plot an aggregate pype """
        pype = pype_input << add1 | forward >> add1
        pype.plot(file_name=self.file_name, view=False)

    def test_fan_aggregate_plot(self, fan_aggregate_pype):
        """ plots a pype that usses aggregations """
        fan_aggregate_pype.plot(file_name=self.file_name, view=False)
Exemplo n.º 7
0
def render(vadp, filename):
    print(graphviz.version())
    graph = graphviz.Digraph('vadp-viz', \
                           filename=filename, \
                           graph_attr={
                               "overlap":'scale', \
                               "nodesep":'1', \
                               "splines":'curved', \
                           },
                           node_attr={'shape':'record'})
    for idx, stmt in enumerate(vadp):
        if isinstance(stmt, vadplib.VADPConfig):
            render_config(graph, stmt)

        elif isinstance(stmt, vadplib.VADPConn):
            src_id = "%s%s:%s" % (stmt.source.block.name, stmt.source.ident,
                                  stmt.source.port.name)
            sink_id = "%s%s:%s" % (stmt.sink.block.name, stmt.sink.ident,
                                   stmt.sink.port.name)
            graph.edge(src_id, sink_id)

        elif isinstance(stmt, vadplib.VADPSink):
            port_id = "%s%s:%s" % (stmt.target.block.name, stmt.target.ident,
                                   stmt.target.port.name)
            sink_id = "sink%d" % idx
            graph.node(sink_id, "sink:" + str(stmt.dsexpr))
            graph.edge(sink_id, port_id)

        elif isinstance(stmt, vadplib.VADPSource):
            port_id = "%s%s:%s" % (stmt.target.block.name, stmt.target.ident,
                                   stmt.target.port.name)
            source_id = "src%d" % idx
            graph.node(source_id, "source: " + str(stmt.dsexpr))
            graph.edge(port_id, source_id)

    graph.render()
Exemplo n.º 8
0
import graphviz
import mxnet
import numpy
import scipy
import sklearn, sklearn.ensemble
import xgboost

if sys.version_info.major == 2:
    import backports.tempfile as tempfile
else:
    import tempfile

if sys.maxsize != 2**63 - 1:
    raise Exception("This script must be ran on Python 64-bit.")

gv_major, gv_minor, _ = graphviz.version()
if not (gv_major == 2 and gv_minor >= 38):
    raise Exception(
        "This script must be ran with a separate installation of graphviz version 2.38 or higher."
    )

s3_model_path, s3_dir_path = sys.argv[1:3]


class NumpyEncoder(json.JSONEncoder):
    """ Special json encoder for numpy types """
    def default(self, obj):
        if isinstance(obj, (numpy.ndarray, )):
            return obj.tolist()
        elif isinstance(obj, (mxnet.ndarray.ndarray.NDArray, )):
            return obj.asnumpy().tolist()
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

__author__ = 'ipetrash'

# pip install graphviz
import graphviz
print(graphviz.version())
Exemplo n.º 10
0
def test_version(capsys):
    result = graphviz.version()
    assert isinstance(result, tuple) and result
    assert all(isinstance(d, int) for d in result)
    assert capsys.readouterr() == ('', '')