Mercurial > repos > shellac > guppy_basecaller
comparison env/lib/python3.7/site-packages/networkx/utils/contextmanagers.py @ 0:26e78fe6e8c4 draft
"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
author | shellac |
---|---|
date | Sat, 02 May 2020 07:14:21 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:26e78fe6e8c4 |
---|---|
1 | |
2 from contextlib import contextmanager | |
3 | |
4 __all__ = [ | |
5 'reversed', | |
6 ] | |
7 | |
8 | |
9 @contextmanager | |
10 def reversed(G): | |
11 """A context manager for temporarily reversing a directed graph in place. | |
12 | |
13 This is a no-op for undirected graphs. | |
14 | |
15 Parameters | |
16 ---------- | |
17 G : graph | |
18 A NetworkX graph. | |
19 """ | |
20 directed = G.is_directed() | |
21 if directed: | |
22 G._pred, G._succ = G._succ, G._pred | |
23 G._adj = G._succ | |
24 | |
25 try: | |
26 yield | |
27 finally: | |
28 if directed: | |
29 # Reverse the reverse. | |
30 G._pred, G._succ = G._succ, G._pred | |
31 G._adj = G._succ |