Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/grimp/application/usecases.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,17 @@ def _assemble_graph(
imports_by_module: Dict[Module, Set[DirectImport]],
) -> ImportGraph:
graph: ImportGraph = settings.IMPORT_GRAPH_CLASS()

package_modules = {Module(found_package.name) for found_package in found_packages}

for module, direct_imports in imports_by_module.items():
graph.add_module(module.name)
for direct_import in direct_imports:
# Before we add the import, check to see if the imported module is in fact an
# external module, and if so, tell the graph that it is a squashed module.
graph.add_module(
direct_import.imported.name,
is_squashed=_is_external(direct_import.imported, found_packages),
is_squashed=_is_external(direct_import.imported, package_modules),
)

graph.add_import(
Expand All @@ -186,9 +189,7 @@ def _assemble_graph(
return graph


def _is_external(module: Module, found_packages: Set[FoundPackage]) -> bool:
package_modules = [Module(found_package.name) for found_package in found_packages]

def _is_external(module: Module, package_modules: Set[Module]) -> bool:
return not any(
module.is_descendant_of(package_module) or module == package_module
for package_module in package_modules
Expand Down
Loading