tox-dev / pipdeptree

A command line utility to display dependency tree of the installed Python packages

Home Page:https://pypi.python.org/pypi/pipdeptree

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Graph Output Broken with graphviz>18.0

macserv opened this issue · comments

In versions of graphviz after 0.18, its submodules (e.g.: graphviz.backend) have been made opaque, and their interfaces have been hoisted to the top module. This change results in the following error:

% pipdeptree --graph-output pdf > dependencies.pdf
Traceback (most recent call last):
  File "/Users/v076726/.pyenv/versions/3.7.9/bin/pipdeptree", line 8, in <module>
    sys.exit(main())
  File "/Users/v076726/.pyenv/versions/3.7.9/lib/python3.7/site-packages/pipdeptree.py", line 879, in main
    is_reverse=args.reverse)
  File "/Users/v076726/.pyenv/versions/3.7.9/lib/python3.7/site-packages/pipdeptree.py", line 601, in dump_graphviz
    if output_format not in backend.FORMATS:
AttributeError: module 'graphviz.backend' has no attribute 'FORMATS'

Remediation of the error would require the replacement of a call to graphviz.backend.FORMATS with graphviz.FORMATS, as shown in the patch below. Alternately, the graphviz dependency could be capped at version 0.18 for now.

As a test, using graphviz@1.18.2, I was able to restore normal operation with the following changes:

--- a/pipdeptree.py
+++ b/pipdeptree.py
@@ -22,7 +22,7 @@ except ImportError:
 
 from pip._vendor import pkg_resources
 # inline:
-# from graphviz import backend, Digraph
+# from graphviz import FORMATS, Digraph
 
 
 __version__ = '2.2.0'
@@ -592,17 +592,17 @@ def dump_graphviz(tree, output_format='dot', is_reverse=False):
 
     """
     try:
-        from graphviz import backend, Digraph
+        from graphviz import FORMATS, Digraph
     except ImportError:
         print('graphviz is not available, but necessary for the output '
               'option. Please install it.', file=sys.stderr)
         sys.exit(1)
 
-    if output_format not in backend.FORMATS:
+    if output_format not in FORMATS:
         print('{0} is not a supported output format.'.format(output_format),
               file=sys.stderr)
         print('Supported formats are: {0}'.format(
-            ', '.join(sorted(backend.FORMATS))), file=sys.stderr)
+            ', '.join(sorted(FORMATS))), file=sys.stderr)
         sys.exit(1)
 
     graph = Digraph(format=output_format)

This has been fixed by PR #158