summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichele Borassi <michele.borassi@imtlucca.it>2015-07-27 12:01:36 +0200
committerMichele Borassi <michele.borassi@imtlucca.it>2015-07-28 12:42:54 +0200
commitacd870b30a526ad507e8b0d920cf4ff696a86626 (patch)
tree9899eaf15aa9238a9e6bc72e75fb904ac8074dca
parenttrac #18929: Reviewer's commit (diff)
Solved bug if igraph is not installed
-rw-r--r--src/sage/graphs/digraph.py9
-rw-r--r--src/sage/graphs/generic_graph.py26
-rw-r--r--src/sage/graphs/graph.py9
3 files changed, 27 insertions, 17 deletions
diff --git a/src/sage/graphs/digraph.py b/src/sage/graphs/digraph.py
index a590afa..94bb4f2 100644
--- a/src/sage/graphs/digraph.py
+++ b/src/sage/graphs/digraph.py
@@ -632,9 +632,12 @@ class DiGraph(GenericGraph):
format = 'NX'
elif isinstance(data, (networkx.DiGraph, networkx.MultiDiGraph)):
format = 'NX'
- import igraph
- if format is None and isinstance(data, igraph.Graph):
- format = 'igraph'
+ try:
+ import igraph
+ if format is None and isinstance(data, igraph.Graph):
+ format = 'igraph'
+ except ImportError:
+ pass
if format is None and isinstance(data, (int, Integer)):
format = 'int'
if format is None and data is None:
diff --git a/src/sage/graphs/generic_graph.py b/src/sage/graphs/generic_graph.py
index 13ce7e7..97f87e6 100644
--- a/src/sage/graphs/generic_graph.py
+++ b/src/sage/graphs/generic_graph.py
@@ -1320,22 +1320,26 @@ class GenericGraph(GenericGraph_pyx):
EXAMPLES::
- sage: G = graphs.TetrahedralGraph()
- sage: H = G.igraph_graph()
- sage: H.summary()
+ sage: G = graphs.TetrahedralGraph() # optional - python_igraph
+ sage: H = G.igraph_graph() # optional - python_igraph
+ sage: H.summary() # optional - python_igraph
'IGRAPH U--- 4 6 -- '
- sage: G = digraphs.Path(3)
- sage: H = G.igraph_graph()
- sage: H.summary()
+ sage: G = digraphs.Path(3) # optional - python_igraph
+ sage: H = G.igraph_graph() # optional - python_igraph
+ sage: H.summary() # optional - python_igraph
'IGRAPH D--- 3 2 -- '
"""
- import igraph
- v_to_int = {v:i for i,v in enumerate(self.vertices())}
- edgelist = [(v_to_int[v],v_to_int[w])
+ try:
+ import igraph
+ v_to_int = {v:i for i,v in enumerate(self.vertices())}
+ edgelist = [(v_to_int[v],v_to_int[w])
for v,w in self.edges(labels=False)]
- g = igraph.Graph(edgelist, directed=self.is_directed())
- return g
+ return igraph.Graph(edgelist, directed=self.is_directed())
+ except ImportError:
+ raise ImportError("The package igraph is not available. To " +
+ "install it, run Sage with option -i " +
+ "python_igraph.")
def to_dictionary(self, edge_labels=False, multiple_edges=False):
r"""
diff --git a/src/sage/graphs/graph.py b/src/sage/graphs/graph.py
index 84a1151..bb11387 100644
--- a/src/sage/graphs/graph.py
+++ b/src/sage/graphs/graph.py
@@ -1177,9 +1177,12 @@ class Graph(GenericGraph):
data = data.to_undirected()
elif isinstance(data, (networkx.Graph, networkx.MultiGraph)):
format = 'NX'
- import igraph
- if format is None and isinstance(data, igraph.Graph):
- format = 'igraph'
+ try:
+ import igraph
+ if format is None and isinstance(data, igraph.Graph):
+ format = 'igraph'
+ except ImportError:
+ pass
if format is None and isinstance(data, (int, Integer)):
format = 'int'
if format is None and data is None: