ronaldoussoren / modulegraph

modulegraph determines a dependency graph between Python modules primarily by bytecode analysis for import statements. modulegraph uses similar methods to modulefinder from the standard library, but uses a more flexible internal representation, has more extensive knowledge of special cases, and is extensible.
MIT No Attribution
38 stars 4 forks source link

Dot output broken in Python 3 #38

Closed ronaldoussoren closed 7 years ago

ronaldoussoren commented 7 years ago

Original report by elnuno (Bitbucket: elnuno, GitHub: elnuno).


When asking for dot output in Python 3, only (empty) subgraphs were being rendered.

In Python 3, map returns an iterator, not a list. itergraphreport creates nodes as such an iterator which gets exhausted the first time we iterate it. Then we try to use it again.

The simplest fix is to turn nodes into a list:

#!diff

diff --git a/modulegraph/modulegraph.py b/modulegraph/modulegraph.py
--- a/modulegraph/modulegraph.py
+++ b/modulegraph/modulegraph.py
@@ -1874,5 +1874,5 @@
     def itergraphreport(self, name='G', flatpackages=()):
         # XXX: Can this be implemented using Dot()?
-        nodes = map(self.graph.describe_node, self.graph.iterdfs(self))
+        nodes = list(map(self.graph.describe_node, self.graph.iterdfs(self)))
         describe_edge = self.graph.describe_edge
         edges = deque()
ronaldoussoren commented 7 years ago

Original comment by Ronald Oussoren (Bitbucket: ronaldoussoren, GitHub: ronaldoussoren).


Thanks for the patch!

ronaldoussoren commented 7 years ago

Original comment by Ronald Oussoren (Bitbucket: ronaldoussoren, GitHub: ronaldoussoren).


I've committed the patch in changeset 252fb9c919d8