Mercurial > repos > shellac > guppy_basecaller
comparison env/lib/python3.7/site-packages/networkx/utils/contextmanagers.py @ 5:9b1c78e6ba9c draft default tip
"planemo upload commit 6c0a8142489327ece472c84e558c47da711a9142"
| author | shellac |
|---|---|
| date | Mon, 01 Jun 2020 08:59:25 -0400 |
| parents | 79f47841a781 |
| children |
comparison
equal
deleted
inserted
replaced
| 4:79f47841a781 | 5:9b1c78e6ba9c |
|---|---|
| 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 |
