Пример #1
0
    def __init__(self, nb, pylab=False, mpl_inline=False, profile_dir=None, working_dir=None, kernel=None, port=None):
        self.km = KernelManager()

        args = []

        if pylab:
            args.append('--pylab=inline')
            logging.warn('--pylab is deprecated and will be removed in a future version')
        elif mpl_inline:
            args.append('--matplotlib=inline')
            logging.warn('--matplotlib is deprecated and will be removed in a future version')

        if profile_dir:
            args.append('--profile-dir=%s' % os.path.abspath(profile_dir))

        cwd = os.getcwd()

        if working_dir:
            os.chdir(working_dir)

        if kernel is not None:
            logging.info("Starting {0} kernel".format(kernel))
            ksm = KernelSpecManager()
            kernel_specs = ksm.find_kernel_specs()
            if not kernel in kernel_specs:
                logging.info("Installed kernels: {0}".format(', '.join(kernel_specs)))
            # throws NoSuchKernel when not found
            self.km.kernel_spec = ksm.get_kernel_spec(kernel)

        if port is None:
            self.km.start_kernel(extra_arguments=args)
        else:
            self.km.start_kernel(extra_arguments=args, port=port)
        
        os.chdir(cwd)

        if platform.system() == 'Darwin':
            # There is sometimes a race condition where the first
            # execute command hits the kernel before it's ready.
            # It appears to happen only on Darwin (Mac OS) and an
            # easy (but clumsy) way to mitigate it is to sleep
            # for a second.
            sleep(1)

        self.kc = self.km.client()
        self.kc.start_channels()
        try:
            self.kc.wait_for_ready()
        except AttributeError:
            # IPython < 3
            self._wait_for_ready_backport()

        self.nb = nb
Пример #2
0
    def run(self):
        install.run(self)

        from IPython.kernel.kernelspec import KernelSpecManager
        from IPython.utils.path import ensure_dir_exists
        destdir = os.path.join(KernelSpecManager().user_kernel_dir, 'IDL')
        ensure_dir_exists(destdir)
        with open(os.path.join(destdir, 'kernel.json'), 'w') as f:
            json.dump(kernel_json, f, sort_keys=True)
Пример #3
0
    def run(self):
        # Regular installation
        install.run(self)

        # Now write the kernelspec
        from IPython.kernel.kernelspec import KernelSpecManager
        from IPython.utils.path import ensure_dir_exists
        destdir = os.path.join(KernelSpecManager().user_kernel_dir, LANGUAGE)
        ensure_dir_exists(destdir)
        with open(os.path.join(destdir, 'kernel.json'), 'w') as f:
            json.dump(kernel_json, f, sort_keys=True)
Пример #4
0
def setup_assets(user=False, ipython_dir=None):
    # Now write the kernelspec
    from IPython.kernel.kernelspec import (
        KernelSpecManager,
        install_kernel_spec,
    )

    if ipython_dir is None:
        install = install_kernel_spec
    else:
        ksm = KernelSpecManager(ipython_dir=ipython_dir)
        install = ksm.install_kernel_spec

    install(join(pkgroot, 'assets'), 'hy', replace=True, user=user)
Пример #5
0
 def _kernel_spec_manager_default(self):
     return KernelSpecManager(ipython_dir=self.ipython_dir)
Пример #6
0
 def init_kernel_manager(self):
     self._km = MultiKernelManager(log=self.log, parent=self)
     self._ksm = KernelSpecManager(log=self.log, parent=self)
     self._kernels = {}