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

authorEmile Anclin
changeset6d2f2e21053d
branchdefault
phasepublic
hiddenno
parent revision#b3032b9393fa Remove trailing whitespace.
child revision<not specified>
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 6d2f2e21053dcdc4116658e24ba14e0415ef3e27
# Parent b3032b9393fa0d9b8005a71c4421a9857f21b01b
Give a nice error message when Graphviz is not installed. Closes issue #168.

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