Python jupyter_client.kernelspec.KernelSpecManager() Examples
The following are 6
code examples of jupyter_client.kernelspec.KernelSpecManager().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
jupyter_client.kernelspec
, or try the search function
.
Example #1
Source File: setup.py From ansible-jupyter-kernel with Apache License 2.0 | 6 votes |
def run(self): # Regular install install.run(self) # Post install print('Installing Ansible Kernel kernelspec') from jupyter_client.kernelspec import KernelSpecManager from IPython.utils.tempdir import TemporaryDirectory kernel_json = { "argv": ["python", "-m", "ansible_kernel", "-f", "{connection_file}"], "codemirror_mode": "yaml", "display_name": "Ansible", "language": "ansible" } with TemporaryDirectory() as td: os.chmod(td, 0o755) with open(os.path.join(td, 'kernel.json'), 'w') as f: json.dump(kernel_json, f, sort_keys=True) ksm = KernelSpecManager() ksm.install_kernel_spec(td, 'ansible', user=self.user, replace=True, prefix=self.prefix)
Example #2
Source File: setup.py From postgres_kernel with MIT License | 5 votes |
def run(self): # Regular installation install.run(self) # Now write the kernelspec from jupyter_client.kernelspec import KernelSpecManager from tempfile import TemporaryDirectory kernel_spec = KernelSpecManager() with TemporaryDirectory() as td: os.chmod(td, 0o755) # Starts off as 700, not user readable with open(os.path.join(td, 'kernel.json'), 'w') as f: json.dump(kernel_json, f, sort_keys=True) # TODO: Copy resources once they're specified kernel_spec.install_kernel_spec(td, 'postgres', user=self.user)
Example #3
Source File: install.py From sos-notebook with BSD 3-Clause "New" or "Revised" License | 5 votes |
def install_sos_kernel_spec(args): user = False prefix = None if args.sys_prefix: prefix = sys.prefix elif args.prefix: prefix = args.prefix elif args.user or not _is_root(): user = True with TemporaryDirectory() as td: os.chmod(td, 0o755) # Starts off as 700, not user readable with open(os.path.join(td, 'kernel.json'), 'w') as f: json.dump(kernel_json, f, sort_keys=True) # Copy resources once they're specified shutil.copy( os.path.join(os.path.split(__file__)[0], 'kernel.js'), os.path.join(td, 'kernel.js')) shutil.copy( os.path.join(os.path.split(__file__)[0], 'logo-64x64.png'), os.path.join(td, 'logo-64x64.png')) KS = KernelSpecManager() KS.log.setLevel(logging.ERROR) KS.install_kernel_spec(td, 'sos', user=user, prefix=prefix) print('sos jupyter kernel spec is installed')
Example #4
Source File: iota_run_nb.py From aws-iot-analytics-notebook-containers with Apache License 2.0 | 5 votes |
def _get_default_kernel_name(): return next(iter(KernelSpecManager().find_kernel_specs().keys()))
Example #5
Source File: setup.py From geonotebook with Apache License 2.0 | 5 votes |
def install_kernel(cmd): # Install the kernel spec when we install the package from ipykernel import kernelspec from jupyter_client.kernelspec import KernelSpecManager kernel_name = 'geonotebook%i' % sys.version_info[0] path = os.path.join(tempfile.mkdtemp(suffix='_kernels'), kernel_name) try: os.makedirs(path) except OSError: pass kernel_dict = { 'argv': kernelspec.make_ipkernel_cmd(mod='geonotebook'), 'display_name': 'Geonotebook (Python %i)' % sys.version_info[0], 'language': 'python', } with open(os.path.join(path, 'kernel.json'), 'w') as fh: json.dump(kernel_dict, fh, indent=1) ksm = KernelSpecManager() ksm.install_kernel_spec( path, kernel_name=kernel_name, user=False, prefix=sys.prefix) shutil.rmtree(path) # shamelessly taken from ipyleaflet: https://github.com/ellisonbg/ipyleaflet # Copyright (c) 2014 Brian E. Granger
Example #6
Source File: notebook.py From pynb with MIT License | 5 votes |
def get_kernelspec(self, name): """Get a kernel specification dictionary given a kernel name """ ksm = KernelSpecManager() kernelspec = ksm.get_kernel_spec(name).to_dict() kernelspec['name'] = name kernelspec.pop('argv') return kernelspec