code: def walk_modules(path):
      
      if path is None or not os.path.isdir(path):
          return
  
      yielded = set()
      try:
          file_names = os.listdir(path)
      except OSError:
          # ignore unreadable directories like import does
          file_names = []
  
      # handle packages before same-named modules
      file_names.sort()
  
      for filename in file_names:
          modname = inspect.getmodulename(filename)
          if modname == "__init__" or modname in yielded:
              continue
  
          file_path = os.path.join(path, filename)
          is_package = False
  
          if not modname and os.path.isdir(file_path) and "." not in filename:
              modname = filename
              try:
                  dir_contents = os.listdir(file_path)
              except OSError:
                  # ignore unreadable directories like import does
                  dir_contents = []
  
              for sub_filename in dir_contents:
                  sub_name = inspect.getmodulename(sub_filename)
                  if sub_name == "__init__":
                      is_package = True
                      break
              else:
                  # not a package
                  continue
  
          if modname and "." not in modname:
              yielded.add(modname)
              yield modname, is_package
docs: Code from ``pkgutil.ImpImporter.iter_modules()``: walks through a folder
      and yields all loadable packages and modules.
  
      :param path: Path where to look for modules
      :return: Generator to walk through found packages and modules