(source_path: Path)
| 5435 | declared_modules_by_file: dict[Path, set[str]] = {} |
| 5436 | |
| 5437 | def _declared_external_modules(source_path: Path) -> set[str]: |
| 5438 | source_path = source_path.resolve() |
| 5439 | if source_path in declared_modules_by_file: |
| 5440 | return declared_modules_by_file[source_path] |
| 5441 | try: |
| 5442 | import tree_sitter_rust as tsrust |
| 5443 | from tree_sitter import Language, Parser |
| 5444 | |
| 5445 | source = source_path.read_bytes() |
| 5446 | tree = Parser(Language(tsrust.language())).parse(source) |
| 5447 | except Exception: |
| 5448 | declared_modules_by_file[source_path] = set() |
| 5449 | return declared_modules_by_file[source_path] |
| 5450 | declared_modules_by_file[source_path] = { |
| 5451 | _read_text(name, source) |
| 5452 | for child in tree.root_node.named_children |
| 5453 | if child.type == "mod_item" |
| 5454 | and child.child_by_field_name("body") is None |
| 5455 | and (name := child.child_by_field_name("name")) is not None |
| 5456 | } |
| 5457 | return declared_modules_by_file[source_path] |
| 5458 | |
| 5459 | def _module_nodes_from( |
| 5460 | base: Path, modules: list[str], parent_file: Path | None, |
no test coverage detected