From ca84f59894b9f62cd528779e7fbe6a6f84c42a57 Mon Sep 17 00:00:00 2001 From: Benjamin Root Date: Sat, 13 Oct 2012 22:30:37 -0400 Subject: [PATCH] Fix bad commandline handling. Closes issue #1306 Don't raise an exception if the --verbose-* doesn't match one of our strings. It might not be intended for us! --- lib/matplotlib/__init__.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/matplotlib/__init__.py b/lib/matplotlib/__init__.py index f67416a078b3..ea8d569b50fe 100644 --- a/lib/matplotlib/__init__.py +++ b/lib/matplotlib/__init__.py @@ -214,8 +214,14 @@ class Verbose: _commandLineVerbose = None for arg in sys.argv[1:]: - if not arg.startswith('--verbose-'): continue - _commandLineVerbose = arg[10:] + if not arg.startswith('--verbose-'): + continue + level_str = arg[10:] + # If it doesn't match one of ours, then don't even + # bother noting it, we are just a 3rd-party library + # to somebody else's script. + if level_str in levels: + _commandLineVerbose = level_str def __init__(self): self.set_level('silent') @@ -227,8 +233,10 @@ def set_level(self, level): if self._commandLineVerbose is not None: level = self._commandLineVerbose if level not in self.levels: - raise ValueError('Illegal verbose string "%s". Legal values are %s'%(level, self.levels)) - self.level = level + warnings.warn('matplotlib: unrecognized --verbose-* string "%s".' + ' Legal values are %s' % (level, self.levels)) + else: + self.level = level def set_fileo(self, fname): std = {