Esempio n. 1
0
def install_notebook_widgets(origin_base, dest_base, verbose=False):
    '''
    Convenience wrapper around :py:func:`~notebook.install_nbextension` that
    installs Jupyter notebook extensions using a systematic naming convention (
    mimics the source directory and file name structure rather than installing
    as a flat file set).

    This function will read the special file "__paths__" to collect dependencies
    not present in the nbextensions directory.

    Args:
        origin_base (str): Location of extension source code
        dest_base (str): Destination location (system and/or user specific)
        verbose (bool): Verbose installation (default False)

    See Also:
        The configuration module :mod:`~exa._config` describes the default
        arguments used by :func:`~exa._install.install` during installation.
    '''
    try:
        shutil.rmtree(dest_base)
    except:
        pass
    for root, subdirs, files in os.walk(origin_base):
        for filename in files:
            subdir = root.split('nbextensions')[-1]
            orig = mkp(root, filename)
            dest = mkp(dest_base, subdir, mk=True)
            install_nbextension(orig, verbose=verbose, overwrite=True, nbextensions_dir=dest)
 def _install_nbextension(extensions):
     """Wrapper for IPython.html.install_nbextension."""
     if IPython.version_info[0] >= 3:
         for extension in extensions:
             install_nbextension(extension, user=True, verbose=0)
     else:
         install_nbextension(extensions, verbose=0)
Esempio n. 3
0
def _prepare_js(force=False):
    pkgdir = op.dirname(__file__)
    jsdir = op.join(pkgdir, '../../html/static/js/')
    # Make sure the JS files are installed to user directory (new argument
    # in IPython 3.0).
    if IPYTHON_MAJOR_VERSION >= 3:
        kwargs = {'user': True}
    else:
        kwargs = {}
    install_nbextension(jsdir, overwrite=force, destination='vispy',
                        symlink=(os.name != 'nt'), **kwargs)
Esempio n. 4
0
def nbinstall(overwrite=False, user=True, prefix=None):
    """Copies resources to the '/nbextensions' folder in your IPython directory

    This function was taken from [5]_ and modified to match our usecase.

    Parameters
    ----------
    overwrite : bool, optional
        If True, always install the files, regardless of what may already be
        installed. Defaults to False.
    user : bool, optional
        Whether to install to the user's .ipython/nbextensions directory.
        Otherwise do a system-wide install
        (e.g. /usr/local/share/jupyter/nbextensions/emperor). Defaults to
        False.
    prefix : str, optional
        Where the files are copied to, by default they are copied to the
        appropriate Jupyter/IPython folder, alternatively it can be a folder
        where the resources are copied to. Note, that if this parameter is set
        `user` has to be `None`.

    Raises
    ------
    ArgumentConflict
        When `prefix` and `user` are used together.

    Notes
    -----
    After you install emperor, call this function once before attempting to
    call ``Emperor`` in the Jupyter notebook.

    References
    ----------
    .. [5] GitHub repository for qgrid https://github.com/quantopian/qgrid
    """

    # Lazy imports so we don't pollute the namespace.
    try:
        from notebook import install_nbextension
    except ImportError:
        from IPython.html.nbextensions import install_nbextension
    from IPython import version_info

    install_nbextension(get_emperor_support_files_dir(),
                        overwrite=overwrite,
                        symlink=False,
                        prefix=prefix,
                        verbose=0,
                        destination='emperor/support_files',
                        **({
                            'user': user
                        } if version_info >= (3, 0, 0, '') else {}))
Esempio n. 5
0
def nbinstall(overwrite=False, user=True):
    """
    Copies javascript and css dependencies to the '/nbextensions' folder in
    your IPython directory.

    Parameters
    ----------

    overwrite : bool
        If True, always install the files, regardless of what may already be
        installed.  Defaults to False.
    user : bool
        Whether to install to the user's .ipython/nbextensions directory.
        Otherwise do a system-wide install
        (e.g. /usr/local/share/jupyter/nbextensions).  Defaults to False.

    Notes
    -----
    After you install qgrid, call this function once before attempting to
    call ``show_grid``.
    """

    # Lazy imports so we don't pollute the namespace.
    import os
    try:
        from notebook import install_nbextension
        from notebook.services.config import ConfigManager
    except ImportError:
        from IPython.html.nbextensions import install_nbextension
        from IPython.html.services.config import ConfigManager
    from IPython import version_info
    from IPython.display import display, Javascript

    qgridjs_path = os.path.join(
        os.path.dirname(__file__),
        'qgridjs',
    )

    install_nbextension(
        qgridjs_path,
        overwrite=overwrite,
        symlink=False,
        verbose=0,
        **({'user': user} if version_info >= (3, 0, 0, '') else {})
    )
Esempio n. 6
0
def nbinstall(overwrite=False, user=True):
    """
    Copies javascript and css dependencies to the '/nbextensions' folder in
    your IPython directory.

    Parameters
    ----------

    overwrite : bool
        If True, always install the files, regardless of what may already be
        installed.  Defaults to False.
    user : bool
        Whether to install to the user's .ipython/nbextensions directory.
        Otherwise do a system-wide install
        (e.g. /usr/local/share/jupyter/nbextensions).  Defaults to False.

    Notes
    -----
    After you install qgrid, call this function once before attempting to
    call ``show_grid``.
    """

    # Lazy imports so we don't pollute the namespace.
    import os
    try:
        from notebook import install_nbextension
        from notebook.services.config import ConfigManager
    except ImportError:
        from IPython.html.nbextensions import install_nbextension
        from IPython.html.services.config import ConfigManager
    from IPython import version_info
    from IPython.display import display, Javascript

    qgridjs_path = os.path.join(
        os.path.dirname(__file__),
        'qgridjs',
    )

    install_nbextension(qgridjs_path,
                        overwrite=overwrite,
                        symlink=False,
                        verbose=0,
                        **({
                            'user': user
                        } if version_info >= (3, 0, 0, '') else {}))
Esempio n. 7
0
def install_notebook_widgets(pkg_nbext, sys_nbext, verbose=False):
    '''
    Convenience wrapper around :py:func:`~notebook.install_nbextension` that
    organizes notebook extensions for exa and related packages in a systematic
    fashion.

    Args:
        pkg_nbext (str): Path to the "_nbextension" directory in the source
        sys_nbext (str): Path to the system "nbextensions" directory
        verbose (bool): Verbose installation
    '''
    try:
        shutil.rmtree(sys_nbext)
    except FileNotFoundError:
        pass
    for root, subdirs, files in os.walk(pkg_nbext):
        for filename in files:
            subdir = root.split('_nbextension')[-1]
            orig = mkp(root, filename)
            dest = mkp(sys_nbext, subdir, mk=True)
            install_nbextension(orig, verbose=verbose, overwrite=True, nbextensions_dir=dest)
Esempio n. 8
0
def nbinstall(overwrite=False, user=True):
    '''
    Installs the Javascript dependencies.

    Parameters
    ----------
    overwrite : bool, optional
        If True, always install the files,
        regardless of what may already be installed.
    user : bool, optional
        Whether to install to the user's nbextensions directory.
    '''
    import os
    try:
        from notebook import install_nbextension
    except ImportError:
        from IPython.html.nbextensions import install_nbextension
    from .widget import _packet_name

    view_static = os.path.abspath(
        os.path.join(os.path.dirname(__file__), 'static', _packet_name()))
    install_nbextension(view_static, user=user, overwrite=overwrite, verbose=0)