[go: nahoru, domu]

Skip to content

Commit

Permalink
Merge pull request cantools#265 from altendky/patch-1
Browse files Browse the repository at this point in the history
lack of matplolib does not error until actually running subcommand
  • Loading branch information
eerimoq committed Feb 9, 2021
2 parents a5029b5 + f35ba93 commit d396fbd
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions cantools/subparsers/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,23 @@
try:
from matplotlib import pyplot as plt
except ImportError:
print("matplotlib package not installed. Required for producing plots.")
plt = None

from .. import database
from .. import errors


plt.rcParams["date.autoformatter.hour"] = "%H:%M"
plt.rcParams["date.autoformatter.minute"] = "%H:%M"
plt.rcParams["date.autoformatter.microsecond"] = "%H:%M:%S.%f"
class MatplotlibNotInstalledError(errors.Error):

def __init__(self):
super().__init__("The matplotlib package not installed and is required "
"for producing plots.")


if plt is not None:
plt.rcParams["date.autoformatter.hour"] = "%H:%M"
plt.rcParams["date.autoformatter.minute"] = "%H:%M"
plt.rcParams["date.autoformatter.microsecond"] = "%H:%M:%S.%f"


# Matches 'candump' output, i.e. "vcan0 1F0 [8] 00 00 00 00 00 00 1B C1".
Expand Down Expand Up @@ -178,6 +187,10 @@ def _do_decode(args):
It iterates over all input lines, parses them
and passes the data to a Plotter object.
'''

if plt is None:
raise MatplotlibNotInstalledError()

if args.show_errors:
args.show_invalid_syntax = True
args.show_unknown_frames = True
Expand Down

0 comments on commit d396fbd

Please sign in to comment.