Пример #1
0
 def setup_extensions(self, CUR_EXT, EXT_DIR, DIR):
     # Install the extensions to the required directories
     ensure_dir_exists(DIR)
     if os.path.exists(CUR_EXT):
         question = "ACTION: The Stepsize extension directory already " \
                    "exists, do you want to overwrite %s with the " \
                    "current installation?" % (CUR_EXT)
         prompt = self.query(question)
         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
Пример #2
0
def install(user=False, symlink=False, quiet=False, enable=False):
    """Install the widget nbextension and optionally enable it.
    
    Parameters
    ----------
    user: bool
        Install for current user instead of system-wide.
    symlink: bool
        Symlink instead of copy (for development).
    enable: bool
        Enable the extension after installing it.
    quiet: bool
        Suppress print statements about progress.
    """
    if not quiet:
        print("Installing nbextension ...")
    staticdir = pjoin(dirname(abspath(__file__)), 'static')
    install_nbextension(staticdir,
                        destination='widgets',
                        user=user,
                        symlink=symlink)

    if enable:
        if not quiet:
            print("Enabling the extension ...")
        cm = ConfigManager()
        cm.update(
            'notebook',
            {"load_extensions": {
                "widgets/notebook/js/extension": True,
            }})
    if not quiet:
        print("Done.")
Пример #3
0
def load_jupyter_server_extension(nbapp):
    """Load the nbserver"""
    windows = sys.platform.startswith('win')
    webapp = nbapp.web_app
    webapp.settings['shared_manager'] = SharedManager(parent=nbapp)
    base_url = webapp.settings['base_url']

    install_nbextension(static, destination='nbshared', symlink=not windows, user=True)

    # cfgm = nbapp.config_manager
    # cfgm.update('tree', {
    #     'load_extensions': {
    #         'nbexamples/main': True,
    #     }
    # })
    # cfgm.update('notebook', {
    #     'load_extensions': {
    #         'nbexamples/submit-example-button': True,
    #     }
    # })

    webapp.add_handlers(".*$", [
        (ujoin(base_url, pat), handler)
        for pat, handler in default_handlers
    ])
Пример #4
0
def install(user=False, symlink=False, enable=False):
    """Install the widget nbextension and optionally enable it.

    Parameters
    ----------
    user: bool
        Install for current user instead of system-wide.
    symlink: bool
        Symlink instead of copy (for development).
    """
    try:
        from notebook.nbextensions import install_nbextension
        from notebook.services.config import ConfigManager
    except ModuleNotFoundError:
        print('"notebook" not installed, silently failing...')
        return
    widgetsdir = pjoin(dirname(abspath(__file__)), 'widgets')
    install_nbextension(widgetsdir,
                        destination='arcgis',
                        user=user,
                        symlink=symlink)

    cm = ConfigManager()
    cm.update('notebook', {"load_extensions": {
        "arcgis/mapview": True,
    }})
Пример #5
0
def install(user=False, symlink=False, overwrite=False, enable=False,
            **kwargs):
    """Install the nbpresent nbextension.

    Parameters
    ----------
    user: bool
        Install for current user instead of system-wide.
    symlink: bool
        Symlink instead of copy (for development).
    overwrite: bool
        Overwrite previously-installed files for this extension
    enable: bool
        Enable the extension on every notebook launch
    **kwargs: keyword arguments
        Other keyword arguments passed to the install_nbextension command
    """
    print("Installing nbpresent nbextension...")
    directory = join(dirname(abspath(__file__)), 'static', 'nbpresent')
    install_nbextension(directory, destination='nbpresent',
                        symlink=symlink, user=user, overwrite=overwrite,
                        **kwargs)

    if enable:
        print("Enabling nbpresent at every notebook launch...")
        cm = ConfigManager()
        cm.update('notebook',
                  {"load_extensions": {"nbpresent/nbpresent.min": True}})
Пример #6
0
def load_jupyter_server_extension(nbapp):
    """Load the nbserver"""
    windows = sys.platform.startswith('win')
    webapp = nbapp.web_app
    webapp.settings['example_manager'] = Examples(parent=nbapp)
    base_url = webapp.settings['base_url']

    install_nbextension(static, destination='nbexamples', symlink=not windows,
                        user=True)
    cfgm = nbapp.config_manager
    cfgm.update('tree', {
        'load_extensions': {
            'nbexamples/main': True,
        }
    })
    cfgm.update('notebook', {
        'load_extensions': {
            'nbexamples/submit-example-button': True,
        }
    })

    ExampleActionHandler.base_url = base_url  # used to redirect after fetch
    webapp.add_handlers(".*$", [
        (ujoin(base_url, pat), handler)
        for pat, handler in default_handlers
    ])
Пример #7
0
 def setup_extensions(self, CUR_EXT, EXT_DIR, DIR):
     # Install the extensions to the required directories
     ensure_dir_exists(DIR)
     if os.path.exists(CUR_EXT):
         question = "ACTION: The Stepsize extension directory already " \
                    "exists, do you want to overwrite %s with the " \
                    "current installation?" % (CUR_EXT)
         prompt = self.query(question)
         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
Пример #8
0
def load_jupyter_server_extension(nbapp):
    """Load the nbserver extension"""
    from distutils.version import LooseVersion as V
    import notebook

    nbapp.log.info("Loading IPython parallel extension")
    webapp = nbapp.web_app
    webapp.settings['cluster_manager'] = ClusterManager(parent=nbapp)

    if V(notebook.__version__) < V('4.2'):
        windows = sys.platform.startswith('win')
        install_nbextension(static,
                            destination='ipyparallel',
                            symlink=not windows,
                            user=True)
        cfgm = nbapp.config_manager
        cfgm.update(
            'tree',
            {'load_extensions': {
                'ipyparallel/main': True,
            }},
        )
    base_url = webapp.settings['base_url']
    webapp.add_handlers(".*$", [(ujoin(base_url, pat), handler)
                                for pat, handler in default_handlers])
Пример #9
0
 def test_create_nbextensions_user(self):
     with TemporaryDirectory() as td:
         install_nbextension(self.src, user=True)
         self.assert_installed(
             pjoin(basename(self.src), u'ƒile'),
             user=True
         )
 def test_create_nbextensions_user(self):
     with TemporaryDirectory() as td:
         install_nbextension(self.src, user=True)
         self.assert_installed(
             pjoin(basename(self.src), u'ƒile'),
             user=True
         )
Пример #11
0
def _install_notebook_extension():
    print('Installing notebook extension')
    install_nbextension(EXT_DIR, overwrite=True, user=True)
    cm = ConfigManager()
    print('Enabling extension for notebook')
    cm.update('notebook', {"load_extensions": {'urth_cms_js/notebook/main': True}})
    print('Enabling extension for dashboard')
    cm.update('tree', {"load_extensions": {'urth_cms_js/dashboard/main': True}})
    print('Enabling extension for text editor')
    cm.update('edit', {"load_extensions": {'urth_cms_js/editor/main': True}})
    print('Enabling notebook and associated files bundler')
    cm.update('notebook', { 
      'jupyter_cms_bundlers': {
        'notebook_associations_download': {
          'label': 'IPython Notebook bundle (.zip)',
          'module_name': 'urth.cms.nb_bundler',
          'group': 'download'
        }
      }
    })

    print('Installing notebook server extension')
    fn = os.path.join(jupyter_config_dir(), 'jupyter_notebook_config.py')
    with open(fn, 'r+') as fh:
        lines = fh.read()
        if SERVER_EXT_CONFIG not in lines:
            fh.seek(0, 2)
            fh.write('\n')
            fh.write(SERVER_EXT_CONFIG)
Пример #12
0
    def run(self):
        # Install Python package
        install.run(self)

        # Install JavaScript extensions to ~/.local/jupyter/
        install_nbextension(EXT_DIR, overwrite=True, user=True)

        # Activate the JS extensions on the notebook, tree, and edit screens
        js_cm = ConfigManager()
        js_cm.update('notebook',
                     {"load_extensions": {
                         'nbdocker/notebook': True
                     }})
        js_cm.update('tree', {"load_extensions": {'nbdocker/dashboard': True}})
        js_cm.update('edit', {"load_extensions": {'nbdocker/editor': True}})

        # Activate the Python server extension
        server_cm = ConfigManager(config_dir=jupyter_config_dir())
        cfg = server_cm.get('jupyter_notebook_config')
        server_extensions = (cfg.setdefault('NotebookApp', {}).setdefault(
            'server_extensions', []))
        if extension not in server_extensions:
            cfg['NotebookApp']['server_extensions'] += [
                'nbdocker.DockerHanlder'
            ]
            server_cm.update('jupyter_notebook_config', cfg)
Пример #13
0
 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)
Пример #14
0
def install(user=False, symlink=False, quiet=False, enable=False):
    """Install the widget nbextension and optionally enable it.
    
    Parameters
    ----------
    user: bool
        Install for current user instead of system-wide.
    symlink: bool
        Symlink instead of copy (for development).
    enable: bool
        Enable the extension after installing it.
    quiet: bool
        Suppress print statements about progress.
    """
    if not quiet:
        print("Installing nbextension ...")
    staticdir = pjoin(dirname(abspath(__file__)), "static")
    install_nbextension(staticdir, destination="widgets", user=user, symlink=symlink)

    if enable:
        if not quiet:
            print("Enabling the extension ...")
        cm = ConfigManager()
        cm.update("notebook", {"load_extensions": {"widgets/extension": True}})
    if not quiet:
        print("Done.")
Пример #15
0
 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])
Пример #16
0
 def test_quiet(self):
     stdout = StringIO()
     stderr = StringIO()
     with patch.object(sys, 'stdout', stdout), \
          patch.object(sys, 'stderr', stderr):
         install_nbextension(self.src, verbose=0)
     self.assertEqual(stdout.getvalue(), '')
     self.assertEqual(stderr.getvalue(), '')
Пример #17
0
 def test_install_zip(self):
     path = pjoin(self.src, "myjsext.zip")
     with zipfile.ZipFile(path, 'w') as f:
         f.writestr("a.js", b"b();")
         f.writestr("foo/a.js", b"foo();")
     install_nbextension(path)
     self.assert_installed("a.js")
     self.assert_installed(pjoin("foo", "a.js"))
Пример #18
0
def install(config_dir, use_symlink=False, enable=True):
    # Install the livereveal code.
    install_nbextension(livereveal_dir, symlink=use_symlink,
                        overwrite=use_symlink, user=True)

    if enable:
        cm = ConfigManager(config_dir=config_dir)
        cm.update('notebook', {"load_extensions": {"livereveal/main": True}})
Пример #19
0
def enable_notebook():
    """Enable IPython notebook widgets to be displayed.

    This function should be called before using TrajectoryWidget.
    """
    display(_REQUIRE_CONFIG)
    staticdir =  resource_filename('mdview', os.path.join('html', 'static'))
    install_nbextension(staticdir, destination='mdview', user=True)
Пример #20
0
 def test_quiet(self):
     stdout = StringIO()
     stderr = StringIO()
     with patch.object(sys, 'stdout', stdout), \
          patch.object(sys, 'stderr', stderr):
         install_nbextension(self.src, verbose=0)
     self.assertEqual(stdout.getvalue(), '')
     self.assertEqual(stderr.getvalue(), '')
Пример #21
0
 def test_install_zip(self):
     path = pjoin(self.src, "myjsext.zip")
     with zipfile.ZipFile(path, 'w') as f:
         f.writestr("a.js", b"b();")
         f.writestr("foo/a.js", b"foo();")
     install_nbextension(path)
     self.assert_installed("a.js")
     self.assert_installed(pjoin("foo", "a.js"))
Пример #22
0
 def test_create_nbextensions_user(self):
     with TemporaryDirectory() as td:
         self.data_dir = pjoin(td, u'jupyter_data')
         install_nbextension(self.src, user=True)
         self.assert_installed(
             pjoin(basename(self.src), u'ƒile'),
             user=True
         )
Пример #23
0
def enable_notebook():
    """Enable IPython notebook widgets to be displayed.

    This function should be called before using TrajectoryWidget.
    """
    display(_REQUIRE_CONFIG)
    staticdir = resource_filename('mdtraj', os.path.join('html', 'static'))
    install_nbextension(staticdir, destination='mdtraj', user=True)
Пример #24
0
 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])
Пример #25
0
def install(enable=False, **kwargs):
    """Install the nbpresent nbextension assets and optionally enables the
       nbextension and server extension for every run.

    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", "nbpresent")

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

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

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

        cm = ConfigManager(config_dir=path)
        print("Enabling nbpresent server component in", cm.config_dir)
        cfg = cm.get("jupyter_notebook_config")
        print("Existing config...")
        pprint(cfg)
        server_extensions = cfg.setdefault("NotebookApp", {}).setdefault("server_extensions", [])
        if "nbpresent" not in server_extensions:
            cfg["NotebookApp"]["server_extensions"] += ["nbpresent"]

        cm.update("jupyter_notebook_config", cfg)
        print("New config...")
        pprint(cm.get("jupyter_notebook_config"))

        _jupyter_config_dir = jupyter_config_dir()
        # try:
        #     subprocess.call(["conda", "info", "--root"])
        #     print("conda detected")
        #     _jupyter_config_dir = ENV_CONFIG_PATH[0]
        # except OSError:
        #     print("conda not detected")

        cm = ConfigManager(config_dir=join(_jupyter_config_dir, "nbconfig"))
        print("Enabling nbpresent nbextension at notebook launch in", cm.config_dir)

        if not exists(cm.config_dir):
            print("Making directory", cm.config_dir)
            os.makedirs(cm.config_dir)

        cm.update("notebook", {"load_extensions": {"nbpresent/nbpresent.min": True}})
Пример #26
0
 def install_extensions(self):
     install_nbextension(self.extra_args[0],
                         overwrite=self.overwrite,
                         symlink=self.symlink,
                         user=self.user,
                         sys_prefix=self.sys_prefix,
                         prefix=self.prefix,
                         nbextensions_dir=self.nbextensions_dir,
                         logger=self.log)
Пример #27
0
 def run(self):
     _develop.run(self)
     install_nbextension(extension_dir,
                         symlink=True,
                         overwrite=True,
                         user=True,
                         destination="idaho_map")
     cm = ConfigManager()
     cm.update('notebook', {"load_extensions": {"idaho_map/index": True}})
Пример #28
0
    def test_install_destination_bad(self):
        with TemporaryDirectory() as d:
            zf = u'ƒ.zip'
            zsrc = pjoin(d, zf)
            with zipfile.ZipFile(zsrc, 'w') as z:
                z.writestr("a.js", b"b();")

            with self.assertRaises(ValueError):
                install_nbextension(zsrc, destination='foo')
Пример #29
0
 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
             )
Пример #30
0
 def test_install_destination_bad(self):
     with TemporaryDirectory() as d:
         zf = u'ƒ.zip'
         zsrc = pjoin(d, zf)
         with zipfile.ZipFile(zsrc, 'w') as z:
             z.writestr("a.js", b"b();")
     
         with self.assertRaises(ValueError):
             install_nbextension(zsrc, destination='foo')
Пример #31
0
 def install(self):
     """
     Install an extension (copy or symlinks)
     """
     try:
         install_nbextension(self.kwargs['static'], **self._install_params())
         self._echo("Installing {}".format(self.name), 'ok')
     except Exception as e:
         self._echo(e, None)
         self._echo("Installing {}".format(self.name), 'fail')
Пример #32
0
 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)
Пример #33
0
 def test_check_nbextension(self):
     with TemporaryDirectory() as d:
         f = u'ƒ.js'
         src = pjoin(d, f)
         touch(src)
         install_nbextension(src, user=True)
     
     assert check_nbextension(f, user=True)
     assert check_nbextension([f], user=True)
     assert not check_nbextension([f, pjoin('dne', f)], user=True)
Пример #34
0
 def install_extensions(self):
     install_nbextension(
         self.extra_args[0],
         overwrite=self.overwrite,
         symlink=self.symlink,
         user=self.user,
         sys_prefix=self.sys_prefix,
         prefix=self.prefix,
         nbextensions_dir=self.nbextensions_dir,
         logger=self.log)
Пример #35
0
    def test_check_nbextension(self):
        with TemporaryDirectory() as d:
            f = u'ƒ.js'
            src = pjoin(d, f)
            touch(src)
            install_nbextension(src, user=True)

        assert check_nbextension(f, user=True)
        assert check_nbextension([f], user=True)
        assert not check_nbextension([f, pjoin('dne', f)], user=True)
Пример #36
0
def install(use_symlink=False, enable=True):
    # Install the livereveal code.
    install_nbextension(livereveal_dir,
                        symlink=use_symlink,
                        overwrite=use_symlink,
                        user=True)

    if enable:
        cm = ConfigManager()
        cm.update('notebook', {"load_extensions": {"livereveal/main": True}})
Пример #37
0
 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)
Пример #38
0
    def run(self):
        global wmmexec
        user = '******' in sys.argv or not _is_root()
        configfilestr = "# iwolfram configuration file\nmathexec = '{wolfram-caller-script-path}'\n\n"
        configfilestr = configfilestr.replace('{wolfram-caller-script-path}',
                                              wmmexec)
        with open('wolfram_kernel/config.py', 'w') as f:
            f.write(configfilestr)

        #Run the standard intallation
        install.run(self)

        def install_kernelspec(self):
            from ipykernel.kernelspec import write_kernel_spec
            from jupyter_client.kernelspec import KernelSpecManager
            from wolfram_kernel.wolfram_kernel import WolframKernel
            kernel_json = WolframKernel.kernel_json
            kernel_js = WolframKernel.kernel_js
            kernel_spec_manager = KernelSpecManager()
            log.info('Writing kernel spec')
            kernel_spec_path = write_kernel_spec(overrides=kernel_json)
            with open(kernel_spec_path + "/kernel.js", "w") as jsfile:
                jsfile.write(kernel_js)

            log.info('Installing kernel spec')
            try:
                kernel_spec_manager.install_kernel_spec(
                    kernel_spec_path,
                    kernel_name=kernel_json['name'],
                    user=user)
            except:
                log.error('Failed to install kernel spec in ' +
                          kernel_spec_path)
                kernel_spec_manager.install_kernel_spec(
                    kernel_spec_path,
                    kernel_name=kernel_json['name'],
                    user=not user)

        print("Installing kernel spec")
        #Build and Install the kernelspec
        install_kernelspec(self)
        log.info("Installing nbextension")
        from notebook.nbextensions import install_nbextension
        import os.path
        try:
            install_nbextension(
                os.path.join(os.path.dirname(__file__), 'nbmathics'),
                overwrite=True,
            )
            jup_nbex_exec = os.path.dirname(
                sys.executable) + "/" + "jupyter-nbextension"
            os.system(jup_nbex_exec + " install --system  nbmathics")
            os.system(jup_nbex_exec + "  enable --system --py  nbmathics")
        except:
            log.info("nbextension can not be installed")
Пример #39
0
 def run_nbextension_install(develop):
     import sys
     sysprefix = hasattr(sys, 'real_prefix')
     if sysprefix:
         install_nbextension(extension_dir, symlink=develop, sys_prefix=sysprefix)
     else:
         install_nbextension(extension_dir, symlink=develop, user=user)
     if enable is not None:
         print("Enabling the extension ...")
         cm = ConfigManager()
         cm.update('notebook', {"load_extensions": {enable: True}})
Пример #40
0
 def test_create_data_dir(self):
     """install_nbextension when data_dir doesn't exist"""
     with TemporaryDirectory() as td:
         self.data_dir = pjoin(td, u'jupyter_data')
         install_nbextension(self.src, user=True)
         self.assert_dir_exists(self.data_dir)
         for file in self.files:
             self.assert_installed(
                 pjoin(basename(self.src), file),
                 user=True,
             )
Пример #41
0
 def test_create_data_dir(self):
     """install_nbextension when data_dir doesn't exist"""
     with TemporaryDirectory() as td:
         self.data_dir = pjoin(td, u'jupyter_data')
         install_nbextension(self.src, user=True)
         self.assert_dir_exists(self.data_dir)
         for file in self.files:
             self.assert_installed(
                 pjoin(basename(self.src), file),
                 user=True,
             )
Пример #42
0
 def run(self):
     _develop.run(self)
     install_nbextension(
         extension_dir,
         symlink=True,
         overwrite=True,
         user=False,
         sys_prefix=True,  # to install it inside virtualenv
         destination="robomission")
     cm = ConfigManager()
     cm.update('notebook', {"load_extensions": {"robomission/index": True } })
Пример #43
0
def install_nbextension(**kwargs):
    """Install the appropriate html and javascript into the nbextension.

    Keyword arguments will be passed on to the Jupyter install_nbextension function.
    """
    import os.path
    from notebook import nbextensions

    pkgdir = os.path.dirname(__file__)
    kwargs["destination"] = "bqplot"
    nbextensions.install_nbextension(os.path.join(pkgdir, "nbextension"), **kwargs)
Пример #44
0
 def run(self):
     _develop.run(self)
     install_nbextension(
         extension_dir,
         symlink=True,
         overwrite=True,
         user=False,
         sys_prefix=True,  # to install it inside virtualenv
         destination="robomission")
     cm = ConfigManager()
     cm.update('notebook', {"load_extensions": {"robomission/index": True}})
