Beispiel #1
0
def main():
    """ The IPython kernel main entry point.
    """
    parser = make_argument_parser()
    parser.add_argument(
        "--pylab",
        type=str,
        metavar="GUI",
        nargs="?",
        const="auto",
        help="Pre-load matplotlib and numpy for interactive use. If GUI is not \
given, the GUI backend is matplotlib's, otherwise use one of: \
['tk', 'gtk', 'qt', 'wx', 'inline'].",
    )
    parser.add_argument(
        "--colors",
        type=str,
        dest="colors",
        help="Set the color scheme (NoColor, Linux, and LightBG).",
        metavar="ZMQInteractiveShell.colors",
    )
    namespace = parser.parse_args()

    kernel_class = Kernel

    kernel_classes = {
        "qt": QtKernel,
        "qt4": QtKernel,
        "inline": Kernel,
        "wx": WxKernel,
        "tk": TkKernel,
        "gtk": GTKKernel,
    }
    if namespace.pylab:
        if namespace.pylab == "auto":
            gui, backend = pylabtools.find_gui_and_backend()
        else:
            gui, backend = pylabtools.find_gui_and_backend(namespace.pylab)
        kernel_class = kernel_classes.get(gui)
        if kernel_class is None:
            raise ValueError("GUI is not supported: %r" % gui)
        pylabtools.activate_matplotlib(backend)
    if namespace.colors:
        ZMQInteractiveShell.colors = namespace.colors

    kernel = make_kernel(namespace, kernel_class, OutStream)

    if namespace.pylab:
        pylabtools.import_pylab(kernel.shell.user_ns, backend, shell=kernel.shell)

    start_kernel(namespace, kernel)
Beispiel #2
0
def main():
    """ The IPython kernel main entry point.
    """
    parser = make_argument_parser()
    parser.add_argument('--pylab', type=str, metavar='GUI', nargs='?',
                        const='auto', help = \
"Pre-load matplotlib and numpy for interactive use. If GUI is not \
given, the GUI backend is matplotlib's, otherwise use one of: \
['tk', 'gtk', 'qt', 'wx', 'osx', 'inline']."                                            )
    parser.add_argument(
        '--colors',
        type=str,
        dest='colors',
        help="Set the color scheme (NoColor, Linux, and LightBG).",
        metavar='ZMQInteractiveShell.colors')
    namespace = parser.parse_args()

    kernel_class = Kernel

    kernel_classes = {
        'qt': QtKernel,
        'qt4': QtKernel,
        'inline': Kernel,
        'osx': TkKernel,
        'wx': WxKernel,
        'tk': TkKernel,
        'gtk': GTKKernel,
    }
    if namespace.pylab:
        if namespace.pylab == 'auto':
            gui, backend = pylabtools.find_gui_and_backend()
        else:
            gui, backend = pylabtools.find_gui_and_backend(namespace.pylab)
        kernel_class = kernel_classes.get(gui)
        if kernel_class is None:
            raise ValueError('GUI is not supported: %r' % gui)
        pylabtools.activate_matplotlib(backend)
    if namespace.colors:
        ZMQInteractiveShell.colors = namespace.colors

    kernel = make_kernel(namespace, kernel_class, OutStream)

    if namespace.pylab:
        pylabtools.import_pylab(kernel.shell.user_ns,
                                backend,
                                shell=kernel.shell)

    start_kernel(namespace, kernel)
    def init_kernel(self):
        kernel_factory = Kernel

        kernel_map = {
            'qt' : QtKernel,
            'qt4': QtKernel,
            'inline': Kernel,
            'osx': TkKernel,
            'wx' : WxKernel,
            'tk' : TkKernel,
            'gtk': GTKKernel,
        }

        if self.pylab:
            key = None if self.pylab == 'auto' else self.pylab
            gui, backend = pylabtools.find_gui_and_backend(key)
            kernel_factory = kernel_map.get(gui)
            if kernel_factory is None:
                raise ValueError('GUI is not supported: %r' % gui)
            pylabtools.activate_matplotlib(backend)

        kernel = kernel_factory(config=self.config, session=self.session,
                                shell_socket=self.shell_socket,
                                iopub_socket=self.iopub_socket,
                                stdin_socket=self.stdin_socket,
                                log=self.log
        )
        self.kernel = kernel
        kernel.record_ports(self.ports)

        if self.pylab:
            import_all = self.pylab_import_all
            pylabtools.import_pylab(kernel.shell.user_ns, backend, import_all,
                                    shell=kernel.shell)
Beispiel #4
0
    def init_kernel(self):
        kernel_factory = Kernel

        kernel_map = {
            "qt": QtKernel,
            "qt4": QtKernel,
            "inline": Kernel,
            "osx": OSXKernel,
            "wx": WxKernel,
            "tk": TkKernel,
            "gtk": GTKKernel,
        }

        if self.pylab:
            key = None if self.pylab == "auto" else self.pylab
            gui, backend = pylabtools.find_gui_and_backend(key)
            kernel_factory = kernel_map.get(gui)
            if kernel_factory is None:
                raise ValueError("GUI is not supported: %r" % gui)
            pylabtools.activate_matplotlib(backend)

        kernel = kernel_factory(
            config=self.config,
            session=self.session,
            shell_socket=self.shell_socket,
            iopub_socket=self.iopub_socket,
            stdin_socket=self.stdin_socket,
            log=self.log,
        )
        self.kernel = kernel
        kernel.record_ports(self.ports)

        if self.pylab:
            import_all = self.pylab_import_all
            pylabtools.import_pylab(kernel.shell.user_ns, backend, import_all, shell=kernel.shell)
