nodes: 0, module; 1, function_definition; 2, function_name:get_imported_modules; 3, parameters; 4, block; 5, identifier:cells; 6, default_parameter; 7, expression_statement; 8, expression_statement; 9, expression_statement; 10, expression_statement; 11, expression_statement; 12, comment:# Imports parent modules - a.b.c = [a, a.b, a.b.c]; 13, expression_statement; 14, expression_statement; 15, return_statement; 16, identifier:nb_module_name; 17, string; 18, string:"Finds all submodules of notebook - sorted by submodules > top level modules > manual imports. This gives notebook imports priority"; 19, assignment; 20, assignment; 21, assignment; 22, assignment; 23, assignment; 24, assignment; 25, list_comprehension; 26, identifier:module_names; 27, call; 28, identifier:nb_imports; 29, list_comprehension; 30, identifier:parts; 31, call; 32, identifier:parent_modules; 33, list_comprehension; 34, identifier:all_modules; 35, binary_operator:module_names + nb_imports + parent_modules; 36, identifier:mods; 37, list_comprehension; 38, identifier:m; 39, for_in_clause; 40, if_clause; 41, identifier:get_top_level_modules; 42, argument_list; 43, call; 44, for_in_clause; 45, for_in_clause; 46, if_clause; 47, attribute; 48, argument_list; 49, call; 50, for_in_clause; 51, binary_operator:module_names + nb_imports; 52, identifier:parent_modules; 53, call; 54, for_in_clause; 55, identifier:m; 56, identifier:mods; 57, comparison_operator:m is not None; 58, attribute; 59, argument_list; 60, identifier:cell; 61, identifier:cells; 62, identifier:match; 63, call; 64, comparison_operator:cell['cell_type'] == 'code'; 65, identifier:nb_module_name; 66, identifier:split; 67, string; 68, attribute; 69, argument_list; 70, identifier:x; 71, call; 72, identifier:module_names; 73, identifier:nb_imports; 74, identifier:import_mod; 75, argument_list; 76, identifier:m; 77, identifier:all_modules; 78, identifier:m; 79, None; 80, identifier:match; 81, identifier:group; 82, integer:1; 83, attribute; 84, argument_list; 85, subscript; 86, string; 87, string_content:.; 88, string; 89, identifier:join; 90, subscript; 91, identifier:range_of; 92, argument_list; 93, identifier:m; 94, keyword_argument; 95, identifier:IMPORT_RE; 96, identifier:finditer; 97, subscript; 98, identifier:cell; 99, string; 100, string_content:code; 101, string_content:.; 102, identifier:parts; 103, slice; 104, identifier:parts; 105, identifier:ignore_errors; 106, True; 107, identifier:cell; 108, string; 109, string_content:cell_type; 110, parenthesized_expression; 111, string_content:source; 112, binary_operator:x+1; 113, identifier:x; 114, integer:1
code: def get_imported_modules(cells, nb_module_name=''):
      "Finds all submodules of notebook - sorted by submodules > top level modules > manual imports. This gives notebook imports priority"
      module_names = get_top_level_modules()
      nb_imports = [match.group(1) for cell in cells for match in IMPORT_RE.finditer(cell['source']) if cell['cell_type'] == 'code']
      parts = nb_module_name.split('.')
      parent_modules = ['.'.join(parts[:(x+1)]) for x in range_of(parts)] # Imports parent modules - a.b.c = [a, a.b, a.b.c]
      all_modules = module_names + nb_imports + parent_modules
      mods = [import_mod(m, ignore_errors=True) for m in all_modules]
      return [m for m in mods if m is not None]