def recursive_write_files(m: pdoc.Module, ext: str, **kwargs): assert ext in ('.html', '.md') filepath = module_path(m, ext=ext) dirpath = path.dirname(filepath) if not os.access(dirpath, os.R_OK): os.makedirs(dirpath) with _open_write_file(filepath) as f: if ext == '.html': f.write(m.html(**kwargs)) elif ext == '.md': f.write(m.text(**kwargs)) for submodule in m.submodules(): recursive_write_files(submodule, ext=ext, **kwargs)
def write_files(m: pdoc.Module, ext: str, **kwargs): assert ext in ('.html', '.md') f = module_path(m, ext=ext) dirpath = path.dirname(f) if not os.access(dirpath, os.R_OK): os.makedirs(dirpath) try: with open(f, 'w+', encoding='utf-8') as w: if ext == '.html': w.write(m.html(**kwargs)) elif ext == '.md': w.write(m.text(**kwargs)) except Exception: try: os.unlink(f) except Exception: pass raise for submodule in m.submodules(): write_files(submodule, ext=ext, **kwargs)