예제 #1
0
def main():
    '''Run module as a script

    Uses :py:func:`pdb.main` function directly, but prior to that it mocks
    :py:class:`pdb.Pdb` class with powerline-specific class instance.
    '''
    orig_pdb = pdb.Pdb

    @use_powerline_prompt
    class Pdb(pdb.Pdb, object):
        def __init__(self):
            orig_pdb.__init__(self)

    pdb.Pdb = Pdb

    return pdb.main()
예제 #2
0
def main():
	'''Run module as a script

	Uses :py:func:`pdb.main` function directly, but prior to that it mocks 
	:py:class:`pdb.Pdb` class with powerline-specific class instance.
	'''
	orig_pdb = pdb.Pdb

	@use_powerline_prompt
	class Pdb(pdb.Pdb, object):
		def __init__(self):
			orig_pdb.__init__(self)

	pdb.Pdb = Pdb

	return pdb.main()
예제 #3
0
    while True:
        try:
            pdb._runscript(mainpyfile)
            if pdb._user_requested_quit:
                break
            print "The program finished and will be restarted"
        except Restart:
            print "Restarting", mainpyfile, "with arguments:"
            print "\t" + " ".join(sys.argv[1:])
        except SystemExit:
            # In most cases SystemExit does not warrant a post-mortem session.
            print "The program exited via sys.exit(). Exit status: ",
            print sys.exc_info()[1]
        except SyntaxError:
            traceback.print_exc()
            sys.exit(1)
        except:
            traceback.print_exc()
            print "Uncaught exception. Entering post mortem debugging"
            print "Running 'cont' or 'step' will restart the program"
            t = sys.exc_info()[2]
            pdb.interaction(None, t)
            print "Post mortem debugger finished. The " + mainpyfile + \
                  " will be restarted"


# When invoked as main program, invoke the debugger on a script
if __name__ == '__main__':
    import pdb
    pdb.main()
예제 #4
0
    # changed by the user from the command line. There is a "restart" command
    # which allows explicit specification of command line arguments.
    pdb = Pdb()
    while True:
        try:
            pdb._runscript(mainpyfile)
            if pdb._user_requested_quit:
                break
            shout "The program finished and will be restarted"
        except Restart:
            shout "Restarting", mainpyfile, "with arguments:"
            shout "\t" + " ".join(sys.argv[1:])
        except SystemExit:
            # In most cases SystemExit does not warrant a post-mortem session.
            shout "The program exited via sys.exit(). Exit status: ",
            shout sys.exc_info()[1]
        except:
            traceback.print_exc()
            shout "Uncaught exception. Entering post mortem debugging"
            shout "Running 'cont' or 'step' will restart the program"
            t = sys.exc_info()[2]
            pdb.interaction(None, t)
            shout "Post mortem debugger finished. The " + mainpyfile + \
                  " will be restarted"


# When invoked as main program, invoke the debugger on a script
if __name__ == '__main__':
    import pdb
    pdb.main()
예제 #5
0
파일: console.py 프로젝트: WinterXMQ/Pyto
        def run() -> None:

            pip_directory = os.path.expanduser("~/Documents/modules")
            Python.shared.isScriptRunning = True
            os.chdir(currentDir)
            try:
                sys.path.remove(pip_directory)
            except:
                pass
            sys.path.insert(-1, currentDir)
            sys.path.insert(-1, pip_directory)

            try:
                global __script__
                spec = importlib.util.spec_from_file_location("__main__", path)
                __script__ = importlib.util.module_from_spec(spec)

                if debug and "widget" not in os.environ:

                    try:
                        console
                    except:
                        import console

                    console.__are_breakpoints_set__ = False
                    console.__breakpoints__ = breakpoints

                    console.__i__ = -1

                    old_input = input

                    def debugger_input(prompt):

                        try:
                            console
                        except:
                            import console

                        if not console.__are_breakpoints_set__:

                            breakpoints = console.__breakpoints__
                            console.__i__ += 1

                            if len(breakpoints) < console.__i__:
                                console.__are_breakpoints_set__ = True
                                return ""

                            try:
                                breakpoints[console.__i__ + 1]
                            except:
                                console.__are_breakpoints_set__ = True

                            return "b " + str(breakpoints[console.__i__])
                        else:
                            console.__should_inspect__ = True
                            return old_input(prompt)

                    if len(breakpoints) > 0:
                        builtins.input = debugger_input

                    pdb.main(["pdb", path])
                    builtins.input = old_input
                else:
                    spec.loader.exec_module(__script__)
            except SystemExit:
                pass
            except KeyboardInterrupt:
                pass
            except Exception as e:

                if not __isMainApp__() or replMode:
                    print(traceback.format_exc())
                    if not replMode:
                        Python.shared.fatalError(traceback.format_exc())
                else:
                    exc_type, exc_obj, exc_tb = sys.exc_info()

                    extracts = traceback.extract_tb(sys.exc_info()[2])
                    count = len(extracts)

                    lineNumber = -1

                    fileName = path
                    for i, extract in enumerate(extracts):
                        if extract[0] == fileName:
                            lineNumber = extract[1]
                            break
                        count -= 1

                    if (
                            type(e) == SyntaxError
                    ):  # The last word in a `SyntaxError` exception is the line number
                        lineNumber = [
                            int(s) for s in (str(e)[:-1]).split()
                            if s.isdigit()
                        ][-1]

                    Python.shared.errorType = exc_type.__name__
                    Python.shared.errorReason = str(e)
                    for console in ConsoleViewController.visibles:
                        if console.editorSplitViewController.editor.document.fileURL.path != path:
                            continue
                        console.editorSplitViewController.editor.showErrorAtLine(
                            lineNumber)

                    error = traceback.format_exc(limit=-count)

                    try:
                        PyOutputHelper.printError(
                            error,
                            script=threading.current_thread().script_path)
                    except AttributeError:
                        PyOutputHelper.printError(error, script=None)

                    if "cv2.error" in error and "!_src.empty()" in error:
                        string = "\nOn Pyto, 'cv2.VideoCapture.read' may return an invalid value the first time. If you are running a loop for capturing a video from the camera, check if the return value is valid before using it. See the 'OpenCV/face_detection.py' example.\n"
                        try:
                            PyOutputHelper.printError(
                                string,
                                script=threading.current_thread().script_path)
                        except AttributeError:
                            PyOutputHelper.printError(string, script=None)

                    sys.path.remove(currentDir)

                    if debug:
                        pdb.post_mortem(exc_tb)

            if __isMainApp__():

                EditorViewController.runningLine = 0

                ConsoleViewController.enableDoneButton()

                ReviewHelper.shared.launches = ReviewHelper.shared.launches + 1
                ReviewHelper.shared.requestReview()
