Ejemplo n.º 1
0
def nbopen(filename):
    filename = os.path.abspath(filename)
    home_dir = os.path.expanduser('~')
    server_inf = find_best_server(filename)
    if server_inf is not None:
        print("Using existing server at", server_inf['notebook_dir'])
        path = os.path.relpath(filename, start=server_inf['notebook_dir'])
        if os.sep != '/':
            path = path.replace(os.sep, '/')
        url = url_path_join(server_inf['url'], 'notebooks', url_escape(path))
        na = notebookapp.NotebookApp.instance()
        na.load_config_file()
        browser = webbrowser.get(na.browser or None)
        browser.open(url, new=2)
    else:
        if filename.startswith(home_dir):
            nbdir = home_dir
        else:
            nbdir = os.path.dirname(filename)

        print("Starting new server")
        # Hack: we want to override these settings if they're in the config file.
        # The application class allows 'command line' config to override config
        # loaded afterwards from the config file. So by specifying config, we
        # can use this mechanism.
        cfg = Config()
        cfg.NotebookApp.file_to_run = os.path.abspath(filename)
        cfg.NotebookApp.notebook_dir = nbdir
        cfg.NotebookApp.open_browser = True
        notebookapp.launch_new_instance(
            config=cfg,
            argv=[],  # Avoid it seeing our own argv
        )
Ejemplo n.º 2
0
def nbopen(filename):
    filename = os.path.abspath(filename)
    home_dir = os.path.expanduser('~')
    server_inf = find_best_server(filename)
    if server_inf is not None:
        print("Using existing server at", server_inf['notebook_dir'])
        path = os.path.relpath(filename, start=server_inf['notebook_dir'])
        if os.sep != '/':
            path = path.replace(os.sep, '/')
        url = url_path_join(server_inf['url'], 'notebooks', url_escape(path))
        na = notebookapp.NotebookApp.instance()
        na.load_config_file()
        browser = webbrowser.get(na.browser or None)
        browser.open(url, new=2)
    else:
        if filename.startswith(home_dir):
            nbdir = home_dir
        else:
            nbdir = os.path.dirname(filename)

        print("Starting new server")
        notebookapp.launch_new_instance(file_to_run=os.path.abspath(filename),
                                        notebook_dir=nbdir,
                                        open_browser=True,
                                        argv=[],  # Avoid it seeing our own argv
                                        )
Ejemplo n.º 3
0
    def _start_notebook(self, args, cwd, env):
        from notebook import notebookapp as app

        # Args must not have ['notebook'] in the begining. Drop the `notebook` subcommand when using `jupyter`
        args = args[1:] if args[0] == "notebook" else args
        self.log.info("Starting notebook with args %s", args)

        # When launching notebook always ensure the first argument is `notebook`.
        with change_exec_context(args, cwd, env):
            app.launch_new_instance()
Ejemplo n.º 4
0
def __main():
    import sys
    import pydrake
    sys.argv = ["notebook", f"{pydrake.getDrakePath()}/tutorials/index.ipynb"]
    try:
        from notebook import notebookapp as app
    except ImportError:
        print("ERROR: the Jupyter notebook runtime is not installed!")
        print()
        print(__doc__)
        sys.exit(1)
    app.launch_new_instance()
Ejemplo n.º 5
0
def nb_open(filename, profile='default', open_browser=True, fLOG=fLOG):
    """
    open a notebook with an existing server,
    if no server can be found, it starts a new one
    (and the function runs until the server is closed)

    @param      filename        notebook
    @param      profile         profile to use
    @param      open_browser    open browser or not
    @param      fLOG            logging function
    @return                     a running server or None if not found
    """
    filename = os.path.abspath(filename)
    server_inf = find_best_server(filename, profile)
    if server_inf is not None:
        from notebook.utils import url_path_join
        fLOG("Using existing server at", server_inf['notebook_dir'])
        path = os.path.relpath(filename, start=server_inf['notebook_dir'])
        url = url_path_join(server_inf['url'], 'notebooks', path)
        webbrowser.open(url, new=2)
        return server_inf
    else:
        fLOG("Starting new server")
        home_dir = os.path.dirname(filename)
        from notebook import notebookapp
        server = notebookapp.launch_new_instance(file_to_run=os.path.abspath(filename),
                                                 notebook_dir=home_dir,
                                                 open_browser=open_browser,
                                                 # Avoid it seeing our own argv
                                                 argv=[],
                                                 )
        return server
Ejemplo n.º 6
0
def nb_open(filename, profile='default', fLOG=fLOG):
    """
    open a notebook with an existing server,
    if no server can be found, it starts a new one
    (and the function runs until the server is closed)

    @param      filename        notebook
    @param      profile         profile to use
    @param      fLOG            logging function
    @return                     a running server or None if not found
    """
    filename = os.path.abspath(filename)
    server_inf = find_best_server(filename, profile)
    if server_inf is not None:
        fLOG("Using existing server at", server_inf['notebook_dir'])
        path = os.path.relpath(filename, start=server_inf['notebook_dir'])
        url = url_path_join(server_inf['url'], 'notebooks', path)
        webbrowser.open(url, new=2)
        return server_inf
    else:
        fLOG("Starting new server")
        home_dir = os.path.dirname(filename)
        server = notebookapp.launch_new_instance(
            file_to_run=os.path.abspath(filename),
            notebook_dir=home_dir,
            open_browser=True,
            # Avoid it seeing our own argv
            argv=[],
        )
        return server
