nodes: 0, module; 1, function_definition; 2, function_name:sort_by_dependencies; 3, parameters; 4, block; 5, identifier:exts; 6, default_parameter; 7, expression_statement; 8, expression_statement; 9, expression_statement; 10, expression_statement; 11, while_statement; 12, return_statement; 13, identifier:retry; 14, None; 15, comment:"""Calculate the Feature Extractor Resolution Order.
  
      """; 16, assignment; 17, assignment; 18, assignment; 19, identifier:pending; 20, block; 21, call; 22, pattern_list; 23, expression_list; 24, identifier:pending; 25, list_comprehension; 26, identifier:retry; 27, conditional_expression:len(exts) * 100 if retry is None else retry; 28, expression_statement; 29, if_statement; 30, expression_statement; 31, if_statement; 32, identifier:tuple; 33, argument_list; 34, identifier:sorted_ext; 35, identifier:features_from_sorted; 36, list; 37, call; 38, tuple; 39, for_in_clause; 40, binary_operator:len(exts) * 100; 41, comparison_operator:retry is None; 42, identifier:retry; 43, assignment; 44, boolean_operator; 45, block; 46, assignment; 47, call; 48, block; 49, else_clause; 50, identifier:sorted_ext; 51, identifier:set; 52, argument_list; 53, identifier:e; 54, integer:0; 55, identifier:e; 56, identifier:exts; 57, call; 58, integer:100; 59, identifier:retry; 60, None; 61, pattern_list; 62, call; 63, not_operator; 64, not_operator; 65, expression_statement; 66, raise_statement; 67, identifier:deps; 68, call; 69, attribute; 70, argument_list; 71, if_statement; 72, expression_statement; 73, block; 74, identifier:len; 75, argument_list; 76, identifier:ext; 77, identifier:cnt; 78, attribute; 79, argument_list; 80, call; 81, call; 82, assignment; 83, call; 84, attribute; 85, argument_list; 86, identifier:deps; 87, identifier:difference; 88, identifier:features_from_sorted; 89, comparison_operator:cnt + 1 > retry; 90, block; 91, call; 92, expression_statement; 93, expression_statement; 94, identifier:exts; 95, identifier:pending; 96, identifier:pop; 97, integer:0; 98, identifier:isinstance; 99, argument_list; 100, identifier:issubclass; 101, argument_list; 102, identifier:msg; 103, string:"Only Extractor instances are allowed. Found {}."; 104, identifier:TypeError; 105, argument_list; 106, identifier:ext; 107, identifier:get_dependencies; 108, binary_operator:cnt + 1; 109, identifier:retry; 110, expression_statement; 111, raise_statement; 112, attribute; 113, argument_list; 114, call; 115, call; 116, identifier:ext; 117, identifier:Extractor; 118, identifier:ext; 119, identifier:Extractor; 120, call; 121, identifier:cnt; 122, integer:1; 123, assignment; 124, call; 125, identifier:pending; 126, identifier:append; 127, tuple; 128, attribute; 129, argument_list; 130, attribute; 131, argument_list; 132, attribute; 133, argument_list; 134, identifier:msg; 135, string:"Maximun retry ({}) to sort achieved from extractor {}."; 136, identifier:RuntimeError; 137, argument_list; 138, identifier:ext; 139, binary_operator:cnt + 1; 140, identifier:sorted_ext; 141, identifier:append; 142, identifier:ext; 143, identifier:features_from_sorted; 144, identifier:update; 145, call; 146, identifier:msg; 147, identifier:format; 148, call; 149, call; 150, identifier:cnt; 151, integer:1; 152, attribute; 153, argument_list; 154, identifier:type; 155, argument_list; 156, attribute; 157, argument_list; 158, identifier:ext; 159, identifier:get_features; 160, identifier:ext; 161, identifier:msg; 162, identifier:format; 163, identifier:retry; 164, call; 165, identifier:type; 166, argument_list; 167, identifier:ext
code: def sort_by_dependencies(exts, retry=None):
      """Calculate the Feature Extractor Resolution Order.
  
      """
      sorted_ext, features_from_sorted = [], set()
      pending = [(e, 0) for e in exts]
      retry = len(exts) * 100 if retry is None else retry
      while pending:
          ext, cnt = pending.pop(0)
  
          if not isinstance(ext, Extractor) and not issubclass(ext, Extractor):
              msg = "Only Extractor instances are allowed. Found {}."
              raise TypeError(msg.format(type(ext)))
  
          deps = ext.get_dependencies()
          if deps.difference(features_from_sorted):
              if cnt + 1 > retry:
                  msg = "Maximun retry ({}) to sort achieved from extractor {}."
                  raise RuntimeError(msg.format(retry, type(ext)))
              pending.append((ext, cnt + 1))
          else:
              sorted_ext.append(ext)
              features_from_sorted.update(ext.get_features())
      return tuple(sorted_ext)