Git Product home page Git Product logo

pydot-ng's Introduction

CI PyPI Code style: black

About

pydot:

  • is an interface to Graphviz,
  • can parse and dump into the DOT language used by GraphViz,
  • is written in pure Python,

and networkx can convert its graphs to pydot.

Development occurs at GitHub, where you can report issues and contribute code.

Examples

The examples here will show you the most common input, editing and output methods.

Input

No matter what you want to do with pydot, it will need some input to start with. Here are 3 common options:

  1. Import a graph from an existing DOT-file.

    Use this method if you already have a DOT-file describing a graph, for example as output of another program. Let's say you already have this example.dot (based on an example from Wikipedia):

    graph my_graph {
       bgcolor="yellow";
       a [label="Foo"];
       b [shape=circle];
       a -- b -- c [color=blue];
    }

    Just read the graph from the DOT-file:

    import pydot
    
    graphs = pydot.graph_from_dot_file("example.dot")
    graph = graphs[0]
  2. or: Parse a graph from an existing DOT-string.

    Use this method if you already have a DOT-string describing a graph in a Python variable:

    import pydot
    
    dot_string = """graph my_graph {
        bgcolor="yellow";
        a [label="Foo"];
        b [shape=circle];
        a -- b -- c [color=blue];
    }"""
    
    graphs = pydot.graph_from_dot_data(dot_string)
    graph = graphs[0]
  3. or: Create a graph from scratch using pydot objects.

    Now this is where the cool stuff starts. Use this method if you want to build new graphs from Python.

    import pydot
    
    graph = pydot.Dot("my_graph", graph_type="graph", bgcolor="yellow")
    
    # Add nodes
    my_node = pydot.Node("a", label="Foo")
    graph.add_node(my_node)
    # Or, without using an intermediate variable:
    graph.add_node(pydot.Node("b", shape="circle"))
    
    # Add edges
    my_edge = pydot.Edge("a", "b", color="blue")
    graph.add_edge(my_edge)
    # Or, without using an intermediate variable:
    graph.add_edge(pydot.Edge("b", "c", color="blue"))

    Imagine using these basic building blocks from your Python program to dynamically generate a graph. For example, start out with a basic pydot.Dot graph object, then loop through your data while adding nodes and edges. Use values from your data as labels, to determine shapes, edges and so forth. This way, you can easily build visualizations of thousands of interconnected items.

  4. or: Convert a NetworkX graph to a pydot graph.

    NetworkX has conversion methods for pydot graphs:

    import networkx
    import pydot
    
    # See NetworkX documentation on how to build a NetworkX graph.
    
    graph = networkx.drawing.nx_pydot.to_pydot(my_networkx_graph)

Edit

You can now further manipulate your graph using pydot methods:

  • Add further nodes and edges:

    graph.add_edge(pydot.Edge("b", "d", style="dotted"))
  • Edit attributes of graph, nodes and edges:

    graph.set_bgcolor("lightyellow")
    graph.get_node("b")[0].set_shape("box")

Output

Here are 3 different output options:

  1. Generate an image.

    To generate an image of the graph, use one of the create_*() or write_*() methods.

    • If you need to further process the output in Python, the create_* methods will get you a Python bytes object:

      output_graphviz_svg = graph.create_svg()
    • If instead you just want to save the image to a file, use one of the write_* methods:

      graph.write_png("output.png")
  2. Retrieve the DOT string.

    There are two different DOT strings you can retrieve:

    • The "raw" pydot DOT: This is generated the fastest and will usually still look quite similar to the DOT you put in. It is generated by pydot itself, without calling Graphviz.

      # As a string:
      output_raw_dot = graph.to_string()
      # Or, save it as a DOT-file:
      graph.write_raw("output_raw.dot")
    • The Graphviz DOT: You can use it to check how Graphviz lays out the graph before it produces an image. It is generated by Graphviz.

      # As a bytes literal:
      output_graphviz_dot = graph.create_dot()
      # Or, save it as a DOT-file:
      graph.write_dot("output_graphviz.dot")
  3. Convert to a NetworkX graph.

    Here as well, NetworkX has a conversion method for pydot graphs:

    my_networkx_graph = networkx.drawing.nx_pydot.from_pydot(graph)

More help

For more help, see the docstrings of the various pydot objects and methods. For example, help(pydot), help(pydot.Graph) and help(pydot.Dot.write).

More documentation contributions welcome.

Installation

From PyPI using pip:

pip install pydot

From source:

python setup.py install