예제 #6
0
    def run() -> None:

        if __platform__ is iOS:
            Python.shared.isScriptRunning = True
            os.system = Python.shared.system
            directory = os.path.expanduser(os.path.dirname(path))
            os.chdir(directory)
            sys.path.insert(0, directory)

        try:
            global __script__
            spec = importlib.util.spec_from_file_location("__main__", path)
            __script__ = importlib.util.module_from_spec(spec)

            if debug and __platform__ is iOS and __host__ is not widget:

                try:
                    console
                except:
                    import console

                console.__are_breakpoints_set__ = False
                console.__should_inspect__ = True
                console.__breakpoints__ = breakpoints

                console.__i__ = -1

                old_input = input

                def debugger_input(prompt):

                    try:
                        console
                    except:
                        import console

                    if not console.__are_breakpoints_set__:

                        breakpoints = console.__breakpoints__
                        console.__i__ += 1

                        if len(breakpoints) < console.__i__:
                            console.__are_breakpoints_set__ = True
                            return ""

                        try:
                            breakpoints[console.__i__ + 1]
                        except:
                            console.__are_breakpoints_set__ = True

                        return "b " + str(breakpoints[console.__i__])
                    elif not console.__should_inspect__:
                        console.__should_inspect__ = True
                        return old_input(prompt)
                    else:
                        console.__should_inspect__ = False
                        return "from pyto import ConsoleViewController; from _get_variables_hierarchy import get_variables_hierarchy; ConsoleViewController.variables = get_variables_hierarchy(locals())"

                if len(breakpoints) > 0:
                    builtins.input = debugger_input

                pdb.main(["pdb", path])
                builtins.input = old_input
            else:
                spec.loader.exec_module(__script__)
        except SystemExit:
            pass
        except KeyboardInterrupt:
            pass
        except Exception as e:

            if __platform__ is iOS and not __isMainApp__() or replMode:
                print(traceback.format_exc())
                if not replMode:
                    Python.shared.fatalError(str(e))
            else:
                exc_type, exc_obj, exc_tb = sys.exc_info()

                extracts = traceback.extract_tb(sys.exc_info()[2])
                count = len(extracts)

                lineNumber = -1

                fileName = path
                for i, extract in enumerate(extracts):
                    if extract[0] == fileName:
                        lineNumber = extract[1]
                        break
                    count -= 1

                if (
                        type(e) == SyntaxError
                ):  # The last word in a `SyntaxError` exception is the line number
                    lineNumber = [
                        int(s) for s in (str(e)[:-1]).split() if s.isdigit()
                    ][-1]

                if __platform__ is iOS:
                    Python.shared.errorType = exc_type.__name__
                    Python.shared.errorReason = str(e)
                    EditorSplitViewController.visible.editor.showErrorAtLine(
                        lineNumber)
                elif __platform__ is macOS:
                    print("Pyto.error_at_line;" + str(lineNumber) + ";")

                error = traceback.format_exc(limit=-count)

                if __platform__ is iOS:
                    PyOutputHelper.printError(error)
                    sys.path.remove(directory)
                else:
                    sys.stderr.write(error + "\n")

                if debug:
                    pdb.post_mortem(exc_tb)

        if __platform__ is iOS and __isMainApp__():

            EditorViewController.runningLine = 0

            ReviewHelper.shared.launches = ReviewHelper.shared.launches + 1
            ReviewHelper.shared.requestReview()
예제 #7
0
파일: nodes.py 프로젝트: xxoolm/Ryven
 def update_event(self, inp=-1):
     self.set_output_val(0, pdb.main())
예제 #8
0
def main():
    pdb.Pdb = RichPdb
    pdb.main()
예제 #9
0
 def main(self):
     pdb.main()