Give a nice error message when Graphviz is not installed. Closes issue #168.

authorEmile Anclin
changesetbd9ee94a908d
branchdefault
phasepublic
hiddenno
parent revision#82fc94502999 Use the new .ctx attribute for subscripts for detecting in which context the node was used. Closes issue #705.
child revision#1cdd3f6a3ac6 Change the attribute check for using hasattr instead of looking explicitly into __dict__.
files modified by this revision
ChangeLog
pylint/pyreverse/main.py
# HG changeset patch
# User Emile Anclin
# Date 1449570314 -7200
# Tue Dec 08 12:25:14 2015 +0200
# Node ID bd9ee94a908d62fd7270f4eb8af88586b93a6953
# Parent 82fc94502999bbe411b3c9f5b7d4af9c4e7843e8
Give a nice error message when Graphviz is not installed. Closes issue #168.

diff --git a/ChangeLog b/ChangeLog
@@ -11,10 +11,13 @@
1      * Accept only functions and methods for the deprecated-method checker.
2 
3       This prevents a crash which can occur when an object doesn't have
4       .qname() method after the inference.
5 
6 +    * Don't crash if graphviz is not installed, instead emit a
7 +      warning letting the user to know.
8 +
9      * Don't emit super-on-old-class on classes with unknown bases.
10        Closes issue #721.
11 
12      * Allow statements in `if` or `try` blocks containing imports.
13 
diff --git a/pylint/pyreverse/main.py b/pylint/pyreverse/main.py
@@ -19,10 +19,11 @@
14    create UML diagrams for classes and modules in <packages>
15  """
16  from __future__ import print_function
17 
18  import os
19 +import subprocess
20  import sys
21 
22  from pylint.config import ConfigurationMixIn
23  from pylint.pyreverse.inspector import Linker, project_from_files
24  from pylint.pyreverse.diadefslib import DiadefsHandler
@@ -89,19 +90,35 @@
25  )
26  # FIXME : quiet mode
27  #( ('quiet',
28                  #dict(help='run quietly', action='store_true', short='q')), )
29 
30 +def _check_graphviz_available(output_format):
31 +    """check if we need graphviz for different output format"""
32 +    try:
33 +        subprocess.call(['dot', '-V'], stdout=subprocess.PIPE,
34 +                        stderr=subprocess.PIPE)
35 +    except OSError:
36 +        print("The output format '%s' is currently not available.\n"
37 +              "Please install 'Graphviz' to have other output formats "
38 +              "than 'dot' or 'vcg'." % output_format)
39 +        sys.exit(32)
40 +
41 +
42 +
43  class Run(ConfigurationMixIn):
44      """base class providing common behaviour for pyreverse commands"""
45 
46      options = OPTIONS
47 
48      def __init__(self, args):
49          ConfigurationMixIn.__init__(self, usage=__doc__)
50          insert_default_options()
51          args = self.load_command_line_configuration()
52 +        if self.config.output_format not in ('dot', 'vcg'):
53 +            _check_graphviz_available(self.config.output_format)
54 +
55          sys.exit(self.run(args))
56 
57      def run(self, args):
58          """checking arguments and run project"""
59          if not args: