@@ -492,7 +492,14 @@ def __init__(self,
492492 cycles = list (nx .simple_cycles (dep_graph ))
493493 if cycles :
494494 cycles_str = '\n - ' .join (' -> ' .join (reversed (c )) + ' -> ' + c [- 1 ] for c in cycles )
495- raise BuildingBlockError (f"Circular dependencies found: \n - { cycles_str } " )
495+ print ("=== WARNING!! ===" , file = sys .stderr )
496+ print (f"Circular dependencies found: \n - { cycles_str } " , file = sys .stderr )
497+ print ("Circular dependency support is experimental" , file = sys .stderr )
498+ print ("=== WARNING!! ===" , file = sys .stderr )
499+ while cycles :
500+ for cycle in cycles :
501+ dep_graph .remove_edge (cycle [0 ], cycle [1 ])
502+ cycles = list (nx .simple_cycles (dep_graph ))
496503 self .bblocks : dict [str , BuildingBlock ] = {b : self .bblocks [b ]
497504 for b in nx .topological_sort (dep_graph )
498505 if b in self .bblocks }
@@ -558,7 +565,7 @@ def _resolve_bblock_deps(self, bblock: BuildingBlock) -> set[str]:
558565 return dependencies
559566
560567 @lru_cache
561- def find_dependencies (self , identifier : str ) -> list [dict | BuildingBlock ]:
568+ def find_dependencies (self , identifier : str , seen : tuple [ str ] = None ) -> list [dict | BuildingBlock ]:
562569 if identifier in self .bblocks :
563570 bblock = self .bblocks [identifier ]
564571 metadata = bblock .metadata
@@ -569,8 +576,10 @@ def find_dependencies(self, identifier: str) -> list[dict | BuildingBlock]:
569576 return []
570577
571578 dependencies = [bblock or metadata ]
579+ seen = (identifier ,) if not seen else seen + (identifier ,)
572580 for d in metadata .get ('dependsOn' , ()):
573- dependencies .extend (self .find_dependencies (d ))
581+ if d not in seen :
582+ dependencies .extend (self .find_dependencies (d , seen = seen ))
574583
575584 return dependencies
576585
0 commit comments