Follow imports within graph from given sources until hitting changed modules. If we find a changed module, we can't continue following imports as the imports may have changed. Args: roots: modules where to start search from graph: module graph to use
(
self,
roots: list[BuildSource],
graph: mypy.build.Graph,
seen: set[str],
changed_paths: AbstractSet[str],
)
| 727 | return messages |
| 728 | |
| 729 | def find_reachable_changed_modules( |
| 730 | self, |
| 731 | roots: list[BuildSource], |
| 732 | graph: mypy.build.Graph, |
| 733 | seen: set[str], |
| 734 | changed_paths: AbstractSet[str], |
| 735 | ) -> tuple[list[tuple[str, str]], list[BuildSource]]: |
| 736 | """Follow imports within graph from given sources until hitting changed modules. |
| 737 | |
| 738 | If we find a changed module, we can't continue following imports as the imports |
| 739 | may have changed. |
| 740 | |
| 741 | Args: |
| 742 | roots: modules where to start search from |
| 743 | graph: module graph to use for the search |
| 744 | seen: modules we've seen before that won't be visited (mutated here!!). |
| 745 | Needed to accumulate all modules encountered during update and remove |
| 746 | everything that no longer exists. |
| 747 | changed_paths: which paths have changed (stop search here and return any found) |
| 748 | |
| 749 | Return (encountered reachable changed modules, |
| 750 | unchanged files not in sources_set traversed). |
| 751 | """ |
| 752 | changed = [] |
| 753 | new_files = [] |
| 754 | worklist = roots.copy() |
| 755 | seen.update(source.module for source in worklist) |
| 756 | while worklist: |
| 757 | nxt = worklist.pop() |
| 758 | if nxt.module not in seen: |
| 759 | seen.add(nxt.module) |
| 760 | new_files.append(nxt) |
| 761 | if nxt.path in changed_paths: |
| 762 | assert nxt.path is not None # TODO |
| 763 | changed.append((nxt.module, nxt.path)) |
| 764 | elif nxt.module in graph: |
| 765 | state = graph[nxt.module] |
| 766 | ancestors = state.ancestors or [] |
| 767 | for dep in state.dependencies + ancestors: |
| 768 | if dep not in seen: |
| 769 | seen.add(dep) |
| 770 | worklist.append(BuildSource(graph[dep].path, graph[dep].id, followed=True)) |
| 771 | return changed, new_files |
| 772 | |
| 773 | def direct_imports( |
| 774 | self, module: tuple[str, str], graph: mypy.build.Graph |
no test coverage detected