For every module directory under basepath (i.e. contains a vtk.module file), copy READMEs under root_destination while recreating the directory structure. Additionally look for README under custom_paths. A "README" file is any file matching the readme_formats. returns a list of dictiona
(
basepath,
root_destination,
custom_paths=[],
readme_formats=["README.md", "README", "readme.md", "README.txt"],
extra_documentation_dirs=[],
ignore_list=[],
)
| 40 | |
| 41 | |
| 42 | def gather_module_documentation( |
| 43 | basepath, |
| 44 | root_destination, |
| 45 | custom_paths=[], |
| 46 | readme_formats=["README.md", "README", "readme.md", "README.txt"], |
| 47 | extra_documentation_dirs=[], |
| 48 | ignore_list=[], |
| 49 | ): |
| 50 | """For every module directory under basepath (i.e. contains a vtk.module file), copy READMEs under root_destination |
| 51 | while recreating the directory structure. Additionally look for README under custom_paths. |
| 52 | |
| 53 | A "README" file is any file matching the readme_formats. |
| 54 | returns a list of dictionaries holding the description of a module (see also parse_vtk_module) |
| 55 | |
| 56 | extra_documentation_dirs: directories to look for additional documentation |
| 57 | ignore_list: paths relative to basepath to ignore |
| 58 | """ |
| 59 | try: |
| 60 | os.mkdir(root_destination) |
| 61 | except FileExistsError: |
| 62 | pass |
| 63 | paths = Path(basepath).rglob("vtk.module") |
| 64 | if len(custom_paths) > 0: |
| 65 | custom_dirs = iter([Path(path) for path in custom_paths]) |
| 66 | paths = itertools.chain(paths, custom_dirs) |
| 67 | |
| 68 | # transform the ignore_list to Path objects |
| 69 | ignore_list = [Path(os.path.join(basepath, path)) for path in ignore_list] |
| 70 | |
| 71 | module_list = [] |
| 72 | |
| 73 | for path in paths: |
| 74 | basename = path |
| 75 | if path.is_file(): |
| 76 | basename = path.parent |
| 77 | |
| 78 | skip = False |
| 79 | for item in ignore_list: |
| 80 | if basename.is_relative_to(item): |
| 81 | skip = True |
| 82 | break |
| 83 | if skip: |
| 84 | continue |
| 85 | |
| 86 | # extract module information |
| 87 | if "vtk.module" in str(path): |
| 88 | module = parse_vtk_module(str(path)) |
| 89 | for doc_dir_name in extra_documentation_dirs: |
| 90 | doc_dir = os.path.join(str(basename), doc_dir_name) |
| 91 | if os.path.exists(doc_dir): |
| 92 | new_doc_dir = os.path.relpath(doc_dir, start="../../") |
| 93 | dest = Path(os.path.join(root_destination, new_doc_dir)) |
| 94 | shutil.copytree( |
| 95 | doc_dir, |
| 96 | dest, |
| 97 | dirs_exist_ok=True, |
| 98 | ) |
| 99 | # Bring module specific readmes while recreating the data structure |