示例#1
0
    def test_app_dir(self):
        app_dir = self.tempdir()
        options = AppOptions(app_dir=app_dir)

        assert install_extension(self.mock_extension,
                                 app_options=options) is True
        path = pjoin(app_dir, "extensions", "*.tgz")
        assert glob.glob(path)
        extensions = get_app_info(app_options=options)["extensions"]
        ext_name = self.pkg_names["extension"]
        assert ext_name in extensions
        assert check_extension(ext_name, app_options=options)

        assert uninstall_extension(self.pkg_names["extension"],
                                   app_options=options) is True
        path = pjoin(app_dir, "extensions", "*.tgz")
        assert not glob.glob(path)
        extensions = get_app_info(app_options=options)["extensions"]
        assert ext_name not in extensions
        assert not check_extension(ext_name, app_options=options)

        assert link_package(self.mock_package, app_options=options) is True
        linked = get_app_info(app_options=options)["linked_packages"]
        pkg_name = self.pkg_names["package"]
        assert pkg_name in linked
        assert check_extension(pkg_name, app_options=options)

        assert unlink_package(self.mock_package, app_options=options) is True
        linked = get_app_info(app_options=options)["linked_packages"]
        assert pkg_name not in linked
        assert not check_extension(pkg_name, app_options=options)
示例#2
0
    def test_app_dir_shadowing(self):
        app_dir = self.tempdir()
        sys_dir = self.app_dir
        if os.path.exists(sys_dir):
            os.removedirs(sys_dir)

        assert install_extension(self.mock_extension) is True
        sys_path = pjoin(sys_dir, 'extensions', '*.tgz')
        assert glob.glob(sys_path)
        app_path = pjoin(app_dir, 'extensions', '*.tgz')
        assert not glob.glob(app_path)
        extensions = get_app_info(app_dir)['extensions']
        ext_name = self.pkg_names['extension']
        assert ext_name in extensions
        assert check_extension(ext_name, app_dir)

        assert install_extension(self.mock_extension, app_dir) is True
        assert glob.glob(app_path)
        extensions = get_app_info(app_dir)['extensions']
        assert ext_name in extensions
        assert check_extension(ext_name, app_dir)

        assert uninstall_extension(self.pkg_names['extension'], app_dir) is True
        assert not glob.glob(app_path)
        assert glob.glob(sys_path)
        extensions = get_app_info(app_dir)['extensions']
        assert ext_name in extensions
        assert check_extension(ext_name, app_dir)

        assert uninstall_extension(self.pkg_names['extension'], app_dir) is True
        assert not glob.glob(app_path)
        assert not glob.glob(sys_path)
        extensions = get_app_info(app_dir)['extensions']
        assert ext_name not in extensions
        assert not check_extension(ext_name, app_dir)
    def test_app_dir(self):
        app_dir = self.tempdir()
        options = AppOptions(app_dir=app_dir)

        assert install_extension(self.mock_extension,
                                 app_options=options) is True
        path = pjoin(app_dir, 'extensions', '*.tgz')
        assert glob.glob(path)
        extensions = get_app_info(app_options=options)['extensions']
        ext_name = self.pkg_names['extension']
        assert ext_name in extensions
        assert check_extension(ext_name, app_options=options)

        assert uninstall_extension(self.pkg_names['extension'],
                                   app_options=options) is True
        path = pjoin(app_dir, 'extensions', '*.tgz')
        assert not glob.glob(path)
        extensions = get_app_info(app_options=options)['extensions']
        assert ext_name not in extensions
        assert not check_extension(ext_name, app_options=options)

        assert link_package(self.mock_package, app_options=options) is True
        linked = get_app_info(app_options=options)['linked_packages']
        pkg_name = self.pkg_names['package']
        assert pkg_name in linked
        assert check_extension(pkg_name, app_options=options)

        assert unlink_package(self.mock_package, app_options=options) is True
        linked = get_app_info(app_options=options)['linked_packages']
        assert pkg_name not in linked
        assert not check_extension(pkg_name, app_options=options)
    def test_install_mime_renderer(self):
        install_extension(self.mock_mimeextension)
        name = self.pkg_names['mimeextension']
        assert name in get_app_info()['extensions']
        assert check_extension(name)

        assert uninstall_extension(name) is True
        assert name not in get_app_info()['extensions']
        assert not check_extension(name)
