Update all stub files in stubs_dir with docstrings from pyarrow runtime.
(stubs_dir)
| 175 | |
| 176 | |
| 177 | def add_docstrings_to_stubs(stubs_dir): |
| 178 | """Update all stub files in stubs_dir with docstrings from pyarrow runtime.""" |
| 179 | stubs_dir = Path(stubs_dir) |
| 180 | print(f"Updating stub docstrings in: {stubs_dir}") |
| 181 | |
| 182 | pyarrow = importlib.import_module("pyarrow") |
| 183 | |
| 184 | for stub_file in sorted(stubs_dir.rglob('*.pyi')): |
| 185 | if stub_file.name == "_stubs_typing.pyi": |
| 186 | continue |
| 187 | |
| 188 | module_name = stub_file.stem |
| 189 | if module_name in LIB_MODULES: |
| 190 | namespace = "lib" |
| 191 | elif stub_file.parent.name in ("parquet", "interchange"): |
| 192 | namespace = (stub_file.parent.name if module_name == "__init__" |
| 193 | else f"{stub_file.parent.name}.{module_name}") |
| 194 | elif module_name == "__init__": |
| 195 | namespace = "" |
| 196 | else: |
| 197 | namespace = module_name |
| 198 | |
| 199 | print(f" {stub_file.name} -> {namespace or '(root)'}") |
| 200 | tree = libcst.parse_module(stub_file.read_text(encoding="utf-8")) |
| 201 | modified = tree.visit(DocstringInserter(pyarrow, namespace)) |
| 202 | stub_file.write_text(modified.code, encoding="utf-8") |
| 203 | |
| 204 | |
| 205 | def _link_or_copy(source, destination): |
no test coverage detected