dvc: add --pdb flag (#4895)

This is a hidden flag (no docs needed) for a handy shortcut to pdb when
we need it. E.g. binaries built by pyinstaller are much easier to debug
with it.
This commit is contained in:
Ruslan Kuprieiev
2020-11-15 02:30:13 +02:00
committed by GitHub
parent 2f620e9226
commit f4349aa09b
2 changed files with 20 additions and 2 deletions
+4
View File
@@ -146,6 +146,10 @@ def get_parent_parser():
)
parent_parser.add_argument("--cprofile-dump", help=argparse.SUPPRESS)
parent_parser.add_argument(
"--pdb", action="store_true", default=False, help=argparse.SUPPRESS,
)
log_level_group = parent_parser.add_mutually_exclusive_group()
log_level_group.add_argument(
"-q", "--quiet", action="count", default=0, help="Be quiet."
+16 -2
View File
@@ -42,6 +42,19 @@ def profile(enable, dump):
prof.dump_stats(dump)
@contextmanager
def debug(enable):
try:
yield
return
except Exception:
if enable:
import pdb # noqa: T100
pdb.post_mortem()
raise
def main(argv=None): # noqa: C901
"""Run dvc CLI command.
@@ -72,8 +85,9 @@ def main(argv=None): # noqa: C901
logger.trace(args)
with profile(enable=args.cprofile, dump=args.cprofile_dump):
cmd = args.func(args)
ret = cmd.run()
with debug(args.pdb):
cmd = args.func(args)
ret = cmd.run()
except ConfigError:
logger.exception("configuration error")
ret = 251