Dependencies

  • pyparsing: used only for loading DOT files, installed automatically during pydot installation.

  • GraphViz: used to render graphs as PDF, PNG, SVG, etc. Should be installed separately, using your system's package manager, something similar (e.g., MacPorts), or from its source.

Troubleshooting

How to enable logging

pydot uses Python's standard logging module. To see the logs, assuming logging has not been configured already:

>>> import logging
>>> logging.basicConfig(level=logging.DEBUG)
>>> import pydot
DEBUG:pydot:pydot initializing
DEBUG:pydot:pydot <version>
DEBUG:pydot.core:pydot core module initializing
DEBUG:pydot.dot_parser:pydot dot_parser module initializing

Warning: When DEBUG level logging is enabled, pydot may log the data that it processes, such as graph contents or DOT strings. This can cause the log to become very large or contain sensitive information.

Advanced logging configuration

  • Check out the Python logging documentation and the logging_tree visualizer.
  • pydot does not add any handlers to its loggers, nor does it setup or modify your root logger. The pydot loggers are created with the default level NOTSET.
  • pydot registers the following loggers:
    • pydot: Parent logger. Emits a few messages during startup.
    • pydot.core: Messages related to pydot objects, Graphviz execution and anything else not covered by the other loggers.
    • pydot.dot_parser: Messages related to the parsing of DOT strings.

License

Distributed under an MIT license.

Contacts

Current maintainer(s):

  • Łukasz Łapiński <lukaszlapinski7 (at) gmail (dot) com>

Past maintainers:

  • Sebastian Kalinowski <sebastian (at) kalinowski (dot) eu> (GitHub: @prmtl)
  • Peter Nowee <peter (at) peternowee (dot) com> (GitHub: @peternowee)

Original author: Ero Carrera <ero (dot) carrera (at) gmail (dot) com>

pydot-ng's People

Contributors

chebee7i avatar erocarrera avatar graingert avatar gustavla avatar nlhepler avatar prmtl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

pydot-ng's Issues

[94] Problems with node's name contains colon (:)

Reported by [email protected], 2014-07-23T17:02:43Z

What steps will reproduce the problem?
  1. Trying to make an output with node A(name="aaaa::bbbb") and node B(name="cccc::dddd") and edge A -> B

In a dot language, the expected output was "aaaa::bbbb" -> "cccc::dddd",
but it returns "aaaa:":bbbb -> "cccc:":dddd.

What version of the product are you using? On what operating system?

It happens on a latest version.

Please provide any additional information below.

From: https://code.google.com/p/pydot/issues/detail?id=94

[97] Make dot_parser import error mutable

Reported by [email protected], 2014-12-22T14:49:33Z

When you import pydot without having dot_parser installed, you get a warning like this:

"Couldn't import dot_parser, loading of dot files will not be possible"

Since this warning is output to stdout, you can't mute it, so if you don't need dot_parser, you have a warning you can never silence.

The attached patch replaces the print statement with a call to warnings.warn(), so that the import warning can be optionally muted.
Attached patch.txt (view on Gist)
From: https://code.google.com/p/pydot/issues/detail?id=97

[72] Quotes included in the node's name

Reported by [email protected], 2012-05-07T15:30:05Z

What steps will reproduce the problem?
  1. Create a dot file with lines:
  "testnode"
  testnode 
  1. call get_nodes()
What is the expected output? What do you see instead?

I would expect one node called 'testnode'. Not two - 'testnode' and '"testnode"' (quoted). Quotes should not be included in the names.

What version of the product are you using? On what operating system?

pydot-1.0.28

Possibly associated with Issue 66.

Dot spec. states:
An ID is just a string; the lack of quote characters in the first two forms is just for simplicity. There is no semantic difference between abc_2 and "abc_2", or between 2.34 and "2.34".

http://www.graphviz.org/content/dot-language
From: https://code.google.com/p/pydot/issues/detail?id=72

[93] Unable to install from pip

Reported by [email protected], 2014-07-05T20:38:10Z

What steps will reproduce the problem?
  1. $ pip install 'pydot==1.0.28'
What is the expected output? What do you see instead?

Installation should proceed correctly.

Instead I have to do the following to get this to work.

$ pip install 'pydot==1.0.28' --allow-external pydot --allow-unverified pydot
What version of the product are you using? On what operating system?
$ pip --version
pip 1.5.6
Please provide any additional information below.
$ lsb_release  -a
LSB Version:    :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
Distributor ID: CentOS
Description:    CentOS release 6.4 (Final)
Release:    6.4
Codename:   Final
$ python --version
Python 2.6.6

