5151#: is augmented with children's details.
5252log = logging .getLogger (__name__ )
5353
54+ NODE_TYPE = {0 : "dependency" , 1 : "operation" }
55+
5456
5557def yield_datanodes (nodes ) -> List [str ]:
5658 """May scan dag nodes."""
@@ -497,16 +499,34 @@ def append_subdoc_chain(doc_parts):
497499 doc_chain = [p for p in doc_chain if p ]
498500 graph .add_edges_from (unseen_subdoc_edges (pairwise (doc_chain )))
499501
502+ node_types = graph .nodes (data = "typ" ) # a view to check for collisions
503+
504+ def check_node_collision (
505+ node , node_type : int , dep_op = None , dep_kind : str = None
506+ ):
507+ """The dep_op/dep_kind are given only for data-nodes."""
508+ if node in node_types and node_types [node ] != node_type :
509+ assert not (bool (dep_op ) ^ bool (dep_kind )), locals ()
510+ graph_type = NODE_TYPE [node_types [node ]]
511+ given_node = (
512+ f"{ dep_kind } ({ node !r} )" if dep_op else f"operation({ node .name } )"
513+ )
514+ dep_op = f"\n +--owning op: { dep_op } " if dep_op else ""
515+ raise ValueError (
516+ f"Name of { given_node } clashed with a same-named { graph_type } in graph!{ dep_op } "
517+ )
518+
500519 ## Needs
501520 #
502521 needs = []
503522 needs_edges = []
504523 for n in operation .needs :
505524 json_path = get_jsonp (n )
525+ check_node_collision (n , 0 , operation , "needs" )
506526 if json_path :
507527 append_subdoc_chain (json_path )
508528
509- nkw , ekw = {}, {} # node, edge props
529+ nkw , ekw = {"typ" : 0 }, {} # node, edge props
510530 if is_optional (n ):
511531 ekw ["optional" ] = True
512532 if is_sfx (n ):
@@ -520,7 +540,8 @@ def append_subdoc_chain(doc_parts):
520540 needs_edges .append ((n , operation , ekw ))
521541 graph .add_nodes_from (needs )
522542 node_props = getattr (operation , "node_props" , None ) or {}
523- graph .add_node (operation , ** node_props )
543+ check_node_collision (operation , 1 )
544+ graph .add_node (operation , typ = 1 , ** node_props )
524545 graph .add_edges_from (needs_edges )
525546
526547 ## Prepare inversed-aliases index, used
@@ -533,20 +554,21 @@ def append_subdoc_chain(doc_parts):
533554 #
534555 for n in operation .provides :
535556 json_path = get_jsonp (n )
557+ check_node_collision (n , 0 , operation , "provides" )
536558 if json_path :
537559 append_subdoc_chain (json_path )
538560
539- kw = {}
561+ nkw , ekw = { "typ" : 0 }, {}
540562 if is_sfx (n ):
541- kw ["sideffect" ] = True
542- graph .add_node (n , sideffect = True )
563+ ekw ["sideffect" ] = nkw ["sideffect" ] = True
543564 if is_implicit (n ):
544- kw ["implicit" ] = True
565+ ekw ["implicit" ] = True
545566
546567 if n in alias_destinations :
547- kw ["alias_of" ] = alias_destinations [n ]
568+ ekw ["alias_of" ] = alias_destinations [n ]
548569
549- graph .add_edge (operation , n , ** kw )
570+ graph .add_node (n , ** nkw )
571+ graph .add_edge (operation , n , ** ekw )
550572
551573 def _apply_graph_predicate (self , graph , predicate ):
552574 to_del = []
0 commit comments