Build __init__.py source code and write to a file Parameters ---------- pkg_root : str Root package in which the top-level an __init__.py file with empty path_parts should reside path_parts : tuple of str Tuple of sub-packages under pkg_root where the __
(pkg_root, path_parts, rel_modules=(), rel_classes=(), init_extra="")
| 96 | |
| 97 | |
| 98 | def write_init_py(pkg_root, path_parts, rel_modules=(), rel_classes=(), init_extra=""): |
| 99 | """ |
| 100 | Build __init__.py source code and write to a file |
| 101 | |
| 102 | Parameters |
| 103 | ---------- |
| 104 | pkg_root : str |
| 105 | Root package in which the top-level an __init__.py file with empty |
| 106 | path_parts should reside |
| 107 | path_parts : tuple of str |
| 108 | Tuple of sub-packages under pkg_root where the __init__.py |
| 109 | file should be written |
| 110 | rel_modules: list of str |
| 111 | list of submodules to import, of the form .submodule |
| 112 | rel_classes: list of str |
| 113 | list of submodule classes/variables to import, of the form ._submodule.Foo |
| 114 | init_extra: str |
| 115 | Extra code snippet to append to end of __init__.py file |
| 116 | Returns |
| 117 | ------- |
| 118 | None |
| 119 | """ |
| 120 | # Generate source code |
| 121 | init_source = build_from_imports_py(rel_modules, rel_classes, init_extra) |
| 122 | |
| 123 | # Write file |
| 124 | filepath = opath.join(pkg_root, *path_parts, "__init__.py") |
| 125 | write_source_py(init_source, filepath) |
| 126 | |
| 127 | |
| 128 | def format_description(desc): |
no test coverage detected