Esempio n. 1
0
def _init_ipython_session(is_wx, source=None, argv=[]):
    """
    Construct new IPython session.
    """
    import IPython
    if IPython.__version__ >= '0.11':
        from IPython.frontend.terminal import ipapp
        # Use an app to parse the command line, and init config.
        app = ipapp.TerminalIPythonApp()
        # Don't draw IPython banner during initialization.
        app.display_banner = False
        app.initialize(argv)
        ip = app.shell

        if is_wx:
            import wx
            from IPython.lib.inputhook import enable_wx
            wxapp = wx.GetApp()
            enable_wx(wxapp)

    else:
        if is_wx:
            from IPython.Shell import IPShellWX

            if source is None:
                source = preexec_source

            aux = {}
            exec source in aux
            ip = IPShellWX(argv, user_ns=aux)

        else:
            ip = IPython.Shell.make_IPython(argv)

    return ip
Esempio n. 2
0
def _init_ipython_session(argv=[]):
    """Construct new IPython session. """
    import IPython
    if IPython.__version__ >= '0.11':
        from IPython.frontend.terminal import ipapp
        # use an app to parse the command line, and init config
        app = ipapp.TerminalIPythonApp()
        # don't draw IPython banner during initialization:
        app.display_banner = False
        app.initialize(argv)
        return app.shell
    else:
        from IPython.Shell import make_IPython
        return make_IPython(argv)
Esempio n. 3
0
def _init_ipython_session(argv=[], auto=False):
    """Construct new IPython session. """
    import IPython

    if IPython.__version__ >= '0.11':
        # use an app to parse the command line, and init config
        from IPython.frontend.terminal import ipapp
        app = ipapp.TerminalIPythonApp()

        # don't draw IPython banner during initialization:
        app.display_banner = False
        app.initialize(argv)

        import re
        re_nameerror = re.compile("name '(?P<symbol>[A-Za-z_][A-Za-z0-9_]*)' is not defined")

        def _handler(self, etype, value, tb, tb_offset=None):
            """Handle :exc:`NameError` exception and allow injection of missing symbols. """
            if etype is NameError and tb.tb_next and not tb.tb_next.tb_next:
                match = re_nameerror.match(str(value))

                if match is not None:
                    self.run_cell("%(symbol)s = Symbol('%(symbol)s')" %
                        {'symbol': match.group("symbol")}, store_history=False)

                    try:
                        code = self.user_ns_hidden['In'][-1]
                    except (KeyError, IndexError):
                        pass
                    else:
                        self.run_cell(code, store_history=False)
                        return None

            stb = self.InteractiveTB.structured_traceback(etype, value, tb, tb_offset=tb_offset)
            self._showtraceback(etype, value, stb)

        if auto:
            app.shell.set_custom_exc((NameError,), _handler)

        return app.shell
    else:
        from IPython.Shell import make_IPython
        return make_IPython(argv)
Esempio n. 4
0
def init_ipython_session(argv=[], auto_symbols=False, auto_int_to_Integer=False):
    """Construct new IPython session. """
    import IPython

    if IPython.__version__ >= '0.11':
        # use an app to parse the command line, and init config
        from IPython.frontend.terminal import ipapp
        app = ipapp.TerminalIPythonApp()

        # don't draw IPython banner during initialization:
        app.display_banner = False
        app.initialize(argv)

        if auto_symbols:
            enable_automatic_symbols(app)
        if auto_int_to_Integer:
            enable_automatic_int_sympification(app)

        return app.shell
    else:
        from IPython.Shell import make_IPython
        return make_IPython(argv)