diff --git a/networkx-pr4012-use-mpl.patch b/networkx-pr4012-use-mpl.patch new file mode 100644 index 0000000..eb1410f --- /dev/null +++ b/networkx-pr4012-use-mpl.patch @@ -0,0 +1,390 @@ +From 83bf28a8f46a311f2bc277eab66226f6b9117c1d Mon Sep 17 00:00:00 2001 +From: Ram Rachum +Date: Sun, 21 Jun 2020 22:24:11 +0300 +Subject: [PATCH 1/2] Fix exception causes and messages in 12 modules + +--- + examples/subclass/plot_antigraph.py | 4 +-- + .../algorithms/approximation/kcomponents.py | 4 +-- + .../algorithms/assortativity/correlation.py | 18 +++++----- + networkx/algorithms/bipartite/cluster.py | 4 +-- + networkx/algorithms/bipartite/edgelist.py | 19 +++++----- + networkx/algorithms/bipartite/matching.py | 4 +-- + networkx/algorithms/bipartite/matrix.py | 4 +-- + networkx/algorithms/bipartite/spectral.py | 4 +-- + .../centrality/current_flow_betweenness.py | 36 +++++++++---------- + .../current_flow_betweenness_subset.py | 20 +++++------ + networkx/algorithms/centrality/katz.py | 12 +++---- + .../algorithms/centrality/second_order.py | 4 +-- + 12 files changed, 68 insertions(+), 65 deletions(-) + +Index: networkx-2.4/examples/subclass/plot_antigraph.py +=================================================================== +--- networkx-2.4.orig/examples/subclass/plot_antigraph.py ++++ networkx-2.4/examples/subclass/plot_antigraph.py +@@ -71,8 +71,8 @@ class AntiGraph(nx.Graph): + """ + try: + return iter(set(self.adj) - set(self.adj[n]) - set([n])) +- except KeyError: +- raise NetworkXError("The node %s is not in the graph." % (n,)) ++ except KeyError as e: ++ raise NetworkXError("The node %s is not in the graph." % (n,)) from e + + def degree(self, nbunch=None, weight=None): + """Return an iterator for (node, degree) in the dense graph. +Index: networkx-2.4/networkx/algorithms/approximation/kcomponents.py +=================================================================== +--- networkx-2.4.orig/networkx/algorithms/approximation/kcomponents.py ++++ networkx-2.4/networkx/algorithms/approximation/kcomponents.py +@@ -245,8 +245,8 @@ class _AntiGraph(nx.Graph): + """ + try: + return iter(set(self._adj) - set(self._adj[n]) - set([n])) +- except KeyError: +- raise NetworkXError("The node %s is not in the graph." % (n,)) ++ except KeyError as e: ++ raise NetworkXError("The node %s is not in the graph." % (n,)) from e + + class AntiAtlasView(Mapping): + """An adjacency inner dict for AntiGraph""" +Index: networkx-2.4/networkx/algorithms/assortativity/correlation.py +=================================================================== +--- networkx-2.4.orig/networkx/algorithms/assortativity/correlation.py ++++ networkx-2.4/networkx/algorithms/assortativity/correlation.py +@@ -132,9 +132,9 @@ def degree_pearson_correlation_coefficie + """ + try: + import scipy.stats as stats +- except ImportError: +- raise ImportError( +- "Assortativity requires SciPy: http://scipy.org/ ") ++ except ImportError as e: ++ raise ImportError("Assortativity requires SciPy:" ++ "http://scipy.org/ ") from e + xy = node_degree_xy(G, x=x, y=y, nodes=nodes, weight=weight) + x, y = zip(*xy) + return stats.pearsonr(x, y)[0] +@@ -254,9 +254,9 @@ def attribute_ac(M): + """ + try: + import numpy +- except ImportError: +- raise ImportError( +- "attribute_assortativity requires NumPy: http://scipy.org/ ") ++ except ImportError as e: ++ raise ImportError('attribute_assortativity requires ' ++ 'NumPy: http://scipy.org/') from e + if M.sum() != 1.0: + M = M / float(M.sum()) + M = numpy.asmatrix(M) +@@ -271,9 +271,9 @@ def numeric_ac(M): + # numeric assortativity coefficient, pearsonr + try: + import numpy +- except ImportError: +- raise ImportError('numeric_assortativity requires ', +- 'NumPy: http://scipy.org/') ++ except ImportError as e: ++ raise ImportError('numeric_assortativity requires ' ++ 'NumPy: http://scipy.org/') from e + if M.sum() != 1.0: + M = M / float(M.sum()) + nx, ny = M.shape # nx=ny +Index: networkx-2.4/networkx/algorithms/bipartite/cluster.py +=================================================================== +--- networkx-2.4.orig/networkx/algorithms/bipartite/cluster.py ++++ networkx-2.4/networkx/algorithms/bipartite/cluster.py +@@ -115,9 +115,9 @@ def latapy_clustering(G, nodes=None, mod + + try: + cc_func = modes[mode] +- except KeyError: ++ except KeyError as e: + raise nx.NetworkXError( +- "Mode for bipartite clustering must be: dot, min or max") ++ "Mode for bipartite clustering must be: dot, min or max") from e + + if nodes is None: + nodes = G +Index: networkx-2.4/networkx/algorithms/bipartite/edgelist.py +=================================================================== +--- networkx-2.4.orig/networkx/algorithms/bipartite/edgelist.py ++++ networkx-2.4/networkx/algorithms/bipartite/edgelist.py +@@ -139,8 +139,8 @@ def generate_edgelist(G, delimiter=' ', + """ + try: + part0 = [n for n, d in G.nodes.items() if d['bipartite'] == 0] +- except: +- raise AttributeError("Missing node attribute `bipartite`") ++ except BaseException as e: ++ raise AttributeError("Missing node attribute `bipartite`") from e + if data is True or data is False: + for n in part0: + for e in G.edges(n, data=data): +@@ -242,9 +242,9 @@ def parse_edgelist(lines, comments='#', + try: + u = nodetype(u) + v = nodetype(v) +- except: ++ except BaseException as e: + raise TypeError("Failed to convert nodes %s,%s to type %s." +- % (u, v, nodetype)) ++ % (u, v, nodetype)) from e + + if len(d) == 0 or data is False: + # no data or data type specified +@@ -253,9 +253,9 @@ def parse_edgelist(lines, comments='#', + # no edge types specified + try: # try to evaluate as dictionary + edgedata = dict(literal_eval(' '.join(d))) +- except: +- raise TypeError( +- "Failed to convert edge data (%s) to dictionary." % (d)) ++ except BaseException as e: ++ raise TypeError("Failed to convert edge data" ++ " (%s) to dictionary." % (d)) from e + else: + # convert edge data to dictionary with specified keys and type + if len(d) != len(data): +@@ -266,10 +266,10 @@ def parse_edgelist(lines, comments='#', + for (edge_key, edge_type), edge_value in zip(data, d): + try: + edge_value = edge_type(edge_value) +- except: ++ except BaseException as e: + raise TypeError( + "Failed to convert %s data %s to type %s." +- % (edge_key, edge_value, edge_type)) ++ % (edge_key, edge_value, edge_type)) from e + edgedata.update({edge_key: edge_value}) + G.add_node(u, bipartite=0) + G.add_node(v, bipartite=1) +Index: networkx-2.4/networkx/algorithms/bipartite/matching.py +=================================================================== +--- networkx-2.4.orig/networkx/algorithms/bipartite/matching.py ++++ networkx-2.4/networkx/algorithms/bipartite/matching.py +@@ -555,9 +555,9 @@ def minimum_weight_full_matching(G, top_ + """ + try: + import scipy.optimize +- except ImportError: ++ except ImportError as e: + raise ImportError('minimum_weight_full_matching requires SciPy: ' + +- 'https://scipy.org/') ++ 'https://scipy.org/') from e + left, right = nx.bipartite.sets(G, top_nodes) + # Ensure that the graph is complete. This is currently a requirement in + # the underlying optimization algorithm from SciPy, but the constraint +Index: networkx-2.4/networkx/algorithms/bipartite/matrix.py +=================================================================== +--- networkx-2.4.orig/networkx/algorithms/bipartite/matrix.py ++++ networkx-2.4/networkx/algorithms/bipartite/matrix.py +@@ -109,8 +109,9 @@ def biadjacency_matrix(G, row_order, col + return M.asformat(format) + # From Scipy 1.1.0, asformat will throw a ValueError instead of an + # AttributeError if the format if not recognized. +- except (AttributeError, ValueError): +- raise nx.NetworkXError("Unknown sparse matrix format: %s" % format) ++ except (AttributeError, ValueError) as e: ++ raise nx.NetworkXError( ++ "Unknown sparse matrix format: %s" % format) from e + + + def from_biadjacency_matrix(A, create_using=None, edge_attribute='weight'): +Index: networkx-2.4/networkx/algorithms/bipartite/spectral.py +=================================================================== +--- networkx-2.4.orig/networkx/algorithms/bipartite/spectral.py ++++ networkx-2.4/networkx/algorithms/bipartite/spectral.py +@@ -56,9 +56,9 @@ def spectral_bipartivity(G, nodes=None, + """ + try: + import scipy.linalg +- except ImportError: ++ except ImportError as e: + raise ImportError('spectral_bipartivity() requires SciPy: ', +- 'http://scipy.org/') ++ 'http://scipy.org/') from e + nodelist = list(G) # ordering of nodes in matrix + A = nx.to_numpy_matrix(G, nodelist, weight=weight) + expA = scipy.linalg.expm(A) +Index: networkx-2.4/networkx/algorithms/centrality/current_flow_betweenness.py +=================================================================== +--- networkx-2.4.orig/networkx/algorithms/centrality/current_flow_betweenness.py ++++ networkx-2.4/networkx/algorithms/centrality/current_flow_betweenness.py +@@ -90,15 +90,15 @@ def approximate_current_flow_betweenness + """ + try: + import numpy as np +- except ImportError: +- raise ImportError('current_flow_betweenness_centrality requires NumPy ', +- 'http://scipy.org/') ++ except ImportError as e: ++ raise ImportError('current_flow_betweenness_centrality requires NumPy ' ++ 'http://scipy.org/') from e + try: + from scipy import sparse + from scipy.sparse import linalg +- except ImportError: +- raise ImportError('current_flow_betweenness_centrality requires SciPy ', +- 'http://scipy.org/') ++ except ImportError as e: ++ raise ImportError('current_flow_betweenness_centrality requires SciPy ' ++ 'http://scipy.org/') from e + if not nx.is_connected(G): + raise nx.NetworkXError("Graph not connected.") + solvername = {"full": FullInverseLaplacian, +@@ -214,14 +214,14 @@ def current_flow_betweenness_centrality( + """ + try: + import numpy as np +- except ImportError: +- raise ImportError('current_flow_betweenness_centrality requires NumPy ', +- 'http://scipy.org/') ++ except ImportError as e: ++ raise ImportError('current_flow_betweenness_centrality requires NumPy ' ++ 'http://scipy.org/') from e + try: + import scipy +- except ImportError: +- raise ImportError('current_flow_betweenness_centrality requires SciPy ', +- 'http://scipy.org/') ++ except ImportError as e: ++ raise ImportError('current_flow_betweenness_centrality requires SciPy ' ++ 'http://scipy.org/') from e + if not nx.is_connected(G): + raise nx.NetworkXError("Graph not connected.") + n = G.number_of_nodes() +@@ -326,14 +326,14 @@ def edge_current_flow_betweenness_centra + from networkx.utils import reverse_cuthill_mckee_ordering + try: + import numpy as np +- except ImportError: +- raise ImportError('current_flow_betweenness_centrality requires NumPy ', +- 'http://scipy.org/') ++ except ImportError as e: ++ raise ImportError('current_flow_betweenness_centrality requires NumPy ' ++ 'http://scipy.org/') from e + try: + import scipy +- except ImportError: +- raise ImportError('current_flow_betweenness_centrality requires SciPy ', +- 'http://scipy.org/') ++ except ImportError as e: ++ raise ImportError('current_flow_betweenness_centrality requires SciPy ' ++ 'http://scipy.org/') from e + if not nx.is_connected(G): + raise nx.NetworkXError("Graph not connected.") + n = G.number_of_nodes() +Index: networkx-2.4/networkx/algorithms/centrality/current_flow_betweenness_subset.py +=================================================================== +--- networkx-2.4.orig/networkx/algorithms/centrality/current_flow_betweenness_subset.py ++++ networkx-2.4/networkx/algorithms/centrality/current_flow_betweenness_subset.py +@@ -99,14 +99,14 @@ def current_flow_betweenness_centrality_ + from networkx.utils import reverse_cuthill_mckee_ordering + try: + import numpy as np +- except ImportError: ++ except ImportError as e: + raise ImportError('current_flow_betweenness_centrality requires NumPy ', +- 'http://scipy.org/') ++ 'http://scipy.org/') from e + try: + import scipy +- except ImportError: ++ except ImportError as e: + raise ImportError('current_flow_betweenness_centrality requires SciPy ', +- 'http://scipy.org/') ++ 'http://scipy.org/') from e + if not nx.is_connected(G): + raise nx.NetworkXError("Graph not connected.") + n = G.number_of_nodes() +@@ -214,14 +214,14 @@ def edge_current_flow_betweenness_centra + """ + try: + import numpy as np +- except ImportError: +- raise ImportError('current_flow_betweenness_centrality requires NumPy ', +- 'http://scipy.org/') ++ except ImportError as e: ++ raise ImportError('current_flow_betweenness_centrality requires NumPy ' ++ 'http://scipy.org/') from e + try: + import scipy +- except ImportError: +- raise ImportError('current_flow_betweenness_centrality requires SciPy ', +- 'http://scipy.org/') ++ except ImportError as e: ++ raise ImportError('current_flow_betweenness_centrality requires SciPy ' ++ 'http://scipy.org/') from e + if not nx.is_connected(G): + raise nx.NetworkXError("Graph not connected.") + n = G.number_of_nodes() +Index: networkx-2.4/networkx/algorithms/centrality/katz.py +=================================================================== +--- networkx-2.4.orig/networkx/algorithms/centrality/katz.py ++++ networkx-2.4/networkx/algorithms/centrality/katz.py +@@ -160,11 +160,11 @@ def katz_centrality(G, alpha=0.1, beta=1 + + try: + b = dict.fromkeys(G, float(beta)) +- except (TypeError, ValueError, AttributeError): ++ except (TypeError, ValueError, AttributeError) as e: + b = beta + if set(beta) != set(G): + raise nx.NetworkXError('beta dictionary ' +- 'must have a value for every node') ++ 'must have a value for every node') from e + + # make up to max_iter iterations + for i in range(max_iter): +@@ -308,8 +308,8 @@ def katz_centrality_numpy(G, alpha=0.1, + """ + try: + import numpy as np +- except ImportError: +- raise ImportError('Requires NumPy: http://scipy.org/') ++ except ImportError as e: ++ raise ImportError('Requires NumPy: http://numpy.org/') from e + if len(G) == 0: + return {} + try: +@@ -322,8 +322,8 @@ def katz_centrality_numpy(G, alpha=0.1, + nodelist = list(G) + try: + b = np.ones((len(nodelist), 1)) * float(beta) +- except (TypeError, ValueError, AttributeError): +- raise nx.NetworkXError('beta must be a number') ++ except (TypeError, ValueError, AttributeError) as e: ++ raise nx.NetworkXError('beta must be a number') from e + + A = nx.adj_matrix(G, nodelist=nodelist, weight=weight).todense().T + n = A.shape[0] +Index: networkx-2.4/networkx/algorithms/centrality/second_order.py +=================================================================== +--- networkx-2.4.orig/networkx/algorithms/centrality/second_order.py ++++ networkx-2.4/networkx/algorithms/centrality/second_order.py +@@ -99,8 +99,8 @@ def second_order_centrality(G): + + try: + import numpy as np +- except ImportError: +- raise ImportError('Requires NumPy: http://scipy.org/') ++ except ImportError as e: ++ raise ImportError('Requires NumPy: http://numpy.org/') from e + + n = len(G) + +Index: networkx-2.4/networkx/drawing/tests/test_pylab.py +=================================================================== +--- networkx-2.4.orig/networkx/drawing/tests/test_pylab.py ++++ networkx-2.4/networkx/drawing/tests/test_pylab.py +@@ -4,7 +4,7 @@ import itertools + import pytest + + mpl = pytest.importorskip('matplotlib') +-mpl.use('PS', warn=False) ++mpl.use('PS') + plt = pytest.importorskip('matplotlib.pyplot') + plt.rcParams['text.usetex'] = False + diff --git a/python-networkx.changes b/python-networkx.changes index 98c40dd..191a17a 100644 --- a/python-networkx.changes +++ b/python-networkx.changes @@ -1,3 +1,9 @@ +------------------------------------------------------------------- +Tue Jul 21 16:10:13 UTC 2020 - Benjamin Greiner + +- gh#networkx/networkx#4012 networkx-pr4012-use-mpl.patch + new matplotlib removed keyword argument 'warn' for mpl.use() + ------------------------------------------------------------------- Tue Jul 7 20:31:26 UTC 2020 - Matej Cepl diff --git a/python-networkx.spec b/python-networkx.spec index 9065604..a0a496b 100644 --- a/python-networkx.spec +++ b/python-networkx.spec @@ -29,6 +29,8 @@ Source: https://files.pythonhosted.org/packages/source/n/networkx/networ Patch0: numpy-38-test.patch # UPSTREAM PATCH: gh#networkx/networkx#3697 Patch1: matplotlib.patch +# UPSTREAM PATCH: gh#networkx/networkx#4012 +Patch2: networkx-pr4012-use-mpl.patch BuildRequires: %{python_module PyYAML} BuildRequires: %{python_module decorator >= 3.4.0} BuildRequires: %{python_module matplotlib >= 3.1}