Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def start(self):
""" Start the IPython Notebook server app, after initialization
This method takes no arguments so all configuration and initialization
must be done prior to calling this method."""
super(NotebookApp, self).start()
info = self.log.info
for line in self.notebook_info().split("\n"):
info(line)
info("Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).")
self.write_server_info_file()
if self.open_browser or self.file_to_run:
try:
browser = webbrowser.get(self.browser or None)
except webbrowser.Error as e:
self.log.warn('No web browser found: %s.' % e)
browser = None
if self.file_to_run:
>>> info = json.loads(app.kv.wait('jupyter.notebook.info'))
Use the connection info as you see fit for your application. Information
provided includes:
- protocol (http or https)
- host
- port
- base_url
- token
"""
name = 'python -m skein.recipes.jupyter_notebook'
aliases = Dict(skein_notebook_aliases)
ip = copy(NotebookApp.ip)
ip.default_value = '0.0.0.0'
open_browser = copy(NotebookApp.open_browser)
open_browser.default_value = False
notebook_info_key = Unicode("jupyter.notebook.info",
config=True,
help=("Skein key in which to store the "
"server information"))
def write_server_info_file(self):
super(SkeinNotebookApp, self).write_server_info_file()
data = {'protocol': 'https' if self.certfile else 'http',
'host': socket.gethostname(),
'port': self.port,
from tornado import ioloop
from traitlets import default
from notebook.notebookapp import NotebookApp
class FormgradeNotebookApp(NotebookApp):
"""A Subclass of the regular NotebookApp that can be spawned by the form grader."""
open_browser = False
token = '' # Notebook >=4.3
@default("profile")
def _profile_default(self):
return 'nbgrader'
def _confirm_exit(self):
# disable the exit confirmation for background notebook processes
ioloop.IOLoop.instance().stop()
def main():
return FormgradeNotebookApp.launch_instance()
def get(self):
"""Get the main page for the application's interface."""
available = self.settings['terminals_available']
return self.write(self.render_template('index.html',
static=self.static_url,
base_url=self.base_url,
token=self.settings['token'],
terminals_available=available))
def get_template(self, name):
loader = FileSystemLoader(HERE)
return loader.load(self.settings['jinja2_env'], name)
class ExampleApp(NotebookApp):
default_url = Unicode('/example')
def init_webapp(self):
"""initialize tornado webapp and httpserver.
"""
super(ExampleApp, self).init_webapp()
default_handlers = [
(r'/example/?', ExampleHandler),
(r"/example/(.*)", FileFindHandler,
{'path': os.path.join(HERE, 'build')})
]
self.web_app.add_handlers('.*$', default_handlers)
if __name__ == '__main__':
class ExampleHandler(IPythonHandler):
"""Handle requests between the main app page and notebook server."""
def get(self):
"""Get the main page for the application's interface."""
return self.write(self.render_template('index.html',
static=self.static_url,
base_url=self.base_url,
token=self.settings['token']))
def get_template(self, name):
loader = FileSystemLoader(HERE)
return loader.load(self.settings['jinja2_env'], name)
class ExampleApp(NotebookApp):
default_url = Unicode('/example')
def init_webapp(self):
"""initialize tornado webapp and httpserver.
"""
super(ExampleApp, self).init_webapp()
default_handlers = [
(r'/example/?', ExampleHandler),
(r"/example/(.*)", FileFindHandler,
{'path': os.path.join(HERE, 'build')}) ]
self.web_app.add_handlers('.*$', default_handlers)
if __name__ == '__main__':
ExampleApp.launch_instance()
pw = IPython.lib.passwd()
print("If you would like to use this password in the future,")
print("place a line like this inside the [yt] section in your")
print("yt configuration file at ~/.config/yt/ytrc")
print()
print("notebook_password = %s" % pw)
print()
elif args.no_password:
pw = None
if args.port != 0:
kwargs['port'] = int(args.port)
if args.profile is not None:
kwargs['profile'] = args.profile
if pw is not None:
kwargs['password'] = pw
app = NotebookApp(open_browser=args.open_browser,
**kwargs)
app.initialize(argv=[])
print()
print("***************************************************************")
print()
print("The notebook is now live at:")
print()
print(" http://127.0.0.1:%s/" % app.port)
print()
print("Recall you can create a new SSH tunnel dynamically by pressing")
print("~C and then typing -L%s:localhost:%s" % (app.port, app.port))
print("where the first number is the port on your local machine. ")
print()
print("If you are using %s on your machine already, try " \
"-L8889:localhost:%s" % (app.port, app.port))
print()
lab_flags = dict(flags)
lab_flags['core-mode'] = (
{'LabApp': {'core_mode': True}},
"Start the app in core mode."
)
lab_flags['dev-mode'] = (
{'LabApp': {'dev_mode': True}},
"Start the app in dev mode for running from source."
)
lab_flags['watch'] = (
{'LabApp': {'watch': True}},
"Start the app in watch mode."
)
class LabApp(NotebookApp):
version = version
description = """
JupyterLab - An extensible computational environment for Jupyter.
This launches a Tornado based HTML Server that serves up an
HTML5/Javascript JupyterLab client.
JupyterLab has three different modes of running:
* Core mode (`--core-mode`): in this mode JupyterLab will run using the JavaScript
assets contained in the installed `jupyterlab` Python package. In core mode, no
extensions are enabled. This is the default in a stable JupyterLab release if you
have no extensions installed.
* Dev mode (`--dev-mode`): uses the unpublished local JavaScript packages in the
`dev_mode` folder. In this case JupyterLab will show a red stripe at the top of
class ExampleHander(IPythonHandler):
"""Handle requests between the main app page and notebook server."""
def get(self):
"""Get the main page for the application's interface."""
return self.write(self.render_template("index.html",
static=self.static_url, base_url=self.base_url,
token=self.settings['token']))
def get_template(self, name):
return LOADER.load(self.settings['jinja2_env'], name)
class ExampleApp(NotebookApp):
"""A notebook app that runs the example."""
default_url = Unicode('/example')
def start(self):
default_handlers = [
(ujoin(self.base_url, r'/example/?'), ExampleHander),
(ujoin(self.base_url, r"/example/(.*)"), FileFindHandler,
{'path': os.path.join(HERE, 'build')}),
]
self.web_app.add_handlers(".*$", default_handlers)
super(ExampleApp, self).start()
if __name__ == '__main__':
ExampleApp.launch_instance()
class ExampleHander(IPythonHandler):
"""Handle requests between the main app page and notebook server."""
def get(self):
"""Get the main page for the application's interface."""
return self.write(self.render_template('index.html',
static=self.static_url,
base_url=self.base_url,
token=self.settings['token']))
def get_template(self, name):
return LOADER.load(self.settings['jinja2_env'], name)
class ExampleApp(NotebookApp):
"""A notebook app that runs the example."""
default_url = Unicode('/example')
def start(self):
default_handlers = [
(ujoin(self.base_url, r'/example/?'), ExampleHander),
(ujoin(self.base_url, r'/example/(.*)'), FileFindHandler, {'path': HERE}),
]
self.web_app.add_handlers('.*$', default_handlers)
super(ExampleApp, self).start()
if __name__ == '__main__':
ExampleApp.launch_instance()
# Simple check whether that process is really still running
# Also remove leftover files from IPython 2.x without a pid field
if ('pid' in info) and check_pid(info['pid']):
yield info
else:
# If the process has died, try to delete its info file
try:
os.unlink(os.path.join(runtime_dir, file_name))
except OSError:
pass # TODO: This should warn or log or something
#-----------------------------------------------------------------------------
# Main entry point
#-----------------------------------------------------------------------------
main = launch_new_instance = NotebookApp.launch_instance