Beispiel #1
0
def start_server() -> None:
    data_path = Path(__file__).parent.absolute()
    config = configparser.ConfigParser()
    config.read(data_path / 'config.txt')
    config = config['default']

    if 'add_path' in config:
        for i, p in enumerate(config['add_path'].split(':')):
            sys.path.insert(i, p)

    if config['backend'] == 'voila':
        voila = Voila()

        mp.set_start_method('spawn')
        gui_p = mp.Process(target=start_gui,
                           args=(config['name'], voila.display_url))
        gui_p.start()

        voila_args = [str(data_path / config['notebook_path'])
                      ] + ([config['backend_args']] or [])
        voila_p = mp.Process(target=voila.launch_instance, args=(voila_args, ))
        voila_p.start()

        gui_p.join()
        voila_p.terminate()
        voila_p.join()
Beispiel #2
0
def main(filename, layout='default'):
    """
    Start a JDAViz application instance with data loaded from FILENAME.\f

    Parameters
    ----------
    filename : str
        The path to the file to be loaded into the JDAViz application.
    layout : str, optional
        Optional specification for which configuration to use on startup.
    """
    filename = os.path.abspath(filename)

    with open(os.path.join(CONFIGS_DIR, layout, layout + '.ipynb')) as f:
        notebook_template = f.read()

    start_dir = os.path.abspath('.')

    nbdir = tempfile.mkdtemp()

    with open(os.path.join(nbdir, 'notebook.ipynb'), 'w') as nbf:
        nbf.write(
            notebook_template.replace('CONFIG_NAME',
                                      layout).replace('DATA_FILENAME',
                                                      filename).strip())

    os.chdir(nbdir)

    try:
        Voila.notebook_path = 'notebook.ipynb'
        VoilaConfiguration.template = 'jdaviz-default'
        VoilaConfiguration.enable_nbextensions = True
        sys.exit(Voila().launch_instance(argv=[]))
    finally:
        os.chdir(start_dir)
Beispiel #3
0
def main(filename, layout='default', browser='default', theme='light', verbosity='info',
         hotreload=False):
    """
    Start a Jdaviz application instance with data loaded from FILENAME.

    Parameters
    ----------
    filename : str
        The path to the file to be loaded into the Jdaviz application.
    layout : str, optional
        Optional specification for which configuration to use on startup.
    browser : str, optional
        Path to browser executable.
    theme : {'light', 'dark'}
        Theme to use for Voila app or Jupyter Lab.
    verbosity : {'debug', 'info', 'warning', 'error'}
        Verbosity of the application.
    hotreload: bool
        Whether to enable hot-reloading of the UI (for development)
    """
    # Tornado Webserver py3.8 compatibility hotfix for windows
    if sys.platform == 'win32':
        import asyncio
        asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())

    # Support comma-separate file list
    filepath = ','.join([str(pathlib.Path(f).absolute()).replace('\\', '/')
                         for f in filename.split(',')])

    with open(os.path.join(CONFIGS_DIR, layout, layout + '.ipynb')) as f:
        notebook_template = f.read()

    start_dir = os.path.abspath('.')

    # Keep track of start directory in environment variable so that it can be
    # easily accessed e.g. in the file load dialog.
    os.environ['JDAVIZ_START_DIR'] = start_dir

    nbdir = tempfile.mkdtemp()

    if hotreload:
        notebook_template = notebook_template.replace("# PREFIX", "from jdaviz import enable_hot_reloading; enable_hot_reloading()")  # noqa: E501

    with open(os.path.join(nbdir, 'notebook.ipynb'), 'w') as nbf:
        nbf.write(notebook_template.replace('DATA_FILENAME', filepath).replace('JDAVIZ_VERBOSITY', verbosity).strip())  # noqa: E501

    os.chdir(nbdir)

    try:
        logging.getLogger('tornado.access').disabled = True
        Voila.notebook_path = 'notebook.ipynb'
        VoilaConfiguration.template = 'jdaviz-default'
        VoilaConfiguration.enable_nbextensions = True
        VoilaConfiguration.file_whitelist = ['.*']
        VoilaConfiguration.theme = theme
        if browser != 'default':
            Voila.browser = browser
        sys.exit(Voila().launch_instance(argv=[]))
    finally:
        os.chdir(start_dir)
Beispiel #4
0
def launch_voila(notebook_path, port=8866, base_url='/', server_url='/'):
    print('serving {path}'.format(path=notebook_path))
    from voila.app import Voila
    v = Voila()
    v.initialize([
        notebook_path, '--port', port, '--base_url', base_url, '--server_url',
        server_url, '--no-browser'
    ])
    v.base_url = base_url
    v.server_url = server_url
    v.tornado_settings = {
        'headers': {
            'Content-Security-Policy': "frame-ancestors 'self' localhost:*"
        }
    }
    v.start()
Beispiel #5
0
def main(filename, layout='default'):
    """
    Start a JDAViz application instance with data loaded from FILENAME.\f

    Parameters
    ----------
    filename : str
        The path to the file to be loaded into the JDAViz application.
    layout : str, optional
        Optional specification for which configuration to use on startup.
    """
    # Tornado Webserver py3.8 compatibility hotfix for windows
    if sys.platform == 'win32':
        import asyncio
        asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())

    filepath = pathlib.Path(filename).absolute()

    with open(os.path.join(CONFIGS_DIR, layout, layout + '.ipynb')) as f:
        notebook_template = f.read()

    start_dir = os.path.abspath('.')

    nbdir = tempfile.mkdtemp()

    with open(os.path.join(nbdir, 'notebook.ipynb'), 'w') as nbf:
        nbf.write(
            notebook_template.replace('DATA_FILENAME',
                                      str(filepath).replace('\\',
                                                            '/')).strip())

    os.chdir(nbdir)

    try:
        Voila.notebook_path = 'notebook.ipynb'
        VoilaConfiguration.template = 'jdaviz-default'
        VoilaConfiguration.enable_nbextensions = True
        sys.exit(Voila().launch_instance(argv=[]))
    finally:
        os.chdir(start_dir)
Beispiel #6
0
def main(filename, layout):

    filename = os.path.abspath(filename)

    with open(os.path.join(CONFIGS_DIR, layout, layout + '.ipynb')) as f:
        notebook_template = f.read()

    start_dir = os.path.abspath('.')

    nbdir = tempfile.mkdtemp()
    with open(os.path.join(nbdir, 'notebook.ipynb'), 'w') as nbf:
        nbf.write(
            notebook_template.replace('CONFIG_NAME',
                                      layout).replace('DATA_FILENAME',
                                                      filename).strip())

    os.chdir(nbdir)
    try:
        Voila.notebook_path = 'notebook.ipynb'
        VoilaConfiguration.template = 'jdaviz-default'
        sys.exit(Voila().launch_instance())
    finally:
        os.chdir(start_dir)
from voila.app import Voila


if __name__ == "__main__":
    v = Voila.launch_instance(
        ["Explainer App.ipynb", "--template=vuetify-default", "--no-browser"]
    )