Look for every file in the directory tree and create the corresponding ReST files.
(rootpath, excludes, opts)
| 107 | |
| 108 | |
| 109 | def recurse_tree(rootpath, excludes, opts): |
| 110 | """ |
| 111 | Look for every file in the directory tree and create the corresponding |
| 112 | ReST files. |
| 113 | """ |
| 114 | # use absolute path for root, as relative paths like '../../foo' cause |
| 115 | # 'if "/." in root ...' to filter out *all* modules otherwise |
| 116 | rootpath = path.normpath(path.abspath(rootpath)) |
| 117 | # check if the base directory is a package and get its name |
| 118 | if INITPY in os.listdir(rootpath): |
| 119 | root_package = rootpath.split(path.sep)[-1] |
| 120 | else: |
| 121 | # otherwise, the base is a directory with packages |
| 122 | root_package = None |
| 123 | |
| 124 | toplevels = [] |
| 125 | for root, subs, files in os.walk(rootpath): |
| 126 | if is_excluded(root, excludes): |
| 127 | del subs[:] |
| 128 | continue |
| 129 | # document only Python module files |
| 130 | py_files = sorted([f for f in files if path.splitext(f)[1] == '.py']) |
| 131 | is_pkg = INITPY in py_files |
| 132 | if is_pkg: |
| 133 | py_files.remove(INITPY) |
| 134 | py_files.insert(0, INITPY) |
| 135 | elif root != rootpath: |
| 136 | # only accept non-package at toplevel |
| 137 | del subs[:] |
| 138 | continue |
| 139 | # remove hidden ('.') and private ('_') directories |
| 140 | subs[:] = sorted(sub for sub in subs if sub[0] not in ['.', '_']) |
| 141 | |
| 142 | if is_pkg: |
| 143 | # we are in a package with something to document |
| 144 | if subs or len(py_files) > 1 or not \ |
| 145 | shall_skip(path.join(root, INITPY)): |
| 146 | subpackage = root[len(rootpath):].lstrip(path.sep).\ |
| 147 | replace(path.sep, '.') |
| 148 | create_package_file(root, root_package, subpackage, |
| 149 | py_files, opts, subs) |
| 150 | toplevels.append(makename(root_package, subpackage)) |
| 151 | else: |
| 152 | # if we are at the root level, we don't require it to be a package |
| 153 | assert root == rootpath and root_package is None |
| 154 | for py_file in py_files: |
| 155 | if not shall_skip(path.join(rootpath, py_file)): |
| 156 | module = path.splitext(py_file)[0] |
| 157 | create_module_file(root_package, module, opts) |
| 158 | toplevels.append(module) |
| 159 | |
| 160 | return toplevels |
| 161 | |
| 162 | |
| 163 | def normalize_excludes(rootpath, excludes): |
no test coverage detected