Exemple #1
0
    def toggle_server_extension(self, import_name):
        """Change the status of a named server extension.

        Uses the value of `self._toggle_value`.

        Parameters
        ---------

        import_name : str
            Importable Python module (dotted-notation) exposing the magic-named
            `load_jupyter_server_extension` function
        """
        # Create an extension manager for this instance.
        config_dir, extension_manager = _get_extmanager_for_context(
            user=self.user, sys_prefix=self.sys_prefix)
        try:
            self.log.info("{}: {}".format(
                self._toggle_pre_message.capitalize(), import_name))
            self.log.info("- Writing config: {}".format(config_dir))
            # Validate the server extension.
            self.log.info("    - Validating {}...".format(import_name))
            # Interface with the Extension Package and validate.
            extpkg = ExtensionPackage(name=import_name)
            extpkg.validate()
            version = extpkg.version
            self.log.info("      {} {} {}".format(import_name, version,
                                                  GREEN_OK))

            # Toggle extension config.
            config = extension_manager.config_manager
            if self._toggle_value is True:
                config.enable(import_name)
            else:
                config.disable(import_name)

            # If successful, let's log.
            self.log.info("    - Extension successfully {}.".format(
                self._toggle_post_message))
        except Exception as err:
            self.log.info("     {} Validation failed: {}".format(RED_X, err))
def test_extension_package_api():
    # Import mock extension metadata
    from .mockextensions import _jupyter_server_extension_points

    # Testing the first path (which is an extension app).
    metadata_list = _jupyter_server_extension_points()
    path1 = metadata_list[0]
    app = path1["app"]

    e = ExtensionPackage(name='jupyter_server.tests.extension.mockextensions')
    e.extension_points
    assert hasattr(e, "extension_points")
    assert len(e.extension_points) == len(metadata_list)
    assert app.name in e.extension_points
    assert e.validate()