#NEWLINE# @ classmethod #NEWLINE# def make_group_dependencies_explicit_for_items( cls , items ) : #NEWLINE# #INDENT# allitems = items #NEWLINE# items = set ( ( k for k in allitems if ( isinstance ( k , Item ) or ( ( type ( k ) == type ) and issubclass ( k , Item ) ) ) ) ) #NEWLINE# groups = set ( ( k for k in allitems if ( isinstance ( k , Group ) or ( ( type ( k ) == type ) and issubclass ( k , Group ) ) ) ) ) #NEWLINE# ( origitems , origgroups ) = ( set ( items ) , set ( groups ) ) #NEWLINE# assert ( allitems == items . union ( groups ) ) #NEWLINE# assert items . isdisjoint ( groups ) #NEWLINE# contained_by = defaultdict ( set ) #NEWLINE# def iter_group_contents( group ) : #NEWLINE# #INDENT# for k in group . contains : #NEWLINE# #INDENT# if ( k in groups ) : #NEWLINE# #INDENT# for kk in iter_group_contents ( k ) : #NEWLINE# #INDENT# ( yield kk ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# ( yield k ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# for group in groups : #NEWLINE# #INDENT# for k in iter_group_contents ( group ) : #NEWLINE# #INDENT# contained_by [ k ] . add ( group ) #NEWLINE# #UNINDENT# #UNINDENT# for ( item , ingroups ) in contained_by . items ( ) : #NEWLINE# #INDENT# assert ingroups . issubset ( groups ) #NEWLINE# new_deps = set ( item . depends ) #NEWLINE# for g in ingroups : #NEWLINE# #INDENT# new_deps . update ( g . depends ) #NEWLINE# #UNINDENT# item . depends = tuple ( new_deps ) #NEWLINE# #UNINDENT# for group in groups : #NEWLINE# #INDENT# group . contains = set ( group . contains ) #NEWLINE# while ( not group . contains . isdisjoint ( groups ) ) : #NEWLINE# #INDENT# for containedgroup in group . contains . intersection ( groups ) : #NEWLINE# #INDENT# assert ( containedgroup != group ) #NEWLINE# group . contains . update ( containedgroup . contains ) #NEWLINE# group . contains . remove ( containedgroup ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# for item in items . difference ( groups ) : #NEWLINE# #INDENT# assert ( item not in groups ) #NEWLINE# if ( not groups . isdisjoint ( item . depends ) ) : #NEWLINE# #INDENT# item . depends = set ( item . depends ) #NEWLINE# for groupdep in item . depends . intersection ( groups ) : #NEWLINE# #INDENT# item . depends . update ( groupdep . contains ) #NEWLINE# item . depends . remove ( groupdep ) #NEWLINE# #UNINDENT# item . depends = tuple ( item . depends ) #NEWLINE# #UNINDENT# assert groups . isdisjoint ( item . depends ) #NEWLINE# #UNINDENT# assert ( items == origitems ) #NEWLINE# assert ( groups == origgroups ) #NEWLINE# assert ( allitems == items . union ( groups ) ) #NEWLINE# assert items . isdisjoint ( groups ) #NEWLINE# assert ( items == allitems . difference ( groups ) ) #NEWLINE# return ingroups