Skip to content

Commit

Permalink
cli: add --pdb flag for toise-plot
Browse files Browse the repository at this point in the history
  • Loading branch information
jvansanten committed May 22, 2024
1 parent a707da3 commit 26a1bae
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion toise/figures/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ def _add_options_for_args(parser, spec: inspect.Signature, param_help):


def make_figure():
import traceback
import pdb
from toise import figures

# find all submodules of toise.figures and import them
Expand All @@ -313,6 +315,9 @@ def make_figure():
)
p.set_defaults(command=func)
p.add_argument("-o", "--outfile")
p.add_argument(
"--pdb", action="store_true", help="Drop into debugger on exception"
)
spec = inspect.signature(func)
num_required_args = 0
if (
Expand All @@ -325,13 +330,22 @@ def make_figure():
kwargs = parser.parse_args().__dict__
infiles = kwargs.pop("infiles", None)
outfile = kwargs.pop("outfile")
do_pdb = kwargs.pop("pdb")

func = kwargs.pop("command")
if infiles:
args = (list(map(load_gzip, infiles)),)
else:
args = tuple()
figure = func(*args, **kwargs)
try:
figure = func(*args, **kwargs)
except:
if do_pdb:
extype, value, tb = sys.exc_info()
traceback.print_exc()
pdb.post_mortem(tb)
else:
raise

if outfile:
figure.savefig(outfile)
Expand Down

0 comments on commit 26a1bae

Please sign in to comment.