示例#5
0
 def test_uninstall_extension(self):
     assert install_extension(self.mock_extension) is True
     name = self.pkg_names["extension"]
     assert check_extension(name)
     assert uninstall_extension(self.pkg_names["extension"]) is True
     path = pjoin(self.app_dir, "extensions", "*.tgz")
     assert not glob.glob(path)
     extensions = get_app_info()["extensions"]
     assert name not in extensions
     assert not check_extension(name)
 def test_uninstall_extension(self):
     assert install_extension(self.mock_extension) is True
     name = self.pkg_names['extension']
     assert check_extension(name)
     assert uninstall_extension(self.pkg_names['extension']) is True
     path = pjoin(self.app_dir, 'extensions', '*.tgz')
     assert not glob.glob(path)
     extensions = get_app_info()['extensions']
     assert name not in extensions
     assert not check_extension(name)
 def test_uninstall_all_extensions(self):
     install_extension(self.mock_extension)
     install_extension(self.mock_mimeextension)
     ext_name = self.pkg_names['extension']
     mime_ext_name = self.pkg_names['mimeextension']
     assert check_extension(ext_name) is True
     assert check_extension(mime_ext_name) is True
     assert uninstall_extension(all_=True) is True
     extensions = get_app_info()['extensions']
     assert ext_name not in extensions
     assert mime_ext_name not in extensions
 def test_link_package(self):
     path = self.mock_package
     name = self.pkg_names['package']
     assert link_package(path) is True
     linked = get_app_info()['linked_packages']
     assert name in linked
     assert name not in get_app_info()['extensions']
     assert check_extension(name)
     assert unlink_package(path)
     linked = get_app_info()['linked_packages']
     assert name not in linked
     assert not check_extension(name)
    def test_validation(self):
        path = self.mock_extension
        os.remove(pjoin(path, 'index.js'))
        with pytest.raises(ValueError):
            install_extension(path)
        assert not check_extension(self.pkg_names["extension"])

        path = self.mock_mimeextension
        os.remove(pjoin(path, 'index.js'))
        with pytest.raises(ValueError):
            install_extension(path)
        assert not check_extension(self.pkg_names["mimeextension"])
示例#10
0
 def test_enable_extension(self):
     options = AppOptions(app_dir=self.tempdir())
     assert install_extension(self.mock_extension, app_options=options) is True
     assert disable_extension(self.pkg_names['extension'], app_options=options) is True
     assert enable_extension(self.pkg_names['extension'], app_options=options) is True
     info = get_app_info(app_options=options)
     assert '@jupyterlab/notebook-extension' not in info['disabled']
     name = self.pkg_names['extension']
     assert info['disabled'].get(name, False) is False
     assert check_extension(name, app_options=options)
     assert disable_extension('@jupyterlab/notebook-extension', app_options=options) is True
     assert check_extension(name, app_options=options)
     assert not check_extension('@jupyterlab/notebook-extension', app_options=options)
示例#11
0
 def test_link_package(self):
     path = self.mock_package
     name = self.pkg_names['package']
     link_package(path)
     app_dir = self.app_dir
     linked = get_app_info(app_dir)['linked_packages']
     assert name in linked
     assert name not in get_app_info(app_dir)['extensions']
     assert check_extension(name)
     unlink_package(path)
     linked = get_app_info(app_dir)['linked_packages']
     assert name not in linked
     assert not check_extension(name)
示例#12
0
 def test_link_extension(self):
     path = self.mock_extension
     name = self.pkg_names["extension"]
     link_package(path)
     linked = get_app_info()["linked_packages"]
     assert name not in linked
     assert name in get_app_info()["extensions"]
     assert check_extension(name)
     assert unlink_package(path) is True
     linked = get_app_info()["linked_packages"]
     assert name not in linked
     assert name not in get_app_info()["extensions"]
     assert not check_extension(name)
示例#13
0
 def test_enable_extension(self):
     app_dir = self.tempdir()
     assert install_extension(self.mock_extension, app_dir) is True
     assert disable_extension(self.pkg_names['extension'], app_dir) is True
     assert enable_extension(self.pkg_names['extension'], app_dir) is True
     info = get_app_info(app_dir)
     name = self.pkg_names['extension']
     assert name not in info['disabled']
     assert check_extension(name, app_dir)
     assert disable_extension('@jupyterlab/notebook-extension', app_dir) is True
     assert name not in info['disabled']
     assert check_extension(name, app_dir)
     assert '@jupyterlab/notebook-extension' not in info['disabled']
     assert not check_extension('@jupyterlab/notebook-extension', app_dir)
    def test_uninstall_core_extension(self):
        assert uninstall_extension('@jupyterlab/console-extension') is True
        app_dir = self.app_dir
        build()
        with open(pjoin(app_dir, 'staging', 'package.json')) as fid:
            data = json.load(fid)
        extensions = data['jupyterlab']['extensions']
        assert '@jupyterlab/console-extension' not in extensions
        assert not check_extension('@jupyterlab/console-extension')

        assert install_extension('@jupyterlab/console-extension') is True
        build()
        with open(pjoin(app_dir, 'staging', 'package.json')) as fid:
            data = json.load(fid)
        extensions = data['jupyterlab']['extensions']
        assert '@jupyterlab/console-extension' in extensions
        assert check_extension('@jupyterlab/console-extension')