Пример #45
0
 def install(self):
     """
     Install an extension (copy or symlinks)
     """
     try:
         install_nbextension(self.kwargs['static'],
                             **self._install_params())
         self._echo("Installing {}".format(self.name), 'ok')
     except Exception as e:
         self._echo(e, None)
         self._echo("Installing {}".format(self.name), 'fail')
 def test_nbextension_enable(self):
     with TemporaryDirectory() as d:
         f = u'ƒ.js'
         src = pjoin(d, f)
         touch(src)
         install_nbextension(src, user=True)
         enable_nbextension(section='notebook', require=u'ƒ')
     
     config_dir = os.path.join(_get_config_dir(user=True), 'nbconfig')
     cm = BaseJSONConfigManager(config_dir=config_dir)
     enabled = cm.get('notebook').get('load_extensions', {}).get(u'ƒ', False)
     assert enabled
Пример #47
0
 def test_nbextension_enable(self):
     with TemporaryDirectory() as d:
         f = u'ƒ.js'
         src = pjoin(d, f)
         touch(src)
         install_nbextension(src, user=True)
         enable_nbextension(section='notebook', require=u'ƒ')
     
     config_dir = os.path.join(_get_config_dir(user=True), 'nbconfig')
     cm = BaseJSONConfigManager(config_dir=config_dir)
     enabled = cm.get('notebook').get('load_extensions', {}).get(u'ƒ', False)
     assert enabled
Пример #48
0
def install_notebook_extension(path=None,
                               overwrite=False,
                               symlink=False,
                               user=False,
                               prefix=None,
                               nbextensions_dir=None,
                               destination=None):
    """
    Install notebook extensions,
    see `install_nbextension <https://ipython.org/ipython-doc/dev/api/generated/IPython.html.nbextensions.html
    #IPython.html.nbextensions.install_nbextension>`_
    for documentation.

    @param      path                if None, use default value
    @param      overwrite           overwrite the extension
    @param      symlink             see the original function
    @param      user                user
    @param      prefix              see the original function
    @param      nbextensions_dir    see the original function
    @param      destination         see the original function
    @return                         standard output

    Default value is
    `https://github.com/ipython-contrib/IPython-notebook-extensions/archive/master.zip
    <https://github.com/ipython-contrib/IPython-notebook-extensions/archive/master.zip>`_.

    .. versionadded:: 1.3
    """
    if path is None:
        path = "https://github.com/ipython-contrib/IPython-notebook-extensions/archive/master.zip"

    cout = sys.stdout
    cerr = sys.stderr
    sys.stdout = StringIO()
    sys.stderr = StringIO()
    from notebook.nbextensions import install_nbextension
    install_nbextension(path=path,
                        overwrite=overwrite,
                        symlink=symlink,
                        user=user,
                        prefix=prefix,
                        nbextensions_dir=nbextensions_dir,
                        destination=destination)

    out = sys.stdout.getvalue()
    err = sys.stderr.getvalue()
    sys.stdout = cout
    sys.stderr = cerr
    if len(err) != 0:
        raise NotebookException(
            "unable to install exception from: {0}\nOUT:\n{1}\n[nberror]\n{2}".
            format(path, out, err))
    return out
Пример #49
0
 def test_install_symlink_bad(self):
     with self.assertRaises(ValueError):
         install_nbextension("http://example.com/foo.js", symlink=True)
     
     with TemporaryDirectory() as d:
         zf = u'ƒ.zip'
         zsrc = pjoin(d, zf)
         with zipfile.ZipFile(zsrc, 'w') as z:
             z.writestr("a.js", b"b();")
     
         with self.assertRaises(ValueError):
             install_nbextension(zsrc, symlink=True)
Пример #50
0
    def test_install_symlink_bad(self):
        with self.assertRaises(ValueError):
            install_nbextension("http://example.com/foo.js", symlink=True)

        with TemporaryDirectory() as d:
            zf = u'ƒ.zip'
            zsrc = pjoin(d, zf)
            with zipfile.ZipFile(zsrc, 'w') as z:
                z.writestr("a.js", b"b();")

            with self.assertRaises(ValueError):
                install_nbextension(zsrc, symlink=True)
