Find a module in a list that directly imports no other module in the list. If no such module exists, return the lexicographically first module from the list. Always return one of the items in the modules list. NOTE: If both 'abc' and 'typing' have changed, an effect of the above rule i
(modules: list[tuple[str, str]], graph: Graph)
| 684 | |
| 685 | |
| 686 | def find_relative_leaf_module(modules: list[tuple[str, str]], graph: Graph) -> tuple[str, str]: |
| 687 | """Find a module in a list that directly imports no other module in the list. |
| 688 | |
| 689 | If no such module exists, return the lexicographically first module from the list. |
| 690 | Always return one of the items in the modules list. |
| 691 | |
| 692 | NOTE: If both 'abc' and 'typing' have changed, an effect of the above rule is that |
| 693 | we prefer 'abc', even if both are in the same SCC. This works around a false |
| 694 | positive in 'typing', at least in tests. |
| 695 | |
| 696 | Args: |
| 697 | modules: List of (module, path) tuples (non-empty) |
| 698 | graph: Program import graph that contains all modules in the module list |
| 699 | """ |
| 700 | assert modules |
| 701 | # Sort for repeatable results. |
| 702 | modules = sorted(modules) |
| 703 | module_set = {module for module, _ in modules} |
| 704 | for module, path in modules: |
| 705 | state = graph[module] |
| 706 | if len(set(state.dependencies) & module_set) == 0: |
| 707 | # Found it! |
| 708 | return module, path |
| 709 | # Could not find any. Just return the first module (by lexicographic order). |
| 710 | return modules[0] |
| 711 | |
| 712 | |
| 713 | def delete_module(module_id: str, path: str, graph: Graph, manager: BuildManager) -> None: |
no test coverage detected
searching dependent graphs…