nodes: 0, module; 1, function_definition; 2, function_name:import_directory; 3, parameters; 4, type; 5, block; 6, typed_parameter; 7, typed_parameter; 8, default_parameter; 9, None; 10, expression_statement; 11, expression_statement; 12, expression_statement; 13, expression_statement; 14, expression_statement; 15, for_statement; 16, identifier:module_basename; 17, type; 18, identifier:directory; 19, type; 20, identifier:sort_key; 21, None; 22, string; 23, call; 24, call; 25, assignment; 26, assignment; 27, identifier:modulename; 28, call; 29, block; 30, identifier:str; 31, identifier:str; 32, string_content:Load all python modules in directory and directory's children.
  
      Parameters
      ----------
  
      :``module_basename``: module name prefix for loaded modules
      :``directory``:       directory to load python modules from
      :``sort_key``:        function to sort module names with before loading; 33, attribute; 34, argument_list; 35, attribute; 36, argument_list; 37, identifier:filenames; 38, call; 39, identifier:modulenames; 40, call; 41, identifier:sorted; 42, argument_list; 43, try_statement; 44, identifier:logger; 45, identifier:info; 46, string; 47, identifier:module_basename; 48, identifier:logger; 49, identifier:info; 50, string; 51, identifier:directory; 52, attribute; 53, argument_list; 54, identifier:_filenames_to_modulenames; 55, argument_list; 56, identifier:modulenames; 57, keyword_argument; 58, block; 59, except_clause; 60, else_clause; 61, string_content:loading submodules of %s; 62, string_content:loading modules from %s; 63, identifier:itertools; 64, identifier:chain; 65, list_splat; 66, identifier:filenames; 67, identifier:module_basename; 68, identifier:directory; 69, identifier:key; 70, identifier:sort_key; 71, expression_statement; 72, identifier:ImportError; 73, block; 74, block; 75, list_comprehension; 76, call; 77, expression_statement; 78, expression_statement; 79, expression_statement; 80, list_comprehension; 81, for_in_clause; 82, if_clause; 83, attribute; 84, argument_list; 85, call; 86, call; 87, call; 88, call; 89, for_in_clause; 90, identifier:_; 91, call; 92, call; 93, identifier:importlib; 94, identifier:import_module; 95, identifier:modulename; 96, attribute; 97, argument_list; 98, attribute; 99, argument_list; 100, attribute; 101, argument_list; 102, attribute; 103, argument_list; 104, identifier:filename; 105, subscript; 106, attribute; 107, argument_list; 108, identifier:len; 109, argument_list; 110, identifier:logger; 111, identifier:warning; 112, string; 113, identifier:modulename; 114, identifier:logger; 115, identifier:exception; 116, string; 117, identifier:logger; 118, identifier:info; 119, string; 120, identifier:modulename; 121, attribute; 122, identifier:join; 123, subscript; 124, identifier:filename; 125, identifier:_; 126, integer:2; 127, identifier:os; 128, identifier:walk; 129, identifier:directory; 130, subscript; 131, string_content:failed loading %s; 132, string_content:module loading failure; 133, string_content:successfully loaded %s; 134, identifier:os; 135, identifier:path; 136, identifier:_; 137, integer:0; 138, identifier:_; 139, integer:2
code: def import_directory(module_basename: str, directory: str, sort_key = None) -> None:
      '''Load all python modules in directory and directory's children.
  
      Parameters
      ----------
  
      :``module_basename``: module name prefix for loaded modules
      :``directory``:       directory to load python modules from
      :``sort_key``:        function to sort module names with before loading
  
      '''
  
      logger.info('loading submodules of %s', module_basename)
      logger.info('loading modules from %s', directory)
  
      filenames = itertools.chain(*[ [ os.path.join(_[0], filename) for filename in _[2] ] for _ in os.walk(directory) if len(_[2]) ])
      modulenames = _filenames_to_modulenames(filenames, module_basename, directory)
  
      for modulename in sorted(modulenames, key = sort_key):
          try:
              importlib.import_module(modulename)
          except ImportError:
              logger.warning('failed loading %s', modulename)
              logger.exception('module loading failure')
          else:
              logger.info('successfully loaded %s', modulename)