def find_modules(rootpath, skip):
INITPY = '<STR_LIT>'<EOL>rootpath = os.path.normpath(os.path.abspath(rootpath))<EOL>if INITPY in os.listdir(rootpath):<EOL><INDENT>root_package = rootpath.split(os.path.sep)[-<NUM_LIT:1>]<EOL>print("<STR_LIT>", rootpath)<EOL><DEDENT>else:<EOL><INDENT>print("<STR_LIT>", rootpath)<EOL>return<EOL><DEDENT>def makename(package, module):<EOL><INDENT>"""<STR_LIT>"""<EOL>if package:<EOL><INDENT>name = package<EOL>if module:<EOL><INDENT>name += '<STR_LIT:.>' + module<EOL><DEDENT><DEDENT>else:<EOL><INDENT>name = module<EOL><DEDENT>return name<EOL><DEDENT>skipall = []<EOL>for m in list(skip.keys()):<EOL><INDENT>if skip[m] is None: skipall.append(m)<EOL><DEDENT>tree = {}<EOL>saved = <NUM_LIT:0><EOL>found = <NUM_LIT:0><EOL>def save(module, submodule):<EOL><INDENT>name = module+ "<STR_LIT:.>"+ submodule<EOL>for s in skipall:<EOL><INDENT>if name.startswith(s):<EOL><INDENT>print("<STR_LIT>"+name)<EOL>return False<EOL><DEDENT><DEDENT>if module in skip:<EOL><INDENT>if submodule in skip[module]:<EOL><INDENT>print("<STR_LIT>"+name)<EOL>return False<EOL><DEDENT><DEDENT>if module not in tree:<EOL><INDENT>tree[module] = []<EOL><DEDENT>tree[module].append(submodule)<EOL>return True<EOL><DEDENT>for root, subs, files in os.walk(rootpath):<EOL><INDENT>py_files = sorted([f for f in files if os.path.splitext(f)[<NUM_LIT:1>] == '<STR_LIT>'])<EOL>if INITPY in py_files:<EOL><INDENT>subpackage = root[len(rootpath):].lstrip(os.path.sep).replace(os.path.sep, '<STR_LIT:.>')<EOL>full = makename(root_package, subpackage)<EOL>part = full.rpartition('<STR_LIT:.>')<EOL>base_package, submodule = part[<NUM_LIT:0>], part[<NUM_LIT:2>]<EOL>found += <NUM_LIT:1><EOL>if save(base_package, submodule): saved += <NUM_LIT:1><EOL>py_files.remove(INITPY)    <EOL>for py_file in py_files:<EOL><INDENT>found += <NUM_LIT:1><EOL>module = os.path.splitext(py_file)[<NUM_LIT:0>]<EOL>if save(full, module): saved += <NUM_LIT:1><EOL><DEDENT><DEDENT><DEDENT>for item in list(tree.keys()):<EOL><INDENT>tree[item].sort()<EOL><DEDENT>print("<STR_LIT>" %(root_package, found, found-saved))<EOL>return tree<EOL>
Look for every file in the directory tree and return a dict
Hacked from sphinx.autodoc