Ejemplo n.º 7
0
def notebook():
    """Start Jupyter notebook."""
    import sys
    from notebook import notebookapp

    sys.argv[:] = ['fake']

    os.environ['PYTHONPATH'] = ':'.join(sys.path)
    sys.exit(notebookapp.launch_new_instance())
Ejemplo n.º 8
0
def handle_make_jupyternb(arg_dict):
    """ Launch Jupyter notebook server """
    if check_directory_makefile(arg_dict) is False:
        exit()
    if check_view_result_directory("notebooks", arg_dict) is False:
        exit()

    ## getting the build folder
    build_folder = arg_dict['directory'] + '_build/jupyter/'

    ## Note: we can support launching of individual files in the future ##

    cfg = Config()
    # cfg.NotebookApp.file_to_run = os.path.abspath(filename)
    cfg.NotebookApp.notebook_dir = build_folder
    cfg.NotebookApp.open_browser = True
    notebookapp.launch_new_instance(config=cfg,
                                    argv=[],  # Avoid it seeing our own argv
                                    )
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
Ejemplo n.º 10
0
def nbopen(filename, profile='default'):
    filename = os.path.abspath(filename)
    home_dir = os.path.expanduser('~')
    server_inf = find_best_server(filename, profile)
    if server_inf is not None:
        print("Using existing server at", server_inf['notebook_dir'])
        path = os.path.relpath(filename, start=server_inf['notebook_dir'])
        url = url_path_join(server_inf['url'], 'notebooks', path)
        webbrowser.open(url, new=2)
    else:
        if filename.startswith(home_dir):
            nbdir = home_dir
        else:
            nbdir = os.path.dirname(filename)

        print("Starting new server")
        notebookapp.launch_new_instance(file_to_run=os.path.abspath(filename),
                                        notebook_dir=nbdir,
                                        open_browser=True,
                                        argv=[],  # Avoid it seeing our own argv
                                       )
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 == "kernel":
            mode = "kernel"
            pass
        else:
            cmd_args.append(arg)

    if mode == "kernel":  # run iPython kernel with passed ops
        args = ["kernel"]
        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)
    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([
            "--notebook-dir=" + getcwd(),
            # If this is being run as a subcommand, be sure to insert it here, below example is for subcommand notebook
            # and also using argparse, note the -- to terminate argument parsing
            # "--KernelManager.kernel_cmd=['"+me+"', 'notebook', 'kernel', '--', '-f', '{connection_file}']"])
            "--KernelManager.kernel_cmd=['" + me +
            "', 'kernel', '-f', '{connection_file}']"
        ])
        args.extend(all_args)
        logger.info("notebook argv: %s", str(args))
        from notebook import notebookapp
        notebookapp.launch_new_instance(argv=args)
    return True
Ejemplo n.º 12
0
def run_jupyter(jupyter_commands):
    app.launch_new_instance(jupyter_commands)
Ejemplo n.º 13
0
def run_jupyter(jupyter_commands):
    app.launch_new_instance(jupyter_commands)
Ejemplo n.º 14
0
class HelloWidget(widgets.DOMWidget):
    _view_name = Unicode('HelloView').tag(sync=True)
    _view_module = Unicode('hello').tag(sync=True)
    _view_module_version = Unicode('0.1.0').tag(sync=True)
    value = Unicode('Hello World!').tag(sync=True)


class AugSlider(widgets.IntSlider):
    def __init__(self):
        super(self.__class__, self)


class Test(BeakerxText):
    def __init__(self):
        super(self.__class__, self)


import ipykernel.kernelapp as app


class Defs(app.IPKernelApp):
    pass


if __name__ == "__main__":
    from notebook import notebookapp
    notebookapp.launch_new_instance()
    # print(AugSlider.__class__)
    # print(type(Test))
    #
    # Defs.launch_instance()
Ejemplo n.º 15
0
"""
Shim to maintain backwards compatibility with old IPython.html imports.
"""
# Copyright (c) IPython Development Team.
# Distributed under the terms of the Modified BSD License.

import sys
from warnings import warn

warn("The `IPython.html` package has been deprecated. "
     "You should import from `notebook` instead. "
     "`IPython.html.widgets` has moved to `ipywidgets`.")

from IPython.utils.shimmodule import ShimModule

_widgets = sys.modules['IPython.html.widgets'] = ShimModule(
    src='IPython.html.widgets', mirror='ipywidgets')

_html = ShimModule(src='IPython.html', mirror='notebook')

# hook up widgets
_html.widgets = _widgets
sys.modules['IPython.html'] = _html

if __name__ == '__main__':
    from notebook import notebookapp as app
    app.launch_new_instance()
Ejemplo n.º 16
0
    def _start_notebook(self, args):
        from notebook import notebookapp as app

        sys.argv = [""] + args
        app.launch_new_instance()
Ejemplo n.º 17
0
"""
Shim to maintain backwards compatibility with old IPython.html imports.
"""
# Copyright (c) IPython Development Team.
# Distributed under the terms of the Modified BSD License.

import sys
from warnings import warn

from IPython.utils.shimmodule import ShimModule, ShimWarning

warn("The `IPython.html` package has been deprecated. "
     "You should import from `notebook` instead. "
     "`IPython.html.widgets` has moved to `ipywidgets`.", ShimWarning)

_widgets = sys.modules['IPython.html.widgets'] = ShimModule(
    src='IPython.html.widgets', mirror='ipywidgets')

_html = ShimModule(
    src='IPython.html', mirror='notebook')

# hook up widgets
_html.widgets = _widgets
sys.modules['IPython.html'] = _html

if __name__ == '__main__':
    from notebook import notebookapp as app
    app.launch_new_instance()