From: https://code.google.com/p/pydot/issues/detail?id=93

[84] Multiple test failures (Ubuntu 13.04, graphviz 2.26.3-14ubuntu1)

Reported by [email protected], 2013-09-20T19:50:13Z

What steps will reproduce the problem?
  1. cd test && python pydot_unittest.py
What is the expected output? What do you see instead?

Expected: all tests pass
Actual: several tests fail (details below)

What version of the product are you using? On what operating system?
Please provide any additional information below.

The following test case failed:

TestGraphAPI.test_attribute_with_implicit_value
TestGraphAPI.test_create_simple_graph_with_node
TestGraphAPI.test_graph_pickling
TestGraphAPI.test_graphviz_regression_tests
TestGraphAPI.test_my_regression_tests
TestGraphAPI.test_quoting
TestGraphAPI.test_subgraphs
TestGraphAPI.test_unicode_ids

I'll attach a log of the complete run.
Attached test-failures.log (view on Gist)
From: https://code.google.com/p/pydot/issues/detail?id=84

[81] pydot depends on pyparsing, the newest version of which is Py3 only

Reported by WJWwood, 2013-03-04T02:01:22Z

What steps will reproduce the problem?
  1. Try to install pydot from pip on OS X.
What is the expected output? What do you see instead?

That it installs correctly.

What version of the product are you using? On what operating system?

pydot 1.0.28 on OS X 10.8.2

Please provide any additional information below.

Probably just need an versioned depend on pyparsing, something like:

Index: setup.py
===================================================================
--- setup.py    (revision 29)
+++ setup.py    (working copy)
@@ -31,5 +31,5 @@
         'Topic :: Software Development :: Libraries :: Python Modules'],
     long_description = "\n".join(pydot.__doc__.split('\n')),
     py_modules = ['pydot', 'dot_parser'],
-    install_requires = ['pyparsing', 'setuptools'],
+    install_requires = ['pyparsing<2.0.0', 'setuptools'],
     data_files = [('.', ['LICENSE', 'README'])] )

From: https://code.google.com/p/pydot/issues/detail?id=81

[96] pydot 1.0.28 on pypi?

Reported by [email protected], 2014-09-18T15:35:10Z

Hello there,

I've noticed that with pip 1.5, pip install pydot gives the old (and for my purposes) pydot 1.0.2.

Would it be possible for the current pydot (1.0.28?) to be uploaded to PyPI? If I understand correctly, the issue is that whilst it is mentioned in the index, the actual tarball is externally hosted on code.google.com; and also does not come with a hash. Perhaps uploading directly to pypi would simplify installation for users?

Currently, for example, all of my pip requirements.txt files require these lines

--allow-external pydot
--allow-unverified pydot

Moreover the need for these means that users with pip 1.4 (default on MacOS X 10.9.4, for example) will not be able to install my packages without first upgrading pip.

Many thanks!
From: https://code.google.com/p/pydot/issues/detail?id=96

[92] Simplify throws NameError, and, as implemented, doesn't work

Reported by [email protected], 2014-06-12T04:30:48Z

What steps will reproduce the problem?
  1. invoke set_simplify(true) on a graph
  2. invoke method to_string()
  3. profit
What is the expected output? What do you see instead?

Extraneous edges removed from dot output

What version of the product are you using? On what operating system?

1.0.2

Please provide any additional information below.

This is a patch which both resolves the NameError and enables the desired behavior:

--- /usr/lib/python2.6/site-packages/pydot.py   2014-06-12 06:22:57.000000000 +0400
+++ virtenv/lib/python2.6/site-packages/pydot.py    2014-06-12 06:28:42.515864719 +0400
@@ -1455,11 +1455,11 @@

                 edge = Edge(obj_dict=obj)

-                if self.obj_dict.get('simplify', False) and elm in edges_done:
+                if self.obj_dict.get('simplify', False) and edge.obj_dict['points'] in edges_done:
                     continue
-
+
                 graph.append( edge.to_string() + '\n' )
-                edges_done.add(edge)
+                edges_done.add(edge.obj_dict['points'])

             else:

Attached pydot_simplify.patch (view on Gist)
From: https://code.google.com/p/pydot/issues/detail?id=92

[80] Setting default graph/node/edge attrs in an existing graph has no effect

Reported by [email protected], 2013-03-01T10:46:07Z

What steps will reproduce the problem?
  1. g = pydot.graph_from_dot_data("""
    digraph G {
    1 -> 2;
    }
    """)
  2. g.set_node_defaults(style="filled", fillcolor="yellow")
  3. g.write_png("simple.yellow.png")
What is the expected output? What do you see instead?

Should see yellow nodes, but nodes are still white.

What version of the product are you using? On what operating system?

Pydot 1.0.28, Python 2.7.3

Please provide any additional information below.

Default attributes are added to the BOTTOM of the DOT spec, after existing nodes and edges, so they don't take effect. They should be inserted at the TOP of the spec to take effect everywhere.

The attached file demonstrates the problem and the solution.
Attached pydot_bug.py (view on Gist)
From: https://code.google.com/p/pydot/issues/detail?id=80

[83] An attribute with "name" ID produces an error when loading dot data

Reported by [email protected], 2013-05-01T05:54:11Z

What steps will reproduce the problem?
  1. pydot.graph_from_dot_data("graph G { a [name=b] }")
2.
3.
What is the expected output? What do you see instead?

output:
TypeError: init() got multiple values for keyword argument 'name'

expected output: I think that this should not produce an error, since it is not excluded by the DOT language.

What version of the product are you using? On what operating system?

pydot 1.0.28; Gentoo/Linux 3.0.6; Python 2.7.3

Please provide any additional information below.

From: https://code.google.com/p/pydot/issues/detail?id=83

Update "README.rst" introduction for great glory of Poznań

Another minor textual issue for you, @prmtl. The introductory paragraph of README.rst could probably benefit from a facelift. This is painfully self-obvious, but...

  • This project is pydot-ng rather than merely pydot.
  • The project tagline (i.e., slogan) should ideally differentiate this project in some way from the original pydot project: e.g.,

pydot-ng - Next-generation Python interface to Graphviz's Dot language

  • Since Ero Carrera (@erocarrera)'s last commit was January 2nd, 2012, the copyright line should be updated to read:

      Ero Carrera (c) 2004-2012
    
  • Likewise, since your first commit was February 25th, 2015, a second copyright line assigning current copyrights to you should be added: e.g.,

      Sebastian Kalinowski (c) 2015-2018
    
  • Since @erocarrera hasn't been involved in the PyDot world for nearly a decade, it might be more useful to list your contact information rather than [email protected].

Altogether, an updated frontispiece might resemble:

pydot-ng - Next-generation Python interface to Graphviz's Dot language

Ero Carrera (c) 2004-2012
Sebastian Kalinowski (c) 2015-2018

[email protected]

Thanks for the continued attention! May the last of your Autumn be warm and giddy. 🍂

[91] GraphViz's executables not found on Windows 7 64-bit if user installs them in a custom directory

Reported by [email protected], 2014-03-28T20:30:27Z

I am running Windows 7 64-bit. I installed graphviz-2.36.msi from http://www.graphviz.org/Download_windows.php but I install most programs to c:\app rather than c:\Program Files, and I get this message (see below). One problem is that there is no SOFTWARE\ATT registry key anymore. (perhaps related to #65)

I think the bigger problem is that this discovery mechanism is a cat-and-mouse game with whatever the graphviz folks do.

===> Could you please add a function so that end-users can just set the graphviz path manually through whatever mechanism they see fit?

For now I'm just monkeypatching the pydot module:

def force_find_graphviz(graphviz_root):
   binpath = os.path.join(graphviz_root, 'bin')
   programs = 'dot twopi neato circo fdp sfdp'
   def helper():
     for prg in programs.split():
       if os.path.exists(os.path.join(binpath, prg)):
         yield ((prg, os.path.join(binpath, prg)))
       elif os.path.exists(os.path.join(binpath, prg+'.exe')):
         yield ((prg, os.path.join(binpath, prg+'.exe')))
   progdict = dict(helper())
   return lambda: progdict

pydot.find_graphviz = force_find_graphviz('c:/app/util/graphviz/2.36')
C:\tmp\blockdiag>python
Python 2.7.5 |Anaconda 1.9.1 (64-bit)| (default, May 31 2013, 10:45:37) [MSC v.1
500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pydot
Couldn't import dot_parser, loading of dot files will not be possible.
>>> graph = pydot.Dot(graph_type='graph')
>>> graph.write_png('test.png')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "c:\app\python\anaconda\1.6.0\lib\site-packages\pydot.py", line 1602, in
<lambda>
    lambda path, f=frmt, prog=self.prog : self.write(path, format=f, prog=prog))

  File "c:\app\python\anaconda\1.6.0\lib\site-packages\pydot.py", line 1696, in
write
    dot_fd.write(self.create(prog, format))
  File "c:\app\python\anaconda\1.6.0\lib\site-packages\pydot.py", line 1724, in