示例#15
0
    def test_uninstall_core_extension(self):
        assert uninstall_extension("@jupyterlab/console-extension") is True
        app_dir = self.app_dir
        build()
        with open(pjoin(app_dir, "staging", "package.json")) as fid:
            data = json.load(fid)
        extensions = data["jupyterlab"]["extensions"]
        assert "@jupyterlab/console-extension" not in extensions
        assert not check_extension("@jupyterlab/console-extension")

        assert install_extension("@jupyterlab/console-extension") is True
        build()
        with open(pjoin(app_dir, "staging", "package.json")) as fid:
            data = json.load(fid)
        extensions = data["jupyterlab"]["extensions"]
        assert "@jupyterlab/console-extension" in extensions
        assert check_extension("@jupyterlab/console-extension")
示例#16
0
 def test_install_extension(self):
     install_extension(self.mock_extension)
     path = pjoin(self.app_dir, 'extensions', '*.tgz')
     assert glob.glob(path)
     extensions = get_app_info(self.app_dir)['extensions']
     name = self.pkg_names['extension']
     assert name in extensions
     assert check_extension(name)
 def test_unlink_package(self):
     target = self.mock_package
     assert link_package(target) is True
     assert unlink_package(target) is True
     linked = get_app_info()['linked_packages']
     name = self.pkg_names['package']
     assert name not in linked
     assert not check_extension(name)
示例#18
0
 def test_install_twice(self):
     assert install_extension(self.mock_extension) is True
     path = pjoin(commands.get_app_dir(), 'extensions', '*.tgz')
     assert install_extension(self.mock_extension) is True
     assert glob.glob(path)
     extensions = get_app_info(self.app_dir)['extensions']
     name = self.pkg_names['extension']
     assert name in extensions
     assert check_extension(name)
 def test_install_failed(self):
     path = self.mock_package
     with pytest.raises(ValueError):
         install_extension(path)
     with open(pjoin(path, 'package.json')) as fid:
         data = json.load(fid)
     extensions = get_app_info()['extensions']
     name = data['name']
     assert name not in extensions
     assert not check_extension(name)
示例#20
0
    def test_app_dir_use_sys_prefix(self):
        app_dir = self.tempdir()
        if os.path.exists(self.app_dir):
            os.removedirs(self.app_dir)

        assert install_extension(self.mock_extension) is True
        path = pjoin(app_dir, 'extensions', '*.tgz')
        assert not glob.glob(path)
        extensions = get_app_info(app_dir)['extensions']
        ext_name = self.pkg_names['extension']
        assert ext_name in extensions
        assert check_extension(ext_name, app_dir)
示例#21
0
    def test_app_dir_disable_sys_prefix(self):
        app_dir = self.tempdir()
        options = AppOptions(app_dir=app_dir, use_sys_dir=False)
        if os.path.exists(self.app_dir):
            os.removedirs(self.app_dir)

        assert install_extension(self.mock_extension) is True
        path = pjoin(app_dir, "extensions", "*.tgz")
        assert not glob.glob(path)
        extensions = get_app_info(app_options=options)["extensions"]
        ext_name = self.pkg_names["extension"]
        assert ext_name not in extensions
        assert not check_extension(ext_name, app_options=options)
