def pudb(line): """ Debug a script (like %run -d) in the IPython process, using PuDB. Usage: %pudb test.py [args] Run script test.py under PuDB. """ # Get the running instance if not line.strip(): print(pudb.__doc__) return from IPython.utils.process import arg_split args = arg_split(line) path = os.path.abspath(args[0]) args = args[1:] if not os.path.isfile(path): from IPython.core.error import UsageError raise UsageError("%%pudb: file %s does not exist" % path) from pudb import runscript runscript(path, args)
def main(): import sys from optparse import OptionParser parser = OptionParser( usage="usage: %prog [options] SCRIPT-TO-RUN [SCRIPT-ARGUMENTS]") parser.add_option("-s", "--steal-output", action="store_true"), parser.add_option("--pre-run", metavar="COMMAND", help="Run command before each program run", default="") parser.disable_interspersed_args() options, args = parser.parse_args() if len(args) < 1: parser.print_help() sys.exit(2) mainpyfile = args[0] from os.path import exists if not exists(mainpyfile): print('Error: %s does not exist' % mainpyfile) sys.exit(1) sys.argv = args from pudb import runscript runscript(mainpyfile, pre_run=options.pre_run, steal_output=options.steal_output)
def pudb_f_v11(self, arg): """ Debug a script (like %run -d) in IPython process, using PuDB. This conforms to IPython version 0.11 Usage: %pudb test.py [args] Run script test.py under PuDB. """ # Get the running instance if not arg.strip(): print __doc__ return from IPython.utils.process import arg_split args = arg_split(arg) path = os.path.abspath(args[0]) args = args[1:] if not os.path.isfile(path): from IPython.core.error import UsageError raise UsageError("%%pudb: file %s does not exist" % path) from pudb import runscript runscript(path, args)
def main(): import sys from optparse import OptionParser parser = OptionParser(usage="usage: %prog [options] SCRIPT-TO-RUN [SCRIPT-ARGUMENTS]") parser.add_option("-s", "--steal-output", action="store_true"), parser.add_option("--pre-run", metavar="COMMAND", help="Run command before each program run", default="") parser.disable_interspersed_args() options, args = parser.parse_args() if len(args) < 1: parser.print_help() sys.exit(2) mainpyfile = args[0] from os.path import exists, dirname if not exists(mainpyfile): print "Error:", mainpyfile, "does not exist" sys.exit(1) sys.argv = args from pudb import runscript runscript(mainpyfile, pre_run=options.pre_run, steal_output=options.steal_output)
def main(**kwargs): import sys parser = get_argparse_parser() options = parser.parse_args() args = options.script_args if options.log_errors: from pudb.lowlevel import setlogfile setlogfile(options.log_errors[0]) options_kwargs = { "pre_run": options.pre_run, "steal_output": options.steal_output, } if len(args) < 1: parser.print_help() sys.exit(2) mainpyfile = args[0] sys.argv = args if options.module: from pudb import runmodule runmodule(mainpyfile, **options_kwargs) else: from os.path import exists if not exists(mainpyfile): print("Error: %s does not exist" % mainpyfile, file=sys.stderr) sys.exit(1) from pudb import runscript runscript(mainpyfile, **options_kwargs)
def main(): import sys import argparse parser = argparse.ArgumentParser( usage="%(prog)s [options] [-m] SCRIPT-OR-MODULE-TO-RUN [SCRIPT_ARGS]") parser.add_argument("-s", "--steal-output", action="store_true"), # note: we're implementing -m as a boolean flag, mimicking pdb's behavior, # and makes it possible without much fuss to support cases like: # python -m pudb -m http.server -h # where the -h will be passed to the http.server module parser.add_argument( "-m", "--module", action='store_true', help="Debug as module or package instead of as a script") parser.add_argument("--pre-run", metavar="COMMAND", help="Run command before each program run", default="") parser.add_argument('script_args', nargs=argparse.REMAINDER, help="Arguments to pass to script or module") options = parser.parse_args() args = options.script_args options_kwargs = { 'pre_run': options.pre_run, 'steal_output': options.steal_output, } if len(args) < 1: parser.print_help() sys.exit(2) mainpyfile = args[0] sys.argv = args if options.module: from pudb import runmodule runmodule(mainpyfile, **options_kwargs) else: from os.path import exists if not exists(mainpyfile): print('Error: %s does not exist' % mainpyfile, file=sys.stderr) sys.exit(1) from pudb import runscript runscript(mainpyfile, **options_kwargs)
def pudb_f_v10(self, arg): """ Debug a script (like %run -d) in IPython process, using PuDB. This conforms to IPython version 0.10 Usage: %pudb test.py [args] Run script test.py under PuDB. """ if not arg.strip(): print __doc__ return from IPython.genutils import arg_split args = arg_split(arg) path = os.path.abspath(args[0]) args = args[1:] if not os.path.isfile(path): raise IPython.ipapi.UsageError("%%pudb: file %s does not exist" % path) from pudb import runscript ip.IP.history_saving_wrapper(lambda: runscript(path, args))()
def main(args=None): parser = argparse.ArgumentParser() parser.add_argument( '--steal-output', '-s', action='store_true', ) parser.add_argument( '--pre-run', metavar='COMMAND', default='', help="Run command before each program run", ) run_group = parser.add_argument_group(title="Run options", description="One of the following:") run_group.add_argument( '--module', '-m', help="Run MODULE as a script", ) run_group.add_argument('script', nargs='?', help="Run SCRIPT") arg_group = parser.add_argument_group(title="Run arguments") arg_group.add_argument( 'arguments', nargs=argparse.REMAINDER, help="Arguments for the script or module", ) options = parser.parse_args(args) if options.module and options.script: # `script` is actually the first `arguments` options.arguments.insert(0, options.script) options.script = None from pudb import runscript runscript(options.module or options.script, as_module=bool(options.module), args=options.arguments, pre_run=options.pre_run, steal_output=options.steal_output)