Skip to content

Commit

Permalink
Adds a command line option to not debug with PDB
Browse files Browse the repository at this point in the history
  • Loading branch information
ESultanik committed Jan 13, 2022
1 parent 0850a3e commit 6408ef5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 6 additions & 1 deletion polyfile/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ def main(argv=None):
parser.add_argument('--trace', '-dd', action='store_true', help='print extra verbose debug information')
parser.add_argument('--debugger', '-db', action='store_true', help='drop into an interactive debugger for libmagic '
'file definition matching')
parser.add_argument('--no-debug-python', action='store_true', help='by default, the `--debugger` option will break '
'on custom matchers and prompt to debug using '
'PDB. This option will suppress those prompts.')
parser.add_argument('--quiet', '-q', action='store_true', help='suppress all log output (overrides --debug)')
parser.add_argument('--version', '-v', action='store_true', help='print PolyFile\'s version information to STDERR')
parser.add_argument('-dumpversion', action='store_true',
Expand Down Expand Up @@ -116,7 +119,9 @@ def main(argv=None):

with path_or_stdin as file_path, ExitStack() as stack:
if args.debugger:
stack.enter_context(Debugger())
stack.enter_context(Debugger(break_on_submatching=not args.no_debug_python))
elif args.no_debug_python:
log.warning("Ignoring `--no-debug-python`; it can only be used with the --debugger option.")
matches = []
try:
if args.only_match_mime:
Expand Down
4 changes: 2 additions & 2 deletions polyfile/magic_debugger.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from enum import Enum
from pdb import Pdb
import sys
from typing import Any, Callable, Iterator, List, Optional, Type, TypeVar, Union
from typing import Any, Callable, ContextManager, Iterator, List, Optional, Type, TypeVar, Union

from .polyfile import __copyright__, __license__, __version__, CUSTOM_MATCHERS, Match, Submatch
from .logger import getStatusLogger
Expand Down Expand Up @@ -241,7 +241,7 @@ class StepMode(Enum):
NEXT = 2


class Debugger:
class Debugger(ContextManager["Debugger"]):
def __init__(self, break_on_submatching: bool = True):
self.instrumented_tests: List[InstrumentedTest] = []
self.breakpoints: List[Breakpoint] = []
Expand Down

0 comments on commit 6408ef5

Please sign in to comment.