示例#22
0
    def test_app_dir_shadowing(self):
        app_dir = self.tempdir()
        sys_dir = self.app_dir
        app_options = AppOptions(app_dir=app_dir)
        if os.path.exists(sys_dir):
            os.removedirs(sys_dir)

        assert install_extension(self.mock_extension) is True
        sys_path = pjoin(sys_dir, "extensions", "*.tgz")
        assert glob.glob(sys_path)
        app_path = pjoin(app_dir, "extensions", "*.tgz")
        assert not glob.glob(app_path)
        extensions = get_app_info(app_options=app_options)["extensions"]
        ext_name = self.pkg_names["extension"]
        assert ext_name in extensions
        assert check_extension(ext_name, app_options=app_options)

        assert install_extension(self.mock_extension,
                                 app_options=app_options) is True
        assert glob.glob(app_path)
        extensions = get_app_info(app_options=app_options)["extensions"]
        assert ext_name in extensions
        assert check_extension(ext_name, app_options=app_options)

        assert uninstall_extension(self.pkg_names["extension"],
                                   app_options=app_options) is True
        assert not glob.glob(app_path)
        assert glob.glob(sys_path)
        extensions = get_app_info(app_options=app_options)["extensions"]
        assert ext_name in extensions
        assert check_extension(ext_name, app_options=app_options)

        assert uninstall_extension(self.pkg_names["extension"],
                                   app_options=app_options) is True
        assert not glob.glob(app_path)
        assert not glob.glob(sys_path)
        extensions = get_app_info(app_options=app_options)["extensions"]
        assert ext_name not in extensions
        assert not check_extension(ext_name, app_options=app_options)
    def test_install_and_uninstall_pinned(self):
        """
        You should be able to install different versions of the same extension with different
        pinned names and uninstall them with those names.
        """
        NAMES = ['test-1', 'test-2']
        assert install_extension(self.pinned_packages[0], pin=NAMES[0])
        assert install_extension(self.pinned_packages[1], pin=NAMES[1])

        extensions = get_app_info()['extensions']
        assert NAMES[0] in extensions
        assert NAMES[1] in extensions
        assert check_extension(NAMES[0])
        assert check_extension(NAMES[1])

        # Uninstall
        assert uninstall_extension(NAMES[0])
        assert uninstall_extension(NAMES[1])

        extensions = get_app_info()['extensions']
        assert NAMES[0] not in extensions
        assert NAMES[1] not in extensions
        assert not check_extension(NAMES[0])
        assert not check_extension(NAMES[1])
示例#24
0
 def test_disable_extension(self):
     options = AppOptions(app_dir=self.tempdir())
     assert install_extension(self.mock_extension,
                              app_options=options) is True
     assert disable_extension(self.pkg_names["extension"],
                              app_options=options) is True
     info = get_app_info(app_options=options)
     name = self.pkg_names["extension"]
     assert info["disabled"].get(name) is True
     assert not check_extension(name, app_options=options)
     assert check_extension(name, installed=True, app_options=options)
     assert disable_extension("@jupyterlab/notebook-extension",
                              app_options=options) is True
     info = get_app_info(app_options=options)
     assert info["disabled"].get("@jupyterlab/notebook-extension") is True
     assert not check_extension("@jupyterlab/notebook-extension",
                                app_options=options)
     assert check_extension("@jupyterlab/notebook-extension",
                            installed=True,
                            app_options=options)
     assert info["disabled"].get(name) is True
     assert not check_extension(name, app_options=options)
     assert check_extension(name, installed=True, app_options=options)
示例#25
0
]


try:
    from jupyterlab.commands import check_extension, AppOptions
    from jupyterlab_server.config import get_federated_extensions
except ImportError:
    print(FIX_PREFIX, 'Please install jupyterlab before checking extensions.')
else:
    missing_extensions = []

    # Fetch federated extensions
    federated_extensions = get_federated_extensions([sys.base_prefix + '/share/jupyter/labextensions']).keys()

    # JupyterLab be quiet
    logger = logging.Logger('quiet')
    logger.setLevel(logging.CRITICAL)
    app_options = AppOptions(logger=logger)

    for extension in lab_extensions:
        if not check_extension(extension, app_options=app_options) and extension not in federated_extensions:
            missing_extensions.append(extension)

    if missing_extensions:
        print(FIX_PREFIX, 'These lab extensions are missing: ',
              ', '.join(missing_extensions))
        print(FIX_PREFIX,' Please try to install the following packages with conda or pip: ',
              ', '.join(missing_extensions))
    else:
        print(f'\t{SUCCESS_PREFIX} All extensions are installed!')
示例#26
0
    "ipysheet",
    "ipytree",
    "ipycanvas",
    "jupyter-matplotlib",
    "jupyter-vuetify",
]

try:
    from jupyterlab.commands import check_extension
except ImportError:
    print(FIX_PREFIX, "Please install jupyterlab before checking extensions.")
else:
    missing_extensions = []

    for extension in lab_extensions:
        if not check_extension(extension):
            missing_extensions.append(extension)

    if missing_extensions:
        print(
            FIX_PREFIX,
            "These lab extensions are missing: ",
            ", ".join(missing_extensions),
        )
        print(
            FIX_PREFIX,
            " Run this to install them: jupyter labextension install ",
            " ".join(missing_extensions),
        )
    else:
        print("\tAll extensions are installed!")
 def test_install_incompatible(self):
     with pytest.raises(ValueError) as excinfo:
         install_extension(self.mock_incompat)
     assert 'Conflicting Dependencies' in str(excinfo.value)
     assert not check_extension(self.pkg_names["incompat"])