4
4
from collections import defaultdict
5
5
from .errors import DataJointError
6
6
7
+
7
8
def extract_master (part_table ):
8
9
"""
9
- given a part table name, return master part. None if not a part table
10
+ given a part table name, return master part. None if not a part table
10
11
"""
11
12
match = re .match (r"(?P<master>`\w+`.`#?\w+)__\w+`" , part_table )
12
- return match ['master' ] + '`' if match else None
13
-
13
+ return match ["master" ] + "`" if match else None
14
14
15
15
16
16
def topo_sort (graph ):
@@ -39,22 +39,19 @@ def topo_sort(graph):
39
39
# to ensure correct topological ordering of the masters.
40
40
for part in graph :
41
41
# find the part's master
42
- master = extract_master (part )
43
- if master :
42
+ if (master := extract_master (part )) in graph :
44
43
for edge in graph .in_edges (part ):
45
44
parent = edge [0 ]
46
45
if parent != master and extract_master (parent ) != master :
47
46
graph .add_edge (parent , master )
48
-
49
47
sorted_nodes = list (nx .topological_sort (graph ))
50
48
51
49
# bring parts up to their masters
52
50
pos = len (sorted_nodes ) - 1
53
51
placed = set ()
54
52
while pos > 1 :
55
53
part = sorted_nodes [pos ]
56
- master = extract_master (part )
57
- if not master or part in placed :
54
+ if not (master := extract_master ) or part in placed :
58
55
pos -= 1
59
56
else :
60
57
placed .add (part )
@@ -63,7 +60,7 @@ def topo_sort(graph):
63
60
except ValueError :
64
61
# master not found
65
62
pass
66
- else :
63
+ else :
67
64
if pos > j + 1 :
68
65
# move the part to its master
69
66
del sorted_nodes [pos ]
@@ -214,8 +211,8 @@ def descendants(self, full_table_name):
214
211
:return: all dependent tables sorted in topological order. Self is included.
215
212
"""
216
213
self .load (force = False )
217
- nodes = self .subgraph (nx .descendants (self , full_table_name ))
218
- return [full_table_name ] + nodes .topo_sort ()
214
+ nodes = self .subgraph (nx .descendants (self , full_table_name ))
215
+ return [full_table_name ] + nodes .topo_sort ()
219
216
220
217
def ancestors (self , full_table_name ):
221
218
"""
0 commit comments