def run_notebook(): app = NotebookApp.instance() # Treat IPYTHON_ARGUMENTS from settings ipython_arguments = self.get_ipython_arguments(options) if "django_extensions.management.notebook_extension" not in ipython_arguments: ipython_arguments.extend(["--ext", "django_extensions.management.notebook_extension"]) # Treat NOTEBOOK_ARGUMENTS from settings notebook_arguments = self.get_notebook_arguments(options) if no_browser and "--no-browser" not in notebook_arguments: notebook_arguments.append("--no-browser") if "--notebook-dir" not in notebook_arguments: notebook_arguments.extend(["--notebook-dir", "."]) # IPython < 3 passes through kernel args from notebook CLI if release.version_info[0] < 3: notebook_arguments.extend(ipython_arguments) app.initialize(notebook_arguments) # IPython >= 3 uses kernelspecs to specify kernel CLI args if release.version_info[0] >= 3: display_name = getattr(settings, "IPYTHON_KERNEL_DISPLAY_NAME", "Django Shell-Plus") install_kernel_spec(app, display_name, ipython_arguments) app.start()
def get_nbextensions_path(): """ Return the nbextensions search path gets the search path for - the current NotebookApp instance or, if we can't instantiate one - the default config used, found by spawning a subprocess """ # Attempt to get the path for the currently-running config, or the default # if one isn't running. # If there's already a non-NotebookApp traitlets app running, e.g. when # we're inside an IPython kernel there's a KernelApp instantiated, then # attempting to get a NotebookApp instance will raise a # MultipleInstanceError. try: return NotebookApp.instance().nbextensions_path except MultipleInstanceError: # So, we spawn a new python process to get paths for the default config cmd = "from {0} import {1}; [print(p) for p in {1}()]".format( get_nbextensions_path.__module__, get_nbextensions_path.__name__) return subprocess.check_output([ sys.executable, '-c', cmd ]).decode(sys.stdout.encoding).split('\n')
def run_notebook(): app = NotebookApp.instance() # Treat IPYTHON_ARGUMENTS from settings ipython_arguments = getattr(settings, 'IPYTHON_ARGUMENTS', []) if 'django_extensions.management.notebook_extension' not in ipython_arguments: ipython_arguments.extend(['--ext', 'django_extensions.management.notebook_extension']) # Treat NOTEBOOK_ARGUMENTS from settings notebook_arguments = getattr(settings, 'NOTEBOOK_ARGUMENTS', []) if no_browser and '--no-browser' not in notebook_arguments: notebook_arguments.append('--no-browser') if '--notebook-dir' not in notebook_arguments: notebook_arguments.extend(['--notebook-dir', '.']) # IPython < 3 passes through kernel args from notebook CLI if release.version_info[0] < 3: notebook_arguments.extend(ipython_arguments) app.initialize(notebook_arguments) # IPython >= 3 uses kernelspecs to specify kernel CLI args if release.version_info[0] >= 3: display_name = getattr(settings, 'IPYTHON_KERNEL_DISPLAY_NAME', "Django Shell-Plus") install_kernel_spec(app, display_name, ipython_arguments) app.start()
def run_notebook(): app = NotebookApp.instance() # Treat IPYTHON_ARGUMENTS from settings ipython_arguments = self.get_ipython_arguments(options) if 'django_extensions.management.notebook_extension' not in ipython_arguments: ipython_arguments.extend([ '--ext', 'django_extensions.management.notebook_extension' ]) # Treat NOTEBOOK_ARGUMENTS from settings notebook_arguments = self.get_notebook_arguments(options) if no_browser and '--no-browser' not in notebook_arguments: notebook_arguments.append('--no-browser') if '--notebook-dir' not in notebook_arguments: notebook_arguments.extend(['--notebook-dir', '.']) # IPython < 3 passes through kernel args from notebook CLI if release.version_info[0] < 3: notebook_arguments.extend(ipython_arguments) app.initialize(notebook_arguments) # IPython >= 3 uses kernelspecs to specify kernel CLI args if release.version_info[0] >= 3: display_name = getattr(settings, 'IPYTHON_KERNEL_DISPLAY_NAME', "Django Shell-Plus") install_kernel_spec(app, display_name, ipython_arguments) app.start()
def main(): """Run main.""" opt = parse_cmd_line() if opt.serve: # pylint: disable=import-outside-toplevel from imjoy.server import start_server start_server(opt) elif opt.jupyter: sys.argv = sys.argv[:1] sys.argc = 1 # pylint: disable=import-outside-toplevel from notebook.notebookapp import NotebookApp kwargs = { "open_browser": False, "allow_origin": opt.allow_origin, "ip": opt.host, "notebook_dir": opt.workspace, "port": int(opt.port), "tornado_settings": { "headers": { "Access-Control-Allow-Origin": opt.allow_origin, "Content-Security-Policy": opt.content_security_policy, } }, } if not opt.token: if not opt.random_token: opt.token = read_or_generate_token() kwargs["token"] = opt.token else: kwargs["token"] = opt.token if opt.insecure: kwargs["token"] = "" kwargs["disable_check_xsrf"] = True logger.warning( "Running Jupyter notebooks with --insecure flag, " "please do not use it for production." ) app = NotebookApp.instance(**kwargs) app.initialize() if app.port != int(opt.port): print(f"\nWARNING: using a different port: {app.port}.\n") write_token(app.token) app._token_generated = True # pylint: disable=protected-access app.start() else: print( "\nNote: We have migrated the backend of the ImJoy Engine." "You can start the Jupyter backend via`imjoy --jupyter`.\n\n" "Or, you can start the socketio backend server via `imjoy --serve`\n" )
def run_notebook(): app = NotebookApp.instance() # Treat IPYTHON_ARGUMENTS from settings ipython_arguments = self.get_ipython_arguments(options) if 'django_extensions.management.notebook_extension' not in ipython_arguments: ipython_arguments.extend([ '--ext', 'django_extensions.management.notebook_extension' ]) # Treat NOTEBOOK_ARGUMENTS from settings notebook_arguments = self.get_notebook_arguments(options) if no_browser and '--no-browser' not in notebook_arguments: notebook_arguments.append('--no-browser') if '--notebook-dir' not in notebook_arguments and not any( e.startswith('--notebook-dir=') for e in notebook_arguments): notebook_arguments.extend(['--notebook-dir', '.']) # IPython < 3 passes through kernel args from notebook CLI if release.version_info[0] < 3: notebook_arguments.extend(ipython_arguments) app.initialize(notebook_arguments) # IPython >= 3 uses kernelspecs to specify kernel CLI args if release.version_info[0] >= 3: ksm = app.kernel_spec_manager for kid, ks in self.generate_kernel_specs( app, ipython_arguments).items(): roots = [ os.path.dirname(ks.resource_dir), ksm.user_kernel_dir ] success = False for root in roots: kernel_dir = os.path.join(root, kid) try: if not os.path.exists(kernel_dir): os.makedirs(kernel_dir) with open(os.path.join(kernel_dir, 'kernel.json'), 'w') as f: f.write(ks.to_json()) success = True break except OSError: continue if not success: raise CommandError( "Could not write kernel %r in directories %r" % (kid, roots)) app.start()
def project(self): # 1. configuration option passed explicitly # 2. from notebooks dir # 3. from cwd if self.ballet_yml_path: return Project.from_path(self.ballet_yml_path) path = NotebookApp.instance().notebook_dir with fy.suppress(Exception): return Project.from_path(path) with fy.suppress(Exception): return Project.from_cwd() raise ConfigurationError('Could not detect Ballet project')
def _get_r_executable(): try: # get notebook app from notebook.notebookapp import NotebookApp nbapp = NotebookApp.instance() # get R executable: kernel_name = nbapp.kernel_manager.default_kernel_name if kernel_name: kernel_spec = nbapp.kernel_spec_manager.get_kernel_spec( kernel_name) # nb_conda_kernels has conda env prefix at idx 4 return '{}/bin/R'.format(kernel_spec.argv[4]) except Exception: nbapp.log.warning( 'Error when trying to get R executable from kernel') return 'R'
def start_notebook(args, l, rc): from notebook.notebookapp import NotebookApp import sys sys.argv = ['ambry'] app = NotebookApp.instance() app._library = l app.contents_manager_class = 'ambry_ui.jupyter.AmbryContentsManager' app.open_browser = not args.no_browser app.ip = args.host if args.port is not None: app.port = int(args.port) app.initialize(None) app.start()
def run_notebook(no_browser=False, display_name='notebook'): app = NotebookApp.instance() ipython_arguments = [] # Will implement to set specific IPython configs notebook_arguments = [] # Will implement to set specific notebook configs if no_browser is True: notebook_arguments.append('--no-browser') if '--notebook-dir' not in notebook_arguments: notebook_arguments.extend(['--notebook-dir', '.']) install_kernel_spec(app, display_name, ipython_arguments) app.initialize(notebook_arguments) app.start()
def run_notebook(no_browser=False, display_name='notebook'): app = NotebookApp.instance() ipython_arguments = [ ] # Will implement to set specific IPython configs notebook_arguments = [ ] # Will implement to set specific notebook configs if no_browser is True: notebook_arguments.append('--no-browser') if '--notebook-dir' not in notebook_arguments: notebook_arguments.extend(['--notebook-dir', '.']) install_kernel_spec(app, display_name, ipython_arguments) app.initialize(notebook_arguments) app.start()
def test_basic(self): from notebook.notebookapp import NotebookApp import sys l = self.library() b = l.new_bundle(source='example.com', dataset='test', assignment_class='self') l.commit() sys.argv = ['ambry'] app = NotebookApp.instance() app._library = l app.contents_manager_class = 'ambry_ui.jupyter.AmbryContentsManager' app.initialize(None) cm = app.contents_manager self.assertEqual('example.com', cm.get('')['content'][0]['path']) self.assertEqual('/example.com/test-0.0.1/bundle.yaml', cm.get(b.identity.cache_key)['content'][0]['path'])
def handle(self, arguments): try: from notebook.notebookapp import NotebookApp except ImportError: # pragma: no cover self.parser.error("notebook not found. Please install it") else: extension = "corral.libs.notebook_extension" pipeline = setup.load_pipeline_setup() app = NotebookApp.instance() dir_name = conf.PACKAGE display_name = pipeline.name settings_module = conf.CORRAL_SETTINGS_MODULE ipython_arguments = ['--ext', extension] app.initialize(arguments) self.install_kernel_spec(app, dir_name, display_name, settings_module, ipython_arguments) app.start()
def handle(self, arguments): try: from notebook.notebookapp import NotebookApp except ImportError: self.parser.error("notebook not found. Please install it") else: extension = "corral.libs.notebook_extension" pipeline = setup.load_pipeline_setup() app = NotebookApp.instance() dir_name = conf.PACKAGE display_name = pipeline.name settings_module = conf.CORRAL_SETTINGS_MODULE ipython_arguments = ['--ext', extension] app.initialize(arguments) self.install_kernel_spec( app, dir_name, display_name, settings_module, ipython_arguments) app.start()
def get_nbextensions_path(): """ Return the nbextensions search path gets the search path for - the current NotebookApp instance or, if we can't instantiate one - the default config used, found by spawning a subprocess """ # Attempt to get the path for the currently-running config, or the default # if one isn't running. # If there's already a non-NotebookApp traitlets app running, e.g. when # we're inside an IPython kernel there's a KernelApp instantiated, then # attempting to get a NotebookApp instance will raise a # MultipleInstanceError. try: return NotebookApp.instance().nbextensions_path except MultipleInstanceError: # So, we spawn a new python process to get paths for the default config cmd = "from {0} import {1}; [print(p) for p in {1}()]".format( get_nbextensions_path.__module__, get_nbextensions_path.__name__) return subprocess.check_output([sys.executable, '-c', cmd]).decode( sys.stdout.encoding).split('\n')
def app_init(*args, **kwargs): app = NotebookApp.instance() app.initialize(*args, **kwargs) return app
def run_notebook(): app = NotebookApp.instance() self.run_notebookapp(app, options, use_kernel_specs)
""" Run this to debug """ import sys import os from notebook.notebookapp import NotebookApp from jupyter_geppetto import settings os.environ['JUPYTER_CONFIG_DIR'] = os.path.join( os.path.dirname(os.path.abspath(__file__)), '.jupyter-config') settings.debug = True if __name__ == '__main__': sys.argv.append('--NotebookApp.default_url=/geppetto') sys.argv.append("--NotebookApp.token=''") sys.argv.append('--library=netpyne_ui') sys.argv.append('--NotebookApp.disable_check_xsrf=True') app = NotebookApp.instance() app.initialize(sys.argv) app.file_to_run = '' sys.exit(app.start())
# Init the Jupyter app kwargs = {} argv = ['--no-browser'] jupyterlab = False if len(sys.argv) > 1: jupyterlab = sys.argv[1] == 'lab' if jupyterlab: from jupyterlab.labapp import LabApp app = LabApp.instance(**kwargs) else: from notebook.notebookapp import NotebookApp app = NotebookApp.instance(**kwargs) # import logging # app.log_level = logging.DEBUG app.initialize(argv) with stdoutlock: print(json.dumps({'sys.path': sys.path})) print(json.dumps({'sys.executable': sys.executable})) print(json.dumps({'os.environ': dict(os.environ)})) print(json.dumps({'server_info': app.server_info()})) sys.stdout.flush() inthread = threading.Thread(target=read_stdin, args=(
def main(): """Run main.""" opt = parse_cmd_line() background_task = None if opt.plugin_file and (opt.plugin_server or opt.serve): async def start_plugin(app): default_config.update({ "name": "ImJoy Plugin", "plugin_server": opt.plugin_server or "http://127.0.0.1:{}".format(opt.serve), }) load_plugin(opt.plugin_file) background_task = start_plugin if opt.serve: try: from imjoy.socketio_server import create_socketio_server except: logger.error( "It appears that your ImJoy installation is not complete, please reinstall it with 'pip install imjoy[socketio]'" ) raise SystemExit if opt.plugin_server and not opt.plugin_server.endswith(opt.serve): print( "WARNING: the specified port ({}) does not match the one in the url ({})" .format(opt.serve, opt.plugin_server)) app = create_socketio_server() if background_task: app.on_startup.append(background_task) web.run_app(app, port=opt.serve) elif opt.plugin_file: loop = asyncio.get_event_loop() loop.create_task(background_task(app)) loop.run_forever() elif opt.jupyter: sys.argv = sys.argv[:1] sys.argc = 1 from notebook.notebookapp import NotebookApp kwargs = { "open_browser": False, "allow_origin": opt.allow_origin, "ip": opt.host, "notebook_dir": opt.workspace, "port": int(opt.port), "tornado_settings": { "headers": { "Access-Control-Allow-Origin": opt.allow_origin, "Content-Security-Policy": opt.content_security_policy, } }, } if not opt.token: if not opt.random_token: opt.token = read_or_generate_token() kwargs["token"] = opt.token else: kwargs["token"] = opt.token app = NotebookApp.instance(**kwargs) app.initialize() if app.port != int(opt.port): print("\nWARNING: using a different port: {}.\n".format(app.port)) write_token(app.token) app._token_generated = True app.start() elif not opt.legacy: print( "\nNote: We are migrating the backend of the ImJoy Engine to Jupyter, to use it please run `imjoy --jupyter`.\n\nIf you want to use the previous engine, run `imjoy --legacy`, however, please note that it maybe removed soon.\n" )