summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Schult <dschult@colgate.edu>2016-01-01 13:27:36 -0500
committerDan Schult <dschult@colgate.edu>2016-01-01 16:53:20 -0500
commitf686430ccc0d30e78e8be92330c52417a9a36234 (patch)
treeacbc3bcaf26dc631bfa38678dc3d9653cf9a7e8e
parent4a56f73f3ac454f7e408ea71928ff710c760a3ef (diff)
downloadnetworkx-f686430ccc0d30e78e8be92330c52417a9a36234.tar.gz
Use pydotplus for all supported python versions
- change to "import pydotplus as pydot"; remove flexible import cruft - remove encode("utf-8") in pydot_layout node names - in tests: sort edges for undirected 2-tuples - in travis.yml: pip install from tar.gz for python3.3 (pip couldn't find)
-rw-r--r--.travis.yml7
-rw-r--r--networkx/drawing/nx_pydot.py42
-rw-r--r--networkx/drawing/tests/test_pydot.py11
3 files changed, 30 insertions, 30 deletions
diff --git a/.travis.yml b/.travis.yml
index d983a290..72976c91 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -101,9 +101,14 @@ install:
conda create -n test-environment python=$TRAVIS_PYTHON_VERSION $DEPS gdal;
conda install -n test-environment --channel https://conda.binstar.org/patricksnape scikits-sparse;
source activate test-environment;
+ if [[ "${TRAVIS_PYTHON_VERSION}" =~ "3.3" ]]; then
+ pip install https://pypi.python.org/packages/source/p/pydotplus/pydotplus-2.0.2.tar.gz#md5=0e2fc3dbdfd846819d4cd3769cb4595b;
+ else
+ pip install pydotplus;
+ fi;
python -c "from osgeo import ogr;print('importing ogr worked')";
if [[ "${TRAVIS_PYTHON_VERSION}" =~ "2.7" ]]; then
- pip install pygraphviz pydot2;
+ pip install pygraphviz;
fi;
fi
- if [[ "${PYTHON_VM}" != ipy ]]; then
diff --git a/networkx/drawing/nx_pydot.py b/networkx/drawing/nx_pydot.py
index eafd287a..4a936966 100644
--- a/networkx/drawing/nx_pydot.py
+++ b/networkx/drawing/nx_pydot.py
@@ -9,7 +9,7 @@ Either this module or nx_pygraphviz can be used to interface with graphviz.
See Also
--------
-Pydot: http://code.google.com/p/pydot/
+PyDotPlus: https://github.com/carlos-jenkins/pydotplus
Graphviz: http://www.research.att.com/sw/tools/graphviz/
DOT Language: http://www.graphviz.org/doc/info/lang.html
"""
@@ -32,29 +32,12 @@ try:
except NameError:
basestring = str
-PYDOT_LIBRARIES = ['pydot', 'pydotplus', 'pydot_ng']
-
-def load_pydot():
- for library in PYDOT_LIBRARIES:
- try:
- module = importlib.import_module(library)
- except ImportError:
- pass
- else:
- break
- else:
- msg = "pydot could not be loaded: http://code.google.com/p/pydot/"
- raise ImportError(msg)
-
- return module
-
@open_file(1, mode='w')
def write_dot(G, path):
"""Write NetworkX graph G to Graphviz dot format on path.
Path can be a string or a file handle.
"""
- pydot = load_pydot()
P=to_pydot(G)
path.write(P.to_string())
return
@@ -76,7 +59,10 @@ def read_dot(path):
-----
Use G=nx.Graph(nx.read_dot(path)) to return a Graph instead of a MultiGraph.
"""
- pydot = load_pydot()
+ try:
+ import pydotplus as pydot
+ except ImportError:
+ raise ImportError("pydotplus required for read_dot()")
data = path.read()
P = pydot.graph_from_dot_data(data)
return from_pydot(P)
@@ -182,8 +168,10 @@ def to_pydot(N, strict=True):
-----
"""
- pydot = load_pydot()
-
+ try:
+ import pydotplus as pydot
+ except ImportError:
+ raise ImportError("pydotplus required for to_pydot()")
# set Graphviz graph type
if N.is_directed():
graph_type='digraph'
@@ -268,8 +256,10 @@ def pydot_layout(G,prog='neato',root=None, **kwds):
>>> pos=nx.pydot_layout(G)
>>> pos=nx.pydot_layout(G,prog='dot')
"""
- pydot = load_pydot()
-
+ try:
+ import pydotplus as pydot
+ except ImportError:
+ raise ImportError("pydotplus required for to_pydot()")
P=to_pydot(G)
if root is not None :
P.set("root",make_str(root))
@@ -289,7 +279,7 @@ def pydot_layout(G,prog='neato',root=None, **kwds):
node_pos={}
for n in G.nodes():
- pydot_node = pydot.Node(make_str(n)).get_name().encode('utf-8')
+ pydot_node = pydot.Node(make_str(n)).get_name()
node=Q.get_node(pydot_node)
if isinstance(node,list):
@@ -304,6 +294,6 @@ def pydot_layout(G,prog='neato',root=None, **kwds):
def setup_module(module):
from nose import SkipTest
try:
- pydot = load_pydot()
+ import pydotplus as pydot
except ImportError:
- raise SkipTest("pydot not available")
+ raise SkipTest("pydotplus not available")
diff --git a/networkx/drawing/tests/test_pydot.py b/networkx/drawing/tests/test_pydot.py
index 05d0bbbf..72e67cbd 100644
--- a/networkx/drawing/tests/test_pydot.py
+++ b/networkx/drawing/tests/test_pydot.py
@@ -14,9 +14,9 @@ class TestPydot(object):
def setupClass(cls):
global pydot
try:
- pydot = nx.drawing.nx_pydot.load_pydot()
+ import pydotplus as pydot
except ImportError:
- raise SkipTest('pydot not available.')
+ raise SkipTest('pydotplus not available.')
def build_graph(self, G):
G.add_edge('A','B')
@@ -28,7 +28,12 @@ class TestPydot(object):
def assert_equal(self, G1, G2):
assert_true( sorted(G1.nodes())==sorted(G2.nodes()) )
- assert_true( sorted(G1.edges())==sorted(G2.edges()) )
+ if G1.is_directed():
+ assert_true(sorted(G1.edges()) == sorted(G2.edges()))
+ else:
+ e1 = sorted(map(sorted, G1.edges()))
+ e2 = sorted(map(sorted, G2.edges()))
+ assert_true(e1 == e2)
def pydot_checks(self, G):
H, P = self.build_graph(G)