def _get_dependencies(documents, deps_mode=True):
 doc_set = set()
 for doc in documents:
  stack = [doc]
  while stack:
   curr_doc = stack.pop()
   if ((curr_doc not in doc_set) and (not curr_doc.is_history)):
    doc_set.add(curr_doc)
    if deps_mode:
     deps_set = set(curr_doc.dependencies.all())
    else:
     deps_set = set(curr_doc.children.all())
    stack.extend((deps_set - doc_set))
 return doc_set

def _get_dependencies ( documents , deps_mode = True ) : doc_set = set ( ) for doc in documents : stack = [ doc ] while stack : curr_doc = stack . pop ( ) if ( ( curr_doc not in doc_set ) and ( not curr_doc . is_history ) ) : doc_set . add ( curr_doc ) if deps_mode : deps_set = set ( curr_doc . dependencies . all ( ) ) else : deps_set = set ( curr_doc . children . all ( ) ) stack . extend ( ( deps_set - doc_set ) ) return doc_set
given a list of document2 objects .