parameters: (rootpath, excludes, opts)
return_statement: return toplevels
docstring: Look for every file in the directory tree and create the corresponding
      ReST files.
docstring_summary: Look for every file in the directory tree and create the corresponding
      ReST files.
docstring_tokens: Look for every file in the directory tree and create the corresponding ReST files .
function: def recurse_tree(rootpath, excludes, opts):
      """
      Look for every file in the directory tree and create the corresponding
      ReST files.
      """
      # use absolute path for root, as relative paths like '../../foo' cause
      # 'if "/." in root ...' to filter out *all* modules otherwise
      rootpath = path.normpath(path.abspath(rootpath))
      # check if the base directory is a package and get its name
      if INITPY in os.listdir(rootpath):
          root_package = rootpath.split(path.sep)[-1]
      else:
          # otherwise, the base is a directory with packages
          root_package = None
  
      toplevels = []
      for root, subs, files in os.walk(rootpath):
          if is_excluded(root, excludes):
              del subs[:]
              continue
          # document only Python module files
          py_files = sorted([f for f in files if path.splitext(f)[1] == '.py'])
          is_pkg = INITPY in py_files
          if is_pkg:
              py_files.remove(INITPY)
              py_files.insert(0, INITPY)
          elif root != rootpath:
              # only accept non-package at toplevel
              del subs[:]
              continue
          # remove hidden ('.') and private ('_') directories
          subs[:] = sorted(sub for sub in subs if sub[0] not in ['.', '_'])
  
          if is_pkg:
              # we are in a package with something to document
              if subs or len(py_files) > 1 or not \
                  shall_skip(path.join(root, INITPY)):
                  subpackage = root[len(rootpath):].lstrip(path.sep).\
                      replace(path.sep, '.')
                  create_package_file(root, root_package, subpackage,
                                      py_files, opts, subs)
                  toplevels.append(makename(root_package, subpackage))
          else:
              # if we are at the root level, we don't require it to be a package
              assert root == rootpath and root_package is None
              for py_file in py_files:
                  if not shall_skip(path.join(rootpath, py_file)):
                      module = path.splitext(py_file)[0]
                      create_module_file(root_package, module, opts)
                      toplevels.append(module)
  
      return toplevels
function_tokens: def recurse_tree ( rootpath , excludes , opts ) : # use absolute path for root, as relative paths like '../../foo' cause # 'if "/." in root ...' to filter out *all* modules otherwise rootpath = path . normpath ( path . abspath ( rootpath ) ) # check if the base directory is a package and get its name if INITPY in os . listdir ( rootpath ) : root_package = rootpath . split ( path . sep ) [ - 1 ] else : # otherwise, the base is a directory with packages root_package = None toplevels = [ ] for root , subs , files in os . walk ( rootpath ) : if is_excluded ( root , excludes ) : del subs [ : ] continue # document only Python module files py_files = sorted ( [ f for f in files if path . splitext ( f ) [ 1 ] == '.py' ] ) is_pkg = INITPY in py_files if is_pkg : py_files . remove ( INITPY ) py_files . insert ( 0 , INITPY ) elif root != rootpath : # only accept non-package at toplevel del subs [ : ] continue # remove hidden ('.') and private ('_') directories subs [ : ] = sorted ( sub for sub in subs if sub [ 0 ] not in [ '.' , '_' ] ) if is_pkg : # we are in a package with something to document if subs or len ( py_files ) > 1 or not shall_skip ( path . join ( root , INITPY ) ) : subpackage = root [ len ( rootpath ) : ] . lstrip ( path . sep ) . replace ( path . sep , '.' ) create_package_file ( root , root_package , subpackage , py_files , opts , subs ) toplevels . append ( makename ( root_package , subpackage ) ) else : # if we are at the root level, we don't require it to be a package assert root == rootpath and root_package is None for py_file in py_files : if not shall_skip ( path . join ( rootpath , py_file ) ) : module = path . splitext ( py_file ) [ 0 ] create_module_file ( root_package , module , opts ) toplevels . append ( module ) return toplevels