create
    self.progs = find_graphviz()
  File "c:\app\python\anaconda\1.6.0\lib\site-packages\pydot.py", line 409, in f
ind_graphviz
    "SOFTWARE\ATT\Graphviz", 0, win32con.KEY_QUERY_VALUE )
pywintypes.error: (2, 'RegOpenKeyEx', 'The system cannot find the file specified
.')
>>>

From: https://code.google.com/p/pydot/issues/detail?id=91

[76] Python 3 compatibility

Reported by [email protected], 2012-11-05T14:43:39Z

The Python 3-compatible branch mentioned on the project home page is over a year old, so apparently it's not kept up-to-date with pydot development. The latest tag is for version 1.0.15, whereas 1.0.28 is the current version of pydot.

Python 3 is becoming more and more mainstream, especially for new projects. It would be very nice to be able to use pydot in Python 3.x projects too.
From: https://code.google.com/p/pydot/issues/detail?id=76

Add documentation for pydot-ng

Documentation should be hosted on Github Pages (github.io) or on Read The Docs. Probably Read The Docs will be better since it was created for such tasks.

Things that need to be done:

  • choose hosting place
  • integrate with Sphinx (do we want to choose anything else?)
  • ...

Some things that need to be covered:

  • dev guide
  • how to replace pydot with pydot-ng
  • some short info about DOT language (see for example #24)
  • integration with networkx
  • ...

[82] syntax error on escaped quotes in double quoted strings

Reported by [email protected], 2013-05-01T05:34:13Z

According to http://www.graphviz.org/doc/info/lang.html, an ID can be:
...
'any double-quoted string ("...") possibly containing escaped quotes (")1;'

pydot does not properly read double quoted strings with escaped quotes

What steps will reproduce the problem?
  1. pydot.graph_from_dot_data("graph G { a [test="\"escaped quotes\""] }")

or

  1. create the following DOT file:
graph G {
  a [test="\"escaped quotes\""]
}
  1. pydot.graph_from_dot_file("file.dot")
What is the expected output? What do you see instead?

expected output: <pydot.Dot object at 0xb483de8c>
output:

graph G { a [test="\"escaped quotes\""] }
            ^
Expected "}" (at char 12), (line:1, col:13)
What version of the product are you using? On what operating system?

pydot 1.0.28; Python 2.7.3; Gentoo/Linux 3.0.6

Please provide any additional information below.

A suggested patch is attached. Apply to dot_parser.py
patch -Np1 dot_parser.py escChar.patch
Attached escChar.patch (view on Gist)
From: https://code.google.com/p/pydot/issues/detail?id=82

[87] Can't install Pydot via pip on my ovh server

Reported by [email protected], 2013-12-02T19:48:34Z

What steps will reproduce the problem?
  1. pip install pydot

Downloading/unpacking pydot
HTTP error 403 while getting http://pydot.googlecode.com/files/pydot-1.0.28.tar.gz (from https://pypi.python.org/simple/pydot/)
Could not install requirement pydot because of error HTTP Error 403: Forbidden
Could not install requirement pydot because of HTTP error HTTP Error 403: Forbidden for URL http://pydot.googlecode.com/files/pydot-1.0.28.tar.gz (from https://pypi.python.org/simple/pydot/)

This is very strange since it works on my local machine.

Please provide any additional information below.

Ubuntu 13.04/Python2.7(virtualenv, pip1.4.1)
similar issue: gak/pygooglechart#18
From: https://code.google.com/p/pydot/issues/detail?id=87

[77] Basic pydot usage error

Reported by [email protected], 2012-11-05T21:31:34Z

What steps will reproduce the problem?
  1. Use Python 3.2.3 on fedora and pydot port to Python3
  2. try following code:
    import pydot
    P = pydot.Dot()
    D = P.create_dot().decode('utf-8')
    print(D)
    Q=pydot.graph_from_dot_data(D)
What is the expected output? What do you see instead?

Expected result is no error. I get the following error:
$python3.2 foo1.py
digraph G {
node [label="\N"];
graph [bb="0,0,0,0"];
}

Traceback (most recent call last):
File "foo1.py", line 5, in
Q=pydot.graph_from_dot_data(D)
File "/nh/nest/u/aric/.local/lib/python3.2/site-packages/pydot-1.0.15-py3.2.egg/pydot.py", line 211, in graph_from_dot_data
return dot_parser.parse_dot_data(data)
File "/nh/nest/u/aric/.local/lib/python3.2/site-packages/pydot-1.0.15-py3.2.egg/dot_parser.py", line 472, in parse_dot_data
if data.startswith( codecs.BOM_UTF8 ):
TypeError: startswith first arg must be str or a tuple of str, not bytes

For more information, please see: networkx/networkx#790

What version of the product are you using? On what operating system?

Fedora 17, x86_64
Pydot - newest version from Python3 branch: https://bitbucket.org/prologic/pydot/overview
Python 3.2.3
python3-pyparsing 1.5.6

Please provide any additional information below.

From: https://code.google.com/p/pydot/issues/detail?id=77

[65] GraphViz's executables not found on Windows 7 64-bit

What steps will reproduce the problem?

  1. Install pydot on Win 7 64
  2. Try to run the graph write_png() method

What is the expected output? What do you see instead?

You'll see this:
graph.write_png('example2_graph.png')
File "build\bdist.win-amd64\egg\pydot.py", line 1809, in
File "build\bdist.win-amd64\egg\pydot.py", line 1911, in write
File "build\bdist.win-amd64\egg\pydot.py", line 1953, in create
pydot.InvocationException: GraphViz's executables not found

What version of the product are you using? On what operating system?

Using graphviz 2.28 on Win 7 64-bit.

Please provide any additional information below.

It looks like graphviz uses a different registry setting for Win7 64:

hkey = win32api.RegOpenKeyEx( win32con.HKEY_LOCAL_MACHINE, "SOFTWARE\Wow6432Node\AT&T Research Labs\Graphviz 2.28", 0, win32con.KEY_QUERY_VALUE )

From: https://code.google.com/p/pydot/issues/detail?id=65
Reported by [email protected], Jan 20, 2012

[85] Multiple styles not correctly rendered ("style=S1, S2=true")

Reported by [email protected], 2013-09-20T20:02:10Z

What steps will reproduce the problem?
  1. add a node constructed like pydot.Node('A', shape='box', style='rounded,dotted')
  2. use graph.write_raw() to emit the dot equivalent
What is the expected output? What do you see instead?

expected output:
A [style="rounded,dotted", shape=box];

actual output:
A [style=rounded,dotted, shape=box];

Note the lack of quoting. dot sees only "rounded" and ignores "dotted".

What version of the product are you using? On what operating system?

svn r29 from http://pydot.googlecode.com/svn/trunk

Please provide any additional information below.

Here is my complete test script:

import pydot

graph = pydot.Dot(graph_type='digraph')
graph.add_node(pydot.Node('A', shape='box', style='rounded,dotted'))

graph.write_raw('twostyles.dot')

and here is the complete dot file that I expect from that script:

digraph G {
A [style="rounded,dotted", shape=box];
}

From: https://code.google.com/p/pydot/issues/detail?id=85

[95] move to git and github

Reported by [email protected], 2014-08-01T19:58:57Z

I would like to suggest moving the official home of pydot to github, and converting the repository from svn to github. The advantages of git over svn are widely accepted and in support are the number of projects that have migrated to git, and many to github from both googlecode and sourceforge.

Other major advantages will be:

  1. there is a community there that will soon send pull requests with updates, open issues reporting bugs and discuss. There already exist unofficial mirrors and forks of pydot on github. So this will encourage people to push their improvements upstream.
  2. github interface ergonomics and popularity are not comparable to googlecode.
  3. issue tracking is superbly implemented on github.

In case people are needed to help with this, I would be happy to do so.
From: https://code.google.com/p/pydot/issues/detail?id=95

[69] Prints to stdout if cannot load dot_parser

Reported by [email protected], 2012-03-20T11:05:59Z

If dot_parser cannot be loaded in pydot, a message is printed to stdout. I believe it's incorrect. A message should be printed to stderr (as in the following patch), or not printed at all.

*** pydot.py.orig   2012-03-20 13:48:01.009730200 +0400
--- pydot.py    2012-03-20 13:48:27.784195800 +0400
***************
*** 23,28 ****
--- 23,29 ----
  __license__ = 'MIT'

  import os
+ import sys
  import re
  import subprocess
  import tempfile
***************
*** 30,36 ****
  try:
      import dot_parser
  except Exception, e:
!     print "Couldn't import dot_parser, loading of dot files will not be possible."



--- 31,37 ----
  try:
      import dot_parser
  except Exception, e:
!     print >> sys.stderr, "Couldn't import dot_parser, loading of dot files will not be possible."

Originally assigned to [email protected]
From: https://code.google.com/p/pydot/issues/detail?id=69

[63] Problem with empty labels

Reported by [email protected], 2012-01-10T10:19:15Z

What steps will reproduce the problem?
  1. Define node with an empty label:
    node = Node('PROCESS_END', shape='doublecircle', style='filled', label='', width='.15')

What is the expected output?
PROCESS_END [width=".15", style=filled, shape=doublecircle, label=""];
or better:
PROCESS_END [width=".15", style="filled", shape="doublecircle", label=""];

What do you see instead?

  1. I get:
    PROCESS_END [width=".15", style=filled, shape=doublecircle, label=];
  2. and the the exception while generating png output:
    Error: XXX.gv:17: syntax error near line 17
    context: PROCESS_END [width=".15", style=filled, shape=doublecircle, >>> label=] <<< ;
  3. and the result picture without the requested width of .15, and with a PROCESS_END label .
What version of the product are you using? On what operating system?

The case is with 1.0.28 release.

Please provide any additional information below.

Release 1.0.25 manages this case properly.

IMO all the attribute values should be quoted.
Originally assigned to [email protected]
From: https://code.google.com/p/pydot/issues/detail?id=63

[68] Invalid command line generated when extra parameters specified

Reported by [email protected], 2012-03-08T19:21:04Z

What steps will reproduce the problem?
  1. Generate any graph structure
  2. Call the write function with a list as the parameter, using more than one value in the list. For example :
    graph.write_svg(somefile, prog=['twopi', 'overlap=scale'])

Expected : The graph is generated using the extra settings specified
Actual : The library raises an error saying that the command line was invalid (with the example above : "InvocationException: Program terminated with status: 2. stderr follows: Error: twopi: can't open overlap=scale")

Pydot-1.0.28-py2.7, on windows 7 x64

I think the bogus line is line 1985 :
cmdline = [self.progs[prog], '-T'+format, tmp_name] + args

The error is that the args list is appended at the end of the command list, while they should be placed between the -T and input elements (the rule being that the input files must be placed at the end of the command)
Originally assigned to [email protected]
From: https://code.google.com/p/pydot/issues/detail?id=68

Freudian typo in repository description

Thanks for the recent commit activity, @prmtl. The excitement begins.

I noted a mildly amusing Freudian slip in the GitHub repository description:

Python interface to Graphviz's Dot language compatible with Python 2 nad Python 3

That should read and rather than nad. In English slang, the term "nad" colloquially refers to... well, the male reproductive organs. </ahem>

You see the problem, I trust. I'll show myself the door now.

Restore compliance with the crusty "pydot" API

README.rst boldly claims that:

This library is API compatible with original pydot so you can use it like this:
import pydot_ng as pydot

Of course, this hasn't been true for over three years; pydot-ng only adheres to the old pydot API. The new pydot API is considerably different. Downstream consumers that actually try to import pydot_ng as pydot are gonna have a Bad Time™.

Just Shoot Me Now

Notably, most top-level pydot functions and methods (e.g., pydot.graph_from_dot_data()) now unconditionally return a list of one or more Graph objects rather than conditionally returning either a single Graph object or a list of two or more Graph objects. To quote @johnyf in an ancient pydot issue:

An earlier version of the API used to return a graph object when the dot file defined one graph, and a list of graphs otherwise (in the case of more graphs). However, I found that the inhomogeneous behavior is more complex (simple is better than complex, PEP 20), so I changed it to return a list in all cases (e.g., a list containing one graph). This simplifies also user code, because there no case distinction needs to be made.

These are useful changes – but they do break backward compatibility. For conformance with the modern pydot API, it's critical that the pydot-ng API be refactored to behave similarly.

But... Can It Be Done?

It can! With perseverance and hideous suffering, anything is possible.

Since these API changes are largely undocumented, the simplest solution might be to:

  1. Integrate the most recent pydot test suite into the existing pydot-ng test suite.
  2. Manually fix each broken test – one by one.

For these purposes, test/pydot_unittest.py is the only useful file. Relevant unit tests include:

Godspeed You Intrepid Coder!

Best of luck, @prmtl. I'd submit a pull request resolving this, but we have our hands full just trying to survive the oncoming Canadian winter. Because in Canada, winter is always coming.

Perpetual snow and unyielding darkness. It isn't easy, folks. ❄️ ☃️ 🏔️

[70] Nodes not identified in graph

Reported by [email protected], 2012-04-09T20:11:41Z

What steps will reproduce the problem?
  1. Create this dot file:
graph condiments {
    ketchup -- mayonnaise -- tartar -- lemon
    ketchup -- bbq
}
  1. Create and run this python script:
impot sys
import pydot

# first arg is the dot file
if len(sys.argv) < 2:
    exit()

g = pydot.graph_from_dot_file(sys.argv[1])

print g.get_node_list()
What is the expected output? What do you see instead?

The output is an empty list, I expected a list of nodes (ketchup, bbq, etc.)

What version of the product are you using? On what operating system?

pydot-1.0.28 with Python 2.7.1, OS X

Please provide any additional information below.

From: https://code.google.com/p/pydot/issues/detail?id=70

[89] cluster to cluster edge fails

Reported by [email protected], 2014-03-07T11:41:54Z

What steps will reproduce the problem?

To see if I'm it's possible to get the dependency graph from VCL/Delphi project, I'm trying to reproduce this example http://www.graphviz.org/content/fdpclust (directed)

everything works well, until it come to add edges on clusters then it fail. (e-> clusterB and clusterC -> clusterD)

What version of the product are you using? On what operating system?

pydot 1.0.28 (patched so it find Graphviz in "Program Files (x86), python 3.3, Windows 7 64 bits.

Joined : the function I use to produce the graph,
Attached clusterExample.py (view on Gist)
From: https://code.google.com/p/pydot/issues/detail?id=89

[66] pydot generates unwanted quotes on edge output

Reported by [email protected], 2012-02-15T19:31:23Z

When generating edges with nodes name starting with a digit, unwanted quotes appear if src or dst includes a letter.
pydot.Edge("1111:1111","2222")
===> 1111:1111 -- 2222
but
pydot.Edge("1111:1111x","2222")
===> "1111:1111x" -- 2222

Since dot does not interpret properly port when quotes are present, this is bogus. See attached patch.
Originally assigned to [email protected]
Attached pydot_fix_need_quotes.patch (view on Gist)
From: https://code.google.com/p/pydot/issues/detail?id=66

[99] pydot should quote labels with colons

Reported by [email protected], 2015-01-31T11:26:23Z

What steps will reproduce the problem?
  1. add to a graph pydot.Edge(src='A', dst='B', label='A:B')
  2. try to render
What is the expected output? What do you see instead?

Expect a graph. Instead, produces an invalid DOT file which then leads to an error:
Warning: /tmp/tmpxw5_0w: syntax error in line 5 near ':'

What version of the product are you using? On what operating system?

1.0.28 Linux (Ubuntu)
From: https://code.google.com/p/pydot/issues/detail?id=99

[88] Guidelines for Node label formatting

Reported by [email protected], 2013-12-12T23:06:44Z

It seems that formatting of the label string supplied to Node constructor
is very sensitive. I had working code that was producing svg with this kind of string for node labels:$GUID__/ffb73e1c-7495-40b3-9618-9e5462fc89c7 . Now I think I have new pydot version and the code does not work:
Warning: /tmp/tmpxa46du:5: ambiguous "-40b" splits into two names: "-40" and "b". If I remove this string, the problems continue, something about newline at the end of the remaining string (as I read on the forum somewhere).

What are the rules for the label string?
Thank you.
From: https://code.google.com/p/pydot/issues/detail?id=88

[98] possible bug in graph_from_adjacency_matrix

Reported by [email protected], 2015-01-26T13:22:22Z

Hi
in the function graph_from_adjacency_matrix, in order to define edges, a string is concatenated with an integer, which generates an error:

  Edge( node_prefix + node_orig, 
        node_prefix + node_dest) )

(node_prefix is a string, node_orig and node_dest are integers).

This is how you can reproduce the problem:

  1. define an adjacency matrix:
import numpy as np
am = np.array([[0, 1, 0], [1, 0, 0], [0, 1, 1]])
  1. run the function:
import pydot
bdot = pydot.graph_from_adjacency_matrix(am, directed=True)

The expected output is to obtain a bdot object, instead you get:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/dist-packages/pydot.py", line 302, in graph_from_adjacency_matrix
    Edge( node_prefix + node_orig, 
TypeError: coercing to Unicode: need string or buffer, int found

Similarly, if you run

bdot = pydot.graph_from_adjacency_matrix(np.asarray(a), node_prefix='', directed=True)

to avoid eventual problems with unicode, you get:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/dist-packages/pydot.py", line 302, in graph_from_adjacency_matrix
    Edge( node_prefix + node_orig, 
TypeError: cannot concatenate 'str' and 'int' objects

I am using Python 2.7.6, pydot version 1.0.28, on Ubuntu 14.04, 64 bits.
From: https://code.google.com/p/pydot/issues/detail?id=98

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.