Пример #51
0
 def run(self):
     _develop.run(self)
     if install_nbextension is not None and ConfigManager is not None:
         install_nbextension(extension_dir,
                             symlink=True,
                             overwrite=True,
                             user=True,
                             destination="demdraper")
         cm = ConfigManager()
         cm.update('notebook',
                   {"load_extensions": {
                       "demdraper/index": True
                   }})
Пример #52
0
 def test_overwrite_dir(self):
     with TemporaryDirectory() as src:
         base = basename(src)
         fname = u'ƒ.js'
         touch(pjoin(src, fname))
         install_nbextension(src)
         self.assert_installed(pjoin(base, fname))
         os.remove(pjoin(src, fname))
         fname2 = u'∂.js'
         touch(pjoin(src, fname2))
         install_nbextension(src, overwrite=True)
         self.assert_installed(pjoin(base, fname2))
         self.assert_not_installed(pjoin(base, fname))
Пример #53
0
 def test_overwrite_dir(self):
     with TemporaryDirectory() as src:
         base = basename(src)
         fname = u'ƒ.js'
         touch(pjoin(src, fname))
         install_nbextension(src)
         self.assert_installed(pjoin(base, fname))
         os.remove(pjoin(src, fname))
         fname2 = u'∂.js'
         touch(pjoin(src, fname2))
         install_nbextension(src, overwrite=True)
         self.assert_installed(pjoin(base, fname2))
         self.assert_not_installed(pjoin(base, fname))
Пример #54
0
def install(user=False, symlink=False, **kw):
    """
    Install SOLVCON's nbextension.
    
    :param user: Install to current user's home.
    :type user: bool
    :param symlink: Do symbolic link instead of copy.
    :type symlink: bool
    """
    directory = os.path.join(
        os.path.dirname(os.path.abspath(__file__)), 'nbextension')
    install_nbextension(directory, destination='solvcon',
                        symlink=symlink, user=user, **kw)
Пример #55
0
    def test_install_tar(self):
        def _add_file(f, fname, buf):
            info = tarfile.TarInfo(fname)
            info.size = len(buf)
            f.addfile(info, BytesIO(buf))

        for i, ext in enumerate((".tar.gz", ".tgz", ".tar.bz2")):
            path = pjoin(self.src, "myjsext" + ext)
            with tarfile.open(path, 'w') as f:
                _add_file(f, "b%i.js" % i, b"b();")
                _add_file(f, "foo/b%i.js" % i, b"foo();")
            install_nbextension(path)
            self.assert_installed("b%i.js" % i)
            self.assert_installed(pjoin("foo", "b%i.js" % i))
Пример #56
0
 def test_install_tar(self):
     def _add_file(f, fname, buf):
         info = tarfile.TarInfo(fname)
         info.size = len(buf)
         f.addfile(info, BytesIO(buf))
     
     for i,ext in enumerate((".tar.gz", ".tgz", ".tar.bz2")):
         path = pjoin(self.src, "myjsext" + ext)
         with tarfile.open(path, 'w') as f:
             _add_file(f, "b%i.js" % i, b"b();")
             _add_file(f, "foo/b%i.js" % i, b"foo();")
         install_nbextension(path)
         self.assert_installed("b%i.js" % i)
         self.assert_installed(pjoin("foo", "b%i.js" % i))
Пример #57
0
 def test_overwrite_broken_symlink(self):
     with TemporaryDirectory() as d:
         f = u'ƒ.js'
         f2 = u'ƒ2.js'
         src = pjoin(d, f)
         src2 = pjoin(d, f2)
         touch(src)
         install_nbextension(src, symlink=True)
         os.rename(src, src2)
         install_nbextension(src2, symlink=True, overwrite=True, destination=f)
     dest = pjoin(self.system_nbext, f)
     assert os.path.islink(dest)
     link = os.readlink(dest)
     self.assertEqual(link, src2)
Пример #58
0
    def test_skip_old_file(self):
        with TemporaryDirectory() as d:
            fname = u'ƒ.js'
            src = pjoin(d, fname)
            mtime = touch(src)
            install_nbextension(src)
            self.assert_installed(fname)
            dest = pjoin(self.system_nbext, fname)
            old_mtime = os.stat(dest).st_mtime

            mtime = touch(src, mtime - 100)
            install_nbextension(src)
            new_mtime = os.stat(dest).st_mtime
            self.assertEqual(new_mtime, old_mtime)