Beispiel #5
0
    def init_kernel(self):

        kernel = Kernel(config=self.config, session=self.session,
                                shell_socket=self.shell_socket,
                                iopub_socket=self.iopub_socket,
                                stdin_socket=self.stdin_socket,
                                log=self.log,
                                profile_dir=self.profile_dir,
        )
        self.kernel = kernel
        kernel.record_ports(self.ports)
        shell = kernel.shell
        if self.pylab:
            try:
                gui, backend = pylabtools.find_gui_and_backend(self.pylab)
                shell.enable_pylab(gui, import_all=self.pylab_import_all)
            except Exception:
                self.log.error("Pylab initialization failed", exc_info=True)
                # print exception straight to stdout, because normally 
                # _showtraceback associates the reply with an execution, 
                # which means frontends will never draw it, as this exception 
                # is not associated with any execute request.
                
                # replace pyerr-sending traceback with stdout
                _showtraceback = shell._showtraceback
                def print_tb(etype, evalue, stb):
                    print ("Error initializing pylab, pylab mode will not be active", file=io.stderr)
                    print (shell.InteractiveTB.stb2text(stb), file=io.stdout)
                shell._showtraceback = print_tb
                
                # send the traceback over stdout
                shell.showtraceback(tb_offset=0)
                
                # restore proper _showtraceback method
                shell._showtraceback = _showtraceback
Beispiel #6
0
def main():
    """ The IPython kernel main entry point.
    """
    parser = make_argument_parser()
    parser.add_argument('--pylab', type=str, metavar='GUI', nargs='?', 
                        const='auto', help = \
"Pre-load matplotlib and numpy for interactive use. If GUI is not \
given, the GUI backend is matplotlib's, otherwise use one of: \
['tk', 'gtk', 'qt', 'wx', 'osx', 'inline'].")
    parser.add_argument('--colors',
        type=str, dest='colors',
        help="Set the color scheme (NoColor, Linux, and LightBG).",
        metavar='ZMQInteractiveShell.colors')
    namespace = parser.parse_args()

    kernel_class = Kernel

    kernel_classes = {
        'qt' : QtKernel,
        'qt4': QtKernel,
        'inline': Kernel,
        'osx': TkKernel,
        'wx' : WxKernel,
        'tk' : TkKernel,
        'gtk': GTKKernel,
    }
    if namespace.pylab:
        if namespace.pylab == 'auto':
            gui, backend = pylabtools.find_gui_and_backend()
        else:
            gui, backend = pylabtools.find_gui_and_backend(namespace.pylab)
        kernel_class = kernel_classes.get(gui)
        if kernel_class is None:
            raise ValueError('GUI is not supported: %r' % gui)
        pylabtools.activate_matplotlib(backend)
    if namespace.colors:
        ZMQInteractiveShell.colors=namespace.colors

    kernel = make_kernel(namespace, kernel_class, OutStream)

    if namespace.pylab:
        pylabtools.import_pylab(kernel.shell.user_ns, backend,
                                shell=kernel.shell)

    start_kernel(namespace, kernel)
Beispiel #7
0
    def init_kernel(self):
        kernel_factory = Kernel

        if self.pylab:
            gui, backend = pylabtools.find_gui_and_backend(self.pylab)

        kernel = kernel_factory(config=self.config, session=self.session,
                                shell_socket=self.shell_socket,
                                iopub_socket=self.iopub_socket,
                                stdin_socket=self.stdin_socket,
                                log=self.log,
        )
        self.kernel = kernel
        kernel.record_ports(self.ports)

        if self.pylab:
            kernel.shell.enable_pylab(gui, import_all=self.pylab_import_all)
Beispiel #8
0
    def init_kernel(self):
        kernel_factory = Kernel

        kernel_map = {
            'qt': QtKernel,
            'qt4': QtKernel,
            'inline': Kernel,
            'osx': TkKernel,
            'wx': WxKernel,
            'tk': TkKernel,
            'gtk': GTKKernel,
        }

        if self.pylab:
            key = None if self.pylab == 'auto' else self.pylab
            gui, backend = pylabtools.find_gui_and_backend(key)
            kernel_factory = kernel_map.get(gui)
            if kernel_factory is None:
                raise ValueError('GUI is not supported: %r' % gui)
            pylabtools.activate_matplotlib(backend)

        kernel = kernel_factory(config=self.config,
                                session=self.session,
                                shell_socket=self.shell_socket,
                                iopub_socket=self.iopub_socket,
                                stdin_socket=self.stdin_socket,
                                log=self.log)
        self.kernel = kernel
        kernel.record_ports(self.ports)

        if self.pylab:
            import_all = self.pylab_import_all
            pylabtools.import_pylab(kernel.shell.user_ns,
                                    backend,
                                    import_all,
                                    shell=kernel.shell)