def callback(brokers): models = Holder() for i, (path, broker) in enumerate(brokers): avail = _get_available_models(broker) if paths: if len(paths) > 1: models[paths[i]] = Models(broker, avail, __cwd, path, __coverage) else: models = Models(broker, avail, __cwd, path, __coverage) else: models = Models(broker, avail, __cwd, path, __coverage) if change_directory and len(brokers) == 1: __working_path, _ = brokers[0] os.chdir(__working_path) # disable jedi since it won't autocomplete for objects with__getattr__ # defined. IPython.core.completer.Completer.use_jedi = False __cfg = Config() __cfg.TerminalInteractiveShell.banner1 = Models.__doc__ __ns = {} __ns.update(globals()) __ns.update({"models": models}) if kernel: from ipykernel import kernelapp kernelapp.launch_new_instance([], user_ns=__ns, config=__cfg) else: IPython.start_ipython([], user_ns=__ns, config=__cfg)
def start_django(reloader, main_func, *args, **kwargs): ensure_echo_on() main_func = check_errors(main_func) django_main_thread = threading.Thread(target=main_func, args=args, kwargs=kwargs, name='django-main-thread') reloader_thread = ReloaderThread(reloader=reloader, django_main_thread=django_main_thread) try: from django_extensions.management.shells import import_objects except ImportError: kernel_user_ns = {} else: kernel_user_ns = import_objects({'quiet_load': True}, style=None) django_main_thread.setDaemon(True) reloader_thread.setDaemon(True) django_main_thread.start() reloader_thread.start() kernelapp.launch_new_instance(argv=[], user_ns=kernel_user_ns, quiet=False, use_experimental_completions=False)
def run_kernel(): from PySide2.QtWidgets import (QLineEdit, QPushButton, QApplication, QVBoxLayout, QDialog) import ipykernel from ipykernel import kernelapp as app from traitlets.config import Config c = Config() c.IPKernelApp.gui = "qt5" c.IPKernelApp.code_to_run = """ from IPython.core.magic import register_line_magic @register_line_magic def init_freecad(line): global _notebook_stdout, _notebook_stderr args = line.split() import sys from pathlib import Path p = sys.base_exec_prefix+"/" print(p) sys.path += [p+"Ext", p+"lib", p+"lib64", p+"libexec"] import FreeCAD as App from IPython.external.qt_loaders import ImportDenier if isinstance(sys.meta_path[0], ImportDenier): del(sys.meta_path[0]) ipython = get_ipython() if "gui" in args: import FreeCADGui as Gui #ipython.user_global_ns["Gui"]= Gui _notebook_stdout, _notebook_stderr = sys.stdout, sys.stderr Gui.showMainWindow() ipython.user_global_ns["App"]= App ipython.user_global_ns["Gui"]= Gui import asyncio async def restore_comms(): sys.stdout, sys.stderr = _notebook_stdout, _notebook_stderr asyncio.Task(restore_comms()) return "FreeCAD initialized. 'App' and 'Gui' added to global namespace." else: ipython.user_global_ns["App"]= App return "FreeCAD initialized. 'App' added to global namespace." """ app.launch_new_instance(config=c)
def jupyter_notebook(arglist): logger.info("epmt_notebook: %s", str(arglist)) mode = None cmd_args = [] all_args = arglist for index, arg in enumerate(all_args): if arg == "ipykernel_launcher": mode = "kernel" pass else: cmd_args.append(arg) if mode == "kernel": # run iPython kernel with passed ops args = ["ipykernel_launcher"] args.extend(cmd_args) # This does not want argv[0] logger.info("ipython kernel argv: %s", str(args)) # from IPython import start_ipython # start_ipython(argv=args) # Remove the CWD from sys.path while we load stuff. # This is added back by InteractiveShellApp.init_path() import sys if sys.path[0] == '': del sys.path[0] from ipykernel import kernelapp as app app.launch_new_instance() else: # Run IPython Notebook with passed ops import sys from os.path import realpath from os import getcwd me = realpath(sys.argv[0]) logger.debug("Using %s as binary", me) args = [] args.extend(all_args) logger.info("notebook argv: %s", str(args)) from notebook import notebookapp notebookapp.launch_new_instance(argv=args) return True
import os, sys, pathlib base = pathlib.Path(sys.executable) base = pathlib.Path(base).parent.parent fp = os.environ.get("FREECAD_PATH", None) if fp: base = pathlib.Path(fp) sys.path.append(str(base) + "/") sys.path.append(str(base / "lib") + "/") from ipykernel import kernelapp as app import ipykernel app.launch_new_instance() ipykernel.start_kernel()
# -*- coding: future_annotations -*- import sys # Remove the CWD from sys.path while we load stuff. # This is added back by InteractiveShellApp.init_path() # TODO: probably need to make this separate from nbsafety package so that we can # completely avoid imports until after removing cwd from sys.path if sys.path[0] == '': del sys.path[0] from ipykernel import kernelapp as app from nbsafety.kernel import SafeKernel app.launch_new_instance(kernel_class=SafeKernel)
import traitlets.config.manager import traitlets.utils.bunch import traitlets.utils.getargspec import traitlets.utils.importstring import traitlets.utils.sentinel from ipykernel import kernelapp import ipykernel.datapub import notebook for i, v in enumerate(notebook.DEFAULT_TEMPLATE_PATH_LIST): notebook.DEFAULT_TEMPLATE_PATH_LIST[i] = v.replace('library.zip\\', '') print(notebook.DEFAULT_TEMPLATE_PATH_LIST) notebook.DEFAULT_STATIC_FILES_PATH = notebook.DEFAULT_STATIC_FILES_PATH.replace('library.zip\\', '') print(notebook.DEFAULT_STATIC_FILES_PATH) if __name__ == '__main__': multiprocessing.freeze_support() if 'ipykernel_launcher' in sys.argv: # Remove the CWD from sys.path while we load stuff. # This is added back by InteractiveShellApp.init_path() if sys.path[0] == '': del sys.path[0] kernelapp.launch_new_instance() else: sys.exit(notebook.notebookapp .main(extra_static_paths=[notebook.DEFAULT_STATIC_FILES_PATH .replace('library.zip\\', '')]))
def _notebook_init(): from ipykernel import kernelapp print("Starting IPython kernel") kernelapp.launch_new_instance()
"""Entry point for launching an IPython kernel. This is separate from the ipykernel package so we can avoid doing imports until after removing the cwd from sys.path. """ import sys if __name__ == '__main__': # Remove the CWD from sys.path while we load stuff. # This is added back by InteractiveShellApp.init_path() if sys.path[0] == '': del sys.path[0] from ipykernel import kernelapp as app app.launch_new_instance()
def launch_kernel(): """ Launch a new Jupyter application instance, using this kernel. """ c = Config() c.TerminalInteractiveShell.highlighting_style = "vim" launch_new_instance(kernel_class=CypherKernel, config=c)
# # DROPLET_EXECUTE_FNAME, # # ) # # exc_count, outputs = droplet_execute(code, session_id).get() # # for index, (tag, output) in outputs: # # if tag == 'stdout': # # sys.stdout.write(output) # # elif tag == 'stderr': # # sys.stderr.write(output) # # else: # # assert False # reply_content = {} # reply_content[u'status'] = u'ok' # reply_content['execution_count'] = exc_count # reply_content[u'user_expressions'] = {} # XXX unused but also dummy # return reply_content import sys if __name__ == '__main__': # Remove the CWD from sys.path while we load stuff. # This is added back by InteractiveShellApp.init_path() if sys.path[0] == '': del sys.path[0] from ipykernel import kernelapp as app app.launch_new_instance(kernel_class=HydroKernel)