How to use the notebook.nbextensions.install_nbextension function in notebook

To help you get started, we’ve selected a few notebook examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dataflownb / dfkernel / dfkernel / nbtests / test_nbextensions.py View on Github external
def test_install_symlink(self):
        with TemporaryDirectory() as d:
            f = u'ƒ.js'
            src = pjoin(d, f)
            touch(src)
            install_nbextension(src, symlink=True)
        dest = pjoin(self.system_nbext, f)
        assert os.path.islink(dest)
        link = os.readlink(dest)
        self.assertEqual(link, src)
github dataflownb / dfkernel / dfkernel / nbtests / test_nbextensions.py View on Github external
def test_quiet(self):
        stdout = StringIO()
        stderr = StringIO()
        with patch.object(sys, 'stdout', stdout), \
             patch.object(sys, 'stderr', stderr):
            install_nbextension(self.src)
        self.assertEqual(stdout.getvalue(), '')
        self.assertEqual(stderr.getvalue(), '')
github dataflownb / dfkernel / dfkernel / nbtests / test_nbextensions.py View on Github external
def test_create_nbextensions_system(self):
        with TemporaryDirectory() as td:
            self.system_nbext = pjoin(td, u'nbextensions')
            with patch.object(nbextensions, 'SYSTEM_JUPYTER_PATH', [td]):
                install_nbextension(self.src, user=False)
                self.assert_installed(
                    pjoin(basename(self.src), u'ƒile'),
                    user=False
                )
github dataflownb / dfkernel / dfkernel / nbtests / test_nbextensions.py View on Github external
def test_overwrite_file(self):
        with TemporaryDirectory() as d:
            fname = u'ƒ.js'
            src = pjoin(d, fname)
            with open(src, 'w') as f:
                f.write('first')
            mtime = touch(src)
            dest = pjoin(self.system_nbext, fname)
            install_nbextension(src)
            with open(src, 'w') as f:
                f.write('overwrite')
            mtime = touch(src, mtime - 100)
            install_nbextension(src, overwrite=True)
            with open(dest) as f:
                self.assertEqual(f.read(), 'overwrite')
github dataflownb / dfkernel / dfkernel / nbtests / test_nbextensions.py View on Github external
def test_single_dir_trailing_slash(self):
        d = u'∂ir/'
        install_nbextension(pjoin(self.src, d))
        self.assert_installed(self.files[-1])
        if os.name == 'nt':
            d = u'∂ir\\'
            install_nbextension(pjoin(self.src, d))
            self.assert_installed(self.files[-1])
github Stepsize / jupyter_search / setup.py View on Github external
if prompt == "yes":
                try:
                    install_nbextension(EXT_DIR, overwrite=True,
                                        nbextensions_dir=DIR)
                    print("OUTCOME: Added the extension to your "
                          "%s directory" % (DIR))
                except:
                    print("WARNING: Unable to install the extension to your "
                          "(nb)extensions folder")
                    print("ERROR: %s" % (sys.exc_info()[0]))
                    raise
            else:
                return
        else:
            try:
                install_nbextension(EXT_DIR, overwrite=True,
                                    nbextensions_dir=DIR)
                print("OUTCOME: Added the extension to your %s directory"
                      % (DIR))
            except:
                print("WARNING: Unable to install the extension to your "
                      "(nb)extensions folder")
                print("ERROR: %s" % (sys.exc_info()[0]))
                raise
github csiro-scientific-computing / NotebookDiff / notebookdiff / filemanager.py View on Github external
def __init__(self, *args, **kwargs):
        # Install the nbextension when instantiated
        from os.path import dirname, abspath, join as pjoin
        from notebook.nbextensions import install_nbextension
        from notebook.services.config import ConfigManager

        # Install the extension
        notebookdiffdir = pjoin(dirname(abspath(__file__)), 'notebookdiff_js')
        install_nbextension(notebookdiffdir, user=True)

        # Enable the extension
        cm = ConfigManager()
        cm.update('notebook', {"load_extensions": {
            "notebookdiff_js/notebook_ui": True
        }})

        # call the parent constructor
        super(NotebookDiffContentsManager, self).__init__(*args, **kwargs)
github Anaconda-Platform / nbbrowserpdf / nbbrowserpdf / install.py View on Github external
Parameters
        ----------
        enable: bool
            Enable the extension on every notebook launch
        **kwargs: keyword arguments
            Other keyword arguments passed to the install_nbextension command
    """
    from notebook.nbextensions import install_nbextension
    from notebook.services.config import ConfigManager

    directory = join(dirname(abspath(__file__)), 'static', 'nbbrowserpdf')

    kwargs = {k: v for k, v in kwargs.items() if not (v is None)}

    kwargs["destination"] = "nbbrowserpdf"
    install_nbextension(directory, **kwargs)

    if enable:
        if "prefix" in kwargs:
            path = join(kwargs["prefix"], "etc", "jupyter")
            if not exists(path):
                print("Making directory", path)
                os.makedirs(path)
        else:
            path = jupyter_config_dir()

        cm = ConfigManager(config_dir=path)
        print("Enabling nbbrowserpdf server component in", cm.config_dir)
        cfg = cm.get("jupyter_notebook_config")
        print("Existing config...")
        pprint(cfg)
        server_extensions = (
github jupyter / jupyter-drive / jupyterdrive / __init__.py View on Github external
def install(profile='default', symlink=True, mixed=False, user=False,
            prefix=None, verbose=False, path=None):

    dname = os.path.dirname(__file__)

    # might want to check if already installed and overwrite if exist
    if symlink and verbose:
        log.info('Will try symlink nbextension')
    if mixed and verbose:
        log.info('Will install mixed content manager')
    if prefix and verbose:
        log.info("I'll install in prefix:", prefix)
    nbe.install_nbextension(os.path.join(dname,'gdrive'),
                                symlink=symlink,
                                   user=user,
                                 prefix=prefix,
                                 nbextensions_dir=path)

    activate(profile, mixed=mixed)
github DigitalGlobe / juno-magic / setup.py View on Github external
def run(self):
        _develop.run(self)
        install_nbextension(extension_dir, symlink=True,
                            overwrite=True, user=True, destination="juno_magic")
        cm = ConfigManager()
        cm.update('notebook', {"load_extensions": {"juno_magic/index": True } })