def run(self): try: from jupyter_client.kernelspec import install_kernel_spec except ImportError: try: from IPython.kernel.kernelspec import install_kernel_spec except ImportError: print( "Please install either Jupyter to IPython before continuing" ) # Regular installation install.run(self) from IPython.utils.tempdir import TemporaryDirectory # Now write the kernelspec with TemporaryDirectory() as temppath: os.chmod(temppath, 0o755) # Starts off as 700, not user readable log.info('Installing Jupyter kernel spec') with open(os.path.join(temppath, 'kernel.json'), 'w') as f: json.dump(kernel_json, f, sort_keys=True) copyfile(os.path.join(_dataRoot, 'logo-64x64.png'), os.path.join(temppath, 'logo-64x64.png')) log.info('files copied to kernel:') for i in os.listdir(temppath): log.info(i) try: install_kernel_spec(temppath, 'SAS', user=False, replace=True) print("SAS Kernel installed as superuser") except: install_kernel_spec(temppath, 'SAS', user=True, replace=True) print("SAS Kernel installed as user")
def install_kernelspec(lib_dir, kernel_dir=None, user=True): if kernel_dir is None: kernel_dir = os.path.join(lib_dir, "kernel", "lambda-notebook") if lib_dir: # TODO: won't override an installed copy of lamb in site-packages (e.g. # in the app), fix this # the following line is to deal with a messy escaping situation for # windows paths this may fail horribly on unix paths with backslashes, # but I don't have a better workaround for now lib_dir = lib_dir.replace("\\", "\\\\\\\\") injection_path_opt = ( "--IPKernelApp.exec_lines=[\"import sys\",\"sys.path.insert(1,\\\"%s\\\")\", \"import lamb.lnsetup\", \"lamb.lnsetup.ipython_setup()\"]" % lib_dir) else: injection_path_opt = "--IPKernelApp.exec_lines=[\"import lamb.lnsetup\", \"lamb.lnsetup.ipython_setup()\"]" k_json = build_json() k_json["argv"].append(injection_path_opt) k_json_filename = os.path.join(kernel_dir, "kernel.json") #print(k_json) with open(k_json_filename, 'w') as k_json_file: json.dump(k_json, k_json_file, sort_keys=True, indent=4) kernelspec.install_kernel_spec(kernel_dir, user=user, replace=True) location = kernelspec.find_kernel_specs()['lambda-notebook'] return location
def run(self): _install.run(self) if not install_kernel_spec: log.error("Cannot import 'jupyter_client' package. " "The 'ldap3-ipython' jupyter kernel will *not* " "be installed.") traceback.print_exception(*exc_info_install_kernel_spec) return kernelspec_prefix = None if not self.no_kernelspec_prefix and self.prefix: kernelspec_prefix = os.path.normpath((self.root or '') + self.prefix) with TemporaryDirectory() as dirname: os.chmod(dirname, 0o755) with open(os.path.join(dirname, "kernel.json"), 'w') as fd: json.dump(kernel_json, fd, sort_keys=True) try: log.debug("kernelspec_prefix: %r" % kernelspec_prefix) install_kernel_spec(dirname, kernel_json["name"], user=False, prefix=kernelspec_prefix) except OSError: if kernelspec_prefix: raise log.warn("Could not install 'ldap3-ipython' jupyter kernel in " "a system-wide location. Performing user install.") install_kernel_spec(dirname, kernel_json["name"], user=True, prefix=kernelspec_prefix)
def install_jupyter_hook(): if not HAVE_JUPYTER: print('Could not install Jupyter kernel spec, please install Jupyter/IPython.') return spec = {"argv": [sys.executable, "-m", "xonsh.jupyter_kernel", "-f", "{connection_file}"], "display_name":"Xonsh", "language":"xonsh", "codemirror_mode":"shell", } if CONDA: d = os.path.join(sys.prefix + '/share/jupyter/kernels/xonsh/') os.makedirs(d, exist_ok=True) if sys.platform == 'win32': # Ensure that conda-build detects the hard coded prefix spec['argv'][0] = spec['argv'][0].replace(os.sep, os.altsep) with open(os.path.join(d, 'kernel.json'), 'w') as f: json.dump(spec, f, sort_keys=True) else: with TemporaryDirectory() as d: os.chmod(d, 0o755) # Starts off as 700, not user readable with open(os.path.join(d, 'kernel.json'), 'w') as f: json.dump(spec, f, sort_keys=True) print('Installing Jupyter kernel spec...') install_kernel_spec(d, 'xonsh', user=('--user' in sys.argv), replace=True)
def install_gauche_kernel_spec(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) print('Installing IPython kernel spec') install_kernel_spec(td, 'gauche', user=user, replace=True)
def install_my_kernel_spec(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) print('Installing IPython kernel spec') install_kernel_spec(td, 'stata', user=user, replace=True)
def install_my_kernel_spec(user=False): with TemporaryDirectory() as td: os.chmod(td, 0o755) # Starts off as 700, not user readable path_of_file = dirname(abspath(__file__)) file_copy(path_of_file + "/mikrokosmoskernel/kernel.js", td) file_copy(path_of_file + "/mikrokosmoskernel/kernel.json", td) print('Installing Jupyter kernel spec') install_kernel_spec(td, 'IMikrokosmos', user=user, replace=True)
def install_my_kernel_spec(user=True): 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) print('Installing IPython kernel spec') install_kernel_spec(td, 'mmt', user=user, replace=True)
def write_notebook(self,specname=None,backup=None,keyname=None): ''' write keyvalue into database notebook kernel file This is an experimantal feature ... wouldnt advise using it ''' verbose = self.verbose # see https://jupyter-client.readthedocs.io/en/latest/kernels.html specname = specname or self.database backup = backup or self.backup keyname = keyname or self.keyname try: # exists spec = kernelspec.get_kernel_spec(specname) except: # doesnt exist spec = kernelspec.get_kernel_spec(backup) kernel_file = kernelspec.find_kernel_specs()[backup] # create specname # try as user then not try: kernelspec.install_kernel_spec(kernel_file, kernel_name=specname, user=False,replace=True) except: kernelspec.install_kernel_spec(kernel_file, kernel_name=specname, user=True,replace=True) try: spec = kernelspec.get_kernel_spec(specname) # now load specname # make a name derived from specname spec.display_name = ' '.join([i.capitalize() for i in specname.split('_')]) # make sure language is python spec.language='python' # add env variable if we can if spec.has_trait('env'): spec.env[keyname] = keyvalue else: # work out how to add env trait at some point pass # Serializing json json_object = spec.to_json() # write this out kernel = Path(spec.resource_dir + '/kernel.json') kernel.parent.mkdir(parents=True, exist_ok=True) with open(kernel, 'w') as f: if verbose: print(f'jupyter kernel written to {kernel}') f.write(json_object) self.make_icons(spec.resource_dir) # load again for luck spec = kernelspec.get_kernel_spec(specname) return spec except: return None
def install_my_kernel_spec(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) # TODO: Copy resources once they're specified print('Installing IPython kernel spec Geoscript Groovy') install_kernel_spec(td, 'geoscript-groovy', user=user, replace=True)
def install_my_kernel_spec(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) # TODO: Copy resources once they're specified print('Installing IPython kernel spec to connect to cassandra host "%s"' % hostname) install_kernel_spec(td, 'CQL', user=user, replace=True)
def install_my_kernel_spec(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) # TODO: Copy resources once they're specified print("Installing IPython kernel spec") install_kernel_spec(td, "magma", user=user, replace=True)
def install_my_kernel_spec(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) kernel_name = kernel_json['name'] try: install_kernel_spec(td, kernel_name, user=user, replace=True) except: install_kernel_spec(td, kernel_name, user=not user, replace=True)
def install_my_kernel_spec(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) path_of_file = dirname( abspath(__file__) ) + "/resources/" file_copy(path_of_file + "logo-32x32.png", td ) file_copy(path_of_file + "logo-64x64.png", td ) print('Installing IPython kernel spec') install_kernel_spec(td, 'Singular', user=user, replace=True)
def main(argv=[]): user = '******' in argv or os.geteuid() != 0 with TemporaryDirectory() as td: # IPython tempdir starts off as 700, not user readable os.chmod(td, 0o755) with open(os.path.join(td, 'kernel.json'), 'w') as f: json.dump(kernel_json, f, sort_keys=True) print('Installing IPython kernel spec') install_kernel_spec(td, 'qsh', user=user, replace=True)
def main(argv=[]): user = '******' in argv or os.geteuid() != 0 with TemporaryDirectory() as td: # IPython tempdir starts off as 700, not user readable os.chmod(td, 0o755) with open(os.path.join(td, 'kernel.json'), 'w') as f: json.dump(kernel_json, f, sort_keys=True) print('Installing IPython kernel spec') install_kernel_spec(td, 'qsh', user=user, replace=True)
def install_my_kernel_spec(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) # TODO: Copy resources once they're specified path_of_file = dirname(abspath(__file__)) + "/resources/" file_copy(path_of_file + "logo-32x32.png", td) file_copy(path_of_file + "logo-64x64.png", td) print('Installing Jupyter kernel spec from') install_kernel_spec(td, 'gap', user=user, replace=True)
def clone_kernelspec(self, kernelspec, kernel_name): if kernelspec is not None: with TemporaryDirectory() as tmpdir: with open(os.path.join(tmpdir, "kernel.json"), "w+") as tmpfile: tmpfile.write(kernelspec) install_kernel_spec( source_dir=tmpdir, kernel_name=kernel_name, user=True ) else: self.log.warning( "Failed to install kernelspec, as there was no kernelspec to be installed." )
def install_my_kernel_spec(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) kernel_name = kernel_json['name'] try: install_kernel_spec(td, kernel_name, user=user, replace=True) except: install_kernel_spec(td, kernel_name, user=not user, replace=True)
def main(argv=None): if argv is None: argv = [] user = "******" in argv or os.geteuid() != 0 with TemporaryDirectory() as td: # IPython tempdir starts off as 700, not user readable os.chmod(td, 0o755) with open(os.path.join(td, "kernel.json"), "w") as f: json.dump(kernel_json, f, sort_keys=True) print("Installing IPython kernel spec") install_kernel_spec(td, "qshell", user=user, replace=True)
def main(argv=None): if argv is None: argv = [] user = "******" in argv or os.geteuid() != 0 with TemporaryDirectory() as td: # IPython tempdir starts off as 700, not user readable os.chmod(td, 0o755) with open(os.path.join(td, "kernel.json"), "w") as f: json.dump(kernel_json, f, sort_keys=True) print("Installing IPython kernel spec") install_kernel_spec(td, "qshell", user=user, replace=True)
def run(self): # global wmmcaller global wmmexec # Determine if the executable is Wolfram Mathematica or mathics # starttext = os.popen("bash -c 'echo |" + wmmexec +"'").read() # if starttext[:11] == "Mathematica": # wmmcaller = wmmexec # if wmmcaller is None: # wmmcaller = '/usr/local/bin/iwolframcaller.sh' # with open(wmmcaller,'w') as f: # f.write("#!/bin/sh\n\n") # f.write("# sh envelopment for the true math command ") # f.write("necesary to avoid the kernel hangs on jupyterhub\n\n\n ") # f.write(wmmexec + " $@") # os.chmod(wmmcaller, 0o755) # else: # wmmcaller = wmmexec # Build the configuration file configfilestr = "# iwolfram configuration file\nmathexec = '{wolfram-caller-script-path}'\n\n" configfilestr = configfilestr.replace('{wolfram-caller-script-path}', wmmexec) with open('wolfram_kernel/config.py', 'w') as f: f.write(configfilestr) #Run the standard intallation install.run(self) print("Installing kernel spec") #Build and Install the kernelspec from wolfram_kernel.wolfram_kernel import WolframKernel kernel_json = WolframKernel.kernel_json 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) log.info('Installing kernel spec') #install_kernel_resources(td,files=['logo-64x64.png']) kernel_name = kernel_json['name'] try: install_kernel_spec(td, kernel_name, user=self.user, replace=True) except: install_kernel_spec(td, kernel_name, user=not self.user, replace=True)
def run(self): # Regular installation install.run(self) # Now write the kernelspec 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) log.info('Installing IPython kernel spec') try: install_kernel_spec(td, 'SAS', user=self.user, replace=True) except: print("Could not install SAS Kernel as %s user" % self.user)
def run(self): install.run(self) try: from jupyter_client.kernelspec import install_kernel_spec except ImportError: from IPython.kernel.kernelspec import install_kernel_spec from IPython.utils.tempdir import TemporaryDirectory # Install unix port with TemporaryDirectory() as td: os.chmod(td, 0o755) with open(os.path.join(td, 'kernel.json'), 'w') as f: json.dump(kernel_json_unix, f, sort_keys=True) kernel_name = 'mp' + pkg_unix try: install_kernel_spec(td, kernel_name=kernel_name, user=self.user, replace=True) except: install_kernel_spec(td, kernel_name=kernel_name, user=not self.user, replace=True) # Install pyboard port with TemporaryDirectory() as td: os.chmod(td, 0o755) with open(os.path.join(td, 'kernel.json'), 'w') as f: json.dump(kernel_json_pyboard, f, sort_keys=True) kernel_name = 'mp' + pkg_stmhal try: install_kernel_spec(td, kernel_name=kernel_name, user=self.user, replace=True) except: install_kernel_spec(td, kernel_name=kernel_name, user=not self.user, replace=True)
def run(self): # Regular installation install.run(self) # Now write the kernelspec 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) log.info('Installing IPython kernel spec') try: install_kernel_spec(td, 'SAS', user=self.user, replace=True) except: print("Could not install SAS Kernel as %s user" % self.user)
def run(self): # Regular installation install.run(self) # Now write the kernelspec from jupyter_client.kernelspec import install_kernel_spec from IPython.utils.tempdir import TemporaryDirectory 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 log.info('Installing Virtuoso kernel spec') install_kernel_spec(td, 'virtuoso', user=self.user, replace=True)
def install_my_kernel_spec(user=True, prefix=None): user = '******' in sys.argv or not _is_root() 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) kernel_name = kernel_json['name'] copyfile(os.path.join(_dataRoot, 'logo-64x64.png'), os.path.join(td, 'logo-64x64.png')) try: install_kernel_spec(td, kernel_name, user=user, replace=True, prefix=prefix) except: install_kernel_spec(td, kernel_name, user=not user, replace=True, prefix=prefix)
def run(self): from notebook.nbextensions import enable_nbextension # run from distutils install _install.run(self) #install kernel specs 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) print('Installing IPython kernel spec') install_kernel_spec(td, 'Singular', user=self.user, replace=True) # enable codemirror notebook extension enable_nbextension('notebook', 'singular-mode/main')
def install(args): # Write kernel spec in a temporary directory user = False if "user" in args: user = args.user print("Installing jupyter kernel spec") install_kernel_spec('etc/jupyter/', kernel_name='gap-4', user=user) print("Installing nbextension for syntax hilighting") install_nbextension('etc/gap-mode', overwrite=True, user=user) enable_nbextension( 'notebook', 'gap-mode/main', )
def run(self): # Regular installation install.run(self) # Now write the kernelspec from jupyter_client.kernelspec import install_kernel_spec from IPython.utils.tempdir import TemporaryDirectory 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 log.info('Installing IPython kernel spec') install_kernel_spec(td, 'virtuoso', user=self.user, replace=True)
def install_my_kernel_spec(user=True): ldflags, ld_lib_path = find_boost_ldflags() env = { "CXX": find_compiler(), "CPPFLAGS": quote_list(find_boost_cppflags()), "LDFLAGS": quote_list(ldflags), "RUNTIME_LIB_PATH": '' } 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(make_kernel_json(env), f, sort_keys=True) # TODO: Copy resources once they're specified print('Installing IPython kernel spec') install_kernel_spec(td, 'fakerepl', user=user, replace=True) for name in sorted(env): print("%s=%s" % (name, env[name]))
def run(self): install.run(self) 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) log.info('Installing kernel spec') install_kernel_resources(td, files=['logo-64x64.png']) kernel_name = kernel_json['name'] try: install_kernel_spec(td, kernel_name, user=self.user, replace=True) except: install_kernel_spec(td, kernel_name, user=not self.user, replace=True)
def install_my_kernel_spec(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) path_of_file = dirname( abspath(__file__)) + "/jupyter_kernel_polymake/resources/" filenames = [ "three.js", "Detector.js", "controls/TrackballControls.js", "renderers/SVGRenderer.js", "renderers/CanvasRenderer.js", "renderers/Projector.js", "menu.svg", "close.svg" ] for i in filenames: file_copy(path_of_file + i, td) file_copy(path_of_file + "kernel.js", td) file_copy(path_of_file + "logo-32x32.png", td) file_copy(path_of_file + "logo-64x64.png", td) print('Installing jupyter kernel spec for polymake') install_kernel_spec(td, 'polymake', user=user, replace=True)
def run(self): install.run(self) user = '******' in sys.argv try: from jupyter_client.kernelspec import install_kernel_spec except ImportError: from IPython.kernel.kernelspec import install_kernel_spec from IPython.utils.tempdir import TemporaryDirectory 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) log.info('Installing kernel spec') kernel_name = kernel_json['name'] try: install_kernel_spec(td, kernel_name, user=user, replace=True) except: install_kernel_spec(td, kernel_name, user=not user, replace=True)
def run(self): install.run(self) user = '******' in sys.argv try: from jupyter_client.kernelspec import install_kernel_spec except ImportError: from IPython.kernel.kernelspec import install_kernel_spec from IPython.utils.tempdir import TemporaryDirectory 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) log.info('Installing kernel spec') kernel_name = kernel_json['name'] try: install_kernel_spec(td, kernel_name, user=user, replace=True) except: install_kernel_spec(td, kernel_name, user=not user, replace=True)
def install_my_kernel_spec(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) path_of_file = dirname( abspath(__file__) ) + "/resources/" filenames=[ "Detector.js", "three.js", "kernel.js" ] filenames_renderer=[ "CanvasRenderer.js", "Projector.js" ] filenames_control=[ "TrackballControls.js" ] for i in filenames: file_copy(path_of_file + i, td ) os.mkdir( td + "renderers", mode=755 ) for i in filenames_renderer: file_copy(path_of_file + "renderers/" + i, td + "renderers" ) os.mkdir( td + "controls", mode=755 ) for i in filenames_control: file_copy(path_of_file + "controls/" + i, td + "controls" ) file_copy(path_of_file + "logo-32x32.png", td ) file_copy(path_of_file + "logo-64x64.png", td ) print('Installing IPython kernel spec') install_kernel_spec(td, 'polymake', user=user, replace=True)
def install(kernel_name="fuckbrain", user=False, replace=False): """ options: -k=<str>, --kernel-name=<str> -u, --user -r, --replace """ path = Path(tempfile.mkdtemp(suffix="_kernels")) / kernel_name path.mkdir() with (path / "kernel.json").open("w") as f: json.dump(kernel_spec, f) return install_kernel_spec(str(path), kernel_name, user, replace)
def install_kernel(c): # Write kernel spec in a temporary directory user = False opt = c.command_options if 'install' in opt: if 'user' in opt['install']: user = True c.announce("Installing jupyter kernel spec") with TemporaryDirectory() as td: with open(os.path.join(td, 'kernel.json'), 'w') as f: json.dump(kernel_json, f, sort_keys=True) install_kernel_spec(td, kernel_name='gap-wrapper', user=user) c.announce("Installing nbextension for syntax hilighting") install_nbextension('jupyter_kernel_gap/resources/gap-mode', overwrite=True, user=user) enable_nbextension( 'notebook', 'gap-mode/main', )
def install_kernelspec(lib_dir, kernel_dir=None, user=True): if kernel_dir is None: kernel_dir = os.path.join(lib_dir, "kernel", "lambda-notebook") if lib_dir: # TODO: won't override an installed copy of lamb in site-packages (e.g. in the app), fix this # the following line is to deal with a messy escaping situation for windows paths # this may fail horribly on unix paths with backslashes, but I don't have a better workaround for now lib_dir = lib_dir.replace("\\", "\\\\\\\\") injection_path_opt = "--IPKernelApp.exec_lines=[\"import sys\",\"sys.path.append(\\\"%s\\\")\", \"import lamb.lnsetup\", \"lamb.lnsetup.ipython_setup()\"]" % lib_dir else: injection_path_opt = "--IPKernelApp.exec_lines=[\"import lamb.lnsetup\", \"lamb.lnsetup.ipython_setup()\"]" k_json = build_json() k_json["argv"].append(injection_path_opt) k_json_filename = os.path.join(kernel_dir, "kernel.json") #print(k_json) with open(k_json_filename, 'w') as k_json_file: json.dump(k_json, k_json_file, sort_keys=True, indent=4) kernelspec.install_kernel_spec(kernel_dir, user=user, replace=True) location = kernelspec.find_kernel_specs()['lambda-notebook'] return location
def _install_spec(self): """ Install the Sage IPython kernel It is safe to call this method multiple times, only one Sage kernel spec is ever installed for any given Sage version. However, it resets the IPython kernel spec directory so additional resources symlinked there are lost. See :meth:`symlink_resources`. EXAMPLES:: sage: from sage.repl.ipython_kernel.install import SageKernelSpec sage: spec = SageKernelSpec() sage: spec._install_spec() # not tested """ import json temp = tmp_dir() kernel_spec = os.path.join(temp, 'kernel.json') with open(kernel_spec, 'w') as f: json.dump(self.kernel_spec(), f) identifier = self.identifier() install_kernel_spec(temp, identifier, user=True, replace=True) self._spec = get_kernel_spec(identifier)
def run(self): install.run(self) try: from jupyter_client.kernelspec import install_kernel_spec except ImportError: from IPython.kernel.kernelspec import install_kernel_spec from IPython.utils.tempdir import TemporaryDirectory # Install unix port with TemporaryDirectory() as td: os.chmod(td, 0o755) with open(os.path.join(td, 'kernel.json'), 'w') as f: json.dump(kernel_json_unix, f, sort_keys=True) kernel_name = 'mp' + pkg_unix try: install_kernel_spec(td, kernel_name=kernel_name, user=self.user, replace=True) except: install_kernel_spec(td, kernel_name=kernel_name, user=not self.user, replace=True) # Install pyboard port with TemporaryDirectory() as td: os.chmod(td, 0o755) with open(os.path.join(td, 'kernel.json'), 'w') as f: json.dump(kernel_json_pyboard, f, sort_keys=True) kernel_name = 'mp' + pkg_stmhal try: install_kernel_spec(td, kernel_name=kernel_name, user=self.user, replace=True) except: install_kernel_spec(td, kernel_name=kernel_name, user=not self.user, replace=True)
def _is_root(): try: return os.geteuid() == 0 except AttributeError: return False # assume not an admin on non-Unix platforms if 'develop' in sys.argv or 'install' in sys.argv: user = '******' in sys.argv or not _is_root() 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) kernel_name = kernel_json['name'] try: install_kernel_spec(td, kernel_name, user=user, replace=True) except: install_kernel_spec(td, kernel_name, user=not user, replace=True) setup(name='matlab_kernel', version=version, description='A Matlab kernel for Jupyter/IPython', long_description=open('README.rst', 'r').read(), url="https://github.com/calysto/matlab_kernel", author='Steven Silvester', author_email='*****@*****.**', py_modules=['matlab_kernel'], license="MIT", install_requires=["metakernel >= 0.10.5", "pymatbridge", "IPython >= 3.0"],
def run_kernel_install(develop): #jupyter_client.kernelspec.install_kernel_spec(source_dir, kernel_name='VPython', user=user) install_kernel_spec(source_dir, kernel_name='VPython', user=user)
def install(user=True): """ Install IPython kernel specification """ name = 'splash-py2' if six.PY2 else 'splash-py3' folder = os.path.join(os.path.dirname(__file__), 'kernels', name) install_kernel_spec(folder, kernel_name="splash", user=user, replace=True)
def run(self): install.run(self) from jupyter_client.kernelspec import install_kernel_spec install_kernel_spec('kernelspec', 'forth', replace=True)
def install(user=True): """ Install IPython kernel specification """ folder = os.path.join(os.path.dirname(__file__), 'kernels', 'splash') install_kernel_spec(folder, kernel_name="splash", user=user, replace=True)
def add_kernel( host, display_name, local_python_path, remote_python_path, env=None, sudo=False, system=False, timeout=5, module="ssh_ipykernel", opt_args=None, ): """Add a new kernel specification for an SSH Kernel Arguments: host {str} -- host where the remote ipykernel should be started display_name {str} -- Display name for the new kernel local_python_path {[type]} -- Local python path to be used (without bin/python) remote_python_path {[type]} -- Remote python path to be used (without bin/python) Keyword Arguments: env {str} -- Environment variables passd to the ipykernel "VAR1=VAL1 VAR2=VAL2" (default: {""}) sudo {bool} -- Start ipykernel as root if necessary (default: {False}) system {bool} -- Create kernelspec as user (False) or system (True) (default: {False}) timeout {int} -- SSH connection timeout (default: {5}) Returns: [type] -- [description] """ def simplify(name): return re.sub(r"[^a-zA-Z0-9\-\.\_]", "", name) if system: username = False else: username = getpass.getuser() if opt_args is None: opt_args = [] kernel_json = { "argv": [ local_python_path, "-m", module, "--host", host, "--python", remote_python_path, "--timeout", str(timeout), ] + opt_args + ["-f", "{connection_file}",], "display_name": display_name, "language": "python", } if env is not None: kernel_json["argv"].insert(-2, "--env") kernel_json["argv"].insert(-2, env) if sudo: kernel_json["argv"].insert(-2, "-s") kernel_name = "{prefix}_{display_name}".format( prefix=PREFIX, host=host, display_name=simplify(display_name) ) with tempfile.TemporaryDirectory() as temp_dir: os.chmod(temp_dir, 0o755) with open(os.path.join(temp_dir, "kernel.json"), "w") as fd: json.dump(kernel_json, fd, sort_keys=True, indent=2) ks.install_kernel_spec(temp_dir, kernel_name, user=username, replace=True) return kernel_name
"argv": [ "python", os.path.join(os.getcwd(), "kernel.py"), "-f", "{connection_file}" ], "display_name": "Idris", "language": "idris", "name": "i2dris", "code_mirror_mode": "haskell" } try: from jupyter_client.kernelspec import install_kernel_spec except ImportError: from IPython.kernel.kernelspec import install_kernel_spec from IPython.utils.tempdir import TemporaryDirectory with TemporaryDirectory() as temp_directory: os.chmod(temp_directory, 0o755) # Starts off as 700, not user readable with open(os.path.join(temp_directory, 'kernel.json'), 'w') as f: json.dump(kernel_json, f, sort_keys=True) kernel_name = kernel_json['name'] install_kernel_spec(temp_directory, kernel_name, user=True, replace=True)
def install(user=True): """ Install IPython kernel specification """ name = 'splash-py2' if six.PY2 else 'splash-py3' folder = os.path.join(os.path.dirname(__file__), 'kernels', name) install_kernel_spec(folder, kernel_name="splash", user=user, replace=True)