Skip to content

Commit 09f7c4f

Browse files
committed
dev-python/networkx: Add from Gentoo
It's from Gentoo commit e5712a8fc3d0d429407ee9db8450b5c573041019.
1 parent bb96a7d commit 09f7c4f

File tree

4 files changed

+142
-0
lines changed

4 files changed

+142
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DIST networkx-3.5.tar.gz 2471065 BLAKE2B 575ac0a6e9741f0ad23396ff089cb360d43fc80f1c5a1fcb69e824c3673aba1aae5c2413020b049bcfecb68045984452eb02aefce1d523bd00d589eb26d8ae0f SHA512 9c060385913cfe67126e71eb9e53c032faa51c9609336ce78333d22e5f73078eb5b4826e0709cae0bd448fef2a5b2fb6f4c29be28c70d34a936d1cf6a00e83a1
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
From 5487e923e39f526fe12a74d7399e5153f06698a4 Mon Sep 17 00:00:00 2001
2+
From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= <[email protected]>
3+
Date: Tue, 3 Jun 2025 09:54:33 +0200
4+
Subject: [PATCH] Use type checks in `generators/lattice.py` for Py3.14 compat
5+
6+
Replace the `TypeError` catching in `networkx/generators/lattice.py`
7+
with explicit type checks to make the code more reliable and fix it for
8+
Python 3.14. Catching the exception immediately does not work
9+
in the second instance, because the code is constructing a generator,
10+
and apparently Python 3.14 does not evaluate the `p in periodic`
11+
expression until the generator is actually iterated over. Given that
12+
the function expects either an iterable or a `bool`, explicitly checking
13+
for `bool` should both be more readable and more reliable.
14+
15+
The alternative would be to replace the generator with a list
16+
comprehension that would be evaluated immediately. However,
17+
the explicit type check seems to be a cleaner solution to the problem.
18+
---
19+
networkx/generators/lattice.py | 12 ++++++------
20+
1 file changed, 6 insertions(+), 6 deletions(-)
21+
22+
diff --git a/networkx/generators/lattice.py b/networkx/generators/lattice.py
23+
index 95e520d2c..3b0900ea1 100644
24+
--- a/networkx/generators/lattice.py
25+
+++ b/networkx/generators/lattice.py
26+
@@ -67,10 +67,10 @@ def grid_2d_graph(m, n, periodic=False, create_using=None):
27+
G.add_edges_from(((i, j), (pi, j)) for pi, i in pairwise(rows) for j in cols)
28+
G.add_edges_from(((i, j), (i, pj)) for i in rows for pj, j in pairwise(cols))
29+
30+
- try:
31+
- periodic_r, periodic_c = periodic
32+
- except TypeError:
33+
+ if isinstance(periodic, bool):
34+
periodic_r = periodic_c = periodic
35+
+ else:
36+
+ periodic_r, periodic_c = periodic
37+
38+
if periodic_r and len(rows) > 2:
39+
first = rows[0]
40+
@@ -129,10 +129,10 @@ def grid_graph(dim, periodic=False):
41+
if not dim:
42+
return empty_graph(0)
43+
44+
- try:
45+
- func = (cycle_graph if p else path_graph for p in periodic)
46+
- except TypeError:
47+
+ if isinstance(periodic, bool):
48+
func = repeat(cycle_graph if periodic else path_graph)
49+
+ else:
50+
+ func = (cycle_graph if p else path_graph for p in periodic)
51+
52+
G = next(func)(dim[0])
53+
for current_dim in dim[1:]:
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE pkgmetadata SYSTEM "https://www.gentoo.org/dtd/metadata.dtd">
3+
<pkgmetadata>
4+
<maintainer type="project">
5+
<email>[email protected]</email>
6+
<name>Python</name>
7+
</maintainer>
8+
<longdescription lang="en">
9+
NetworkX is a Python-based package for the creation, manipulation, and
10+
study of the structure, dynamics, and functions of complex networks.
11+
The structure of a graph or network is encoded in the edges (connections,
12+
links, ties, arcs, bonds) between nodes (vertices, sites, actors). If
13+
unqualified, by graph we mean a simple undirected graph, i.e. no
14+
self-loops and no multiple edges are allowed. By a network we usually
15+
mean a graph with weights (fields, properties) on nodes and/or edges.
16+
The potential audience for NetworkX includes: mathematicians, physicists,
17+
biologists, computer scientists, social scientists.
18+
</longdescription>
19+
<stabilize-allarches/>
20+
<upstream>
21+
<remote-id type="pypi">networkx</remote-id>
22+
<remote-id type="github">networkx/networkx</remote-id>
23+
</upstream>
24+
</pkgmetadata>
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Copyright 1999-2025 Gentoo Authors
2+
# Distributed under the terms of the GNU General Public License v2
3+
4+
EAPI=8
5+
6+
DISTUTILS_USE_PEP517=setuptools
7+
PYTHON_FULLY_TESTED=( python3_{11..13} )
8+
PYTHON_COMPAT=( "${PYTHON_FULLY_TESTED[@]}" python3_14 )
9+
10+
inherit distutils-r1 optfeature pypi virtualx
11+
12+
DESCRIPTION="Python tools to manipulate graphs and complex networks"
13+
HOMEPAGE="
14+
https://networkx.org/
15+
https://github.com/networkx/networkx/
16+
https://pypi.org/project/networkx/
17+
"
18+
19+
LICENSE="BSD"
20+
SLOT="0"
21+
KEYWORDS="amd64 arm arm64 ~loong ~ppc64 ~riscv ~sparc x86 ~amd64-linux ~x86-linux ~ppc-macos ~x64-macos"
22+
23+
BDEPEND="
24+
test? (
25+
>=dev-python/lxml-4.6[${PYTHON_USEDEP}]
26+
$(python_gen_cond_dep '
27+
>=dev-python/matplotlib-3.8[${PYTHON_USEDEP}]
28+
>=dev-python/numpy-1.25[${PYTHON_USEDEP}]
29+
>=dev-python/scipy-1.11.2[${PYTHON_USEDEP}]
30+
' "${PYTHON_FULLY_TESTED[@]}")
31+
)
32+
"
33+
34+
EPYTEST_XDIST=1
35+
distutils_enable_tests pytest
36+
37+
PATCHES=(
38+
# minimal fix for https://github.com/networkx/networkx/issues/8091
39+
"${FILESDIR}/${P}-py314.patch"
40+
)
41+
42+
src_test() {
43+
virtx distutils-r1_src_test
44+
}
45+
46+
python_test() {
47+
local -x PYTEST_DISABLE_PLUGIN_AUTOLOAD=1
48+
# virtx implies nonfatal
49+
nonfatal epytest || die
50+
}
51+
52+
src_install() {
53+
distutils-r1_src_install
54+
# those examples use various assets and pre-compressed files
55+
docompress -x /usr/share/doc/${PF}/examples
56+
}
57+
58+
pkg_postinst() {
59+
optfeature "recommended dependencies" "dev-python/matplotlib dev-python/numpy dev-python/pandas dev-python/scipy"
60+
optfeature "graph drawing and graph layout algorithms" "dev-python/pygraphviz dev-python/pydot"
61+
optfeature "YAML format reading and writing" "dev-python/pyyaml"
62+
optfeature "shapefile format reading and writing" "sci-libs/gdal[python]"
63+
optfeature "GraphML XML format" "dev-python/lxml"
64+
}

0 commit comments

Comments
 (0)