示例#1
0
    def command(self) -> None:
        """Uninstall a plugin."""
        installed_plugins = {
            name: attrs
            for name, attrs in disthelpers.get_installed_plugins().items()
            if not attrs.get("builtin")
        }

        if self.plugin_name:
            # non-interactive uninstall
            if self.plugin_name not in installed_plugins:
                raise plug.PlugError(
                    f"no plugin '{self.plugin_name}' installed"
                )
            selected_plugin_name = self.plugin_name
        else:
            # interactive uninstall
            if not installed_plugins:
                plug.echo("No plugins installed")
                return

            plug.echo("Installed plugins:")
            _list_installed_plugins(
                installed_plugins, disthelpers.get_active_plugins()
            )

            selected_plugin_name = bullet.Bullet(
                prompt="Select a plugin to uninstall:",
                choices=list(installed_plugins.keys()),
            ).launch()

        _uninstall_plugin(selected_plugin_name, installed_plugins)
示例#2
0
    def command(self) -> None:
        """Activate a plugin."""
        installed_plugins = disthelpers.get_installed_plugins()
        active = disthelpers.get_active_plugins()

        names = list(installed_plugins.keys()) + list(
            disthelpers.get_builtin_plugins().keys()
        )

        if self.plugin_name:
            # non-interactive activate
            if self.plugin_name not in names:
                raise plug.PlugError(
                    f"no plugin named '{self.plugin_name}' installed"
                )
            selection = (
                active + [self.plugin_name]
                if self.plugin_name not in active
                else list(set(active) - {self.plugin_name})
            )
        else:
            # interactive activate
            default = [i for i, name in enumerate(names) if name in active]
            selection = bullet.Check(
                choices=names,
                prompt="Select plugins to activate (space to check/un-check, "
                "enter to confirm selection):",
            ).launch(default=default)

        disthelpers.write_active_plugins(selection)

        self._echo_state_change(active_before=active, active_after=selection)
示例#3
0
    def command(self) -> None:
        """Install a plugin."""
        plugins = disthelpers.get_plugins_json()
        installed_plugins = disthelpers.get_installed_plugins()
        active_plugins = disthelpers.get_active_plugins()

        if self.local:
            abspath = self.local.absolute()
            if not abspath.exists():
                raise plug.PlugError(f"no such file or directory: '{abspath}'")

            _install_local_plugin(abspath, installed_plugins)
        else:
            plug.echo("Available plugins:")
            _list_all_plugins(plugins, installed_plugins, active_plugins)
            name, version = _select_plugin(plugins)

            if name in installed_plugins:
                _uninstall_plugin(name, installed_plugins)

            plug.echo(f"Installing {name}@{version}")
            _install_plugin(name, version, plugins)

            plug.echo(f"Successfully installed {name}@{version}")

            installed_plugins[name] = dict(version=version)
            disthelpers.write_installed_plugins(installed_plugins)
示例#4
0
    def test_install_junit4_plugin_from_remote_git_repository(self):
        url = "https://github.com/repobee/repobee-junit4.git"

        repobee.run(f"plugin install --git-url {url}".split())

        install_info = disthelpers.get_installed_plugins()["junit4"]
        assert install_info["version"] == url
        assert get_pkg_version("repobee-junit4")
示例#5
0
    def test_install_specific_version_from_remote_git_repository(self):
        url = "https://github.com/repobee/repobee-junit4.git"
        version = "v1.0.0"

        repobee.run(f"plugin install --git-url {url}@{version}".split())

        install_info = disthelpers.get_installed_plugins()["junit4"]
        assert install_info["version"] == f"{url}@{version}"
        assert get_pkg_version("repobee-junit4") == version.lstrip("v")
示例#6
0
    def command(self) -> None:
        """List available plugins."""
        plugins = disthelpers.get_plugins_json()
        plugins.update(disthelpers.get_builtin_plugins())
        installed_plugins = disthelpers.get_installed_plugins()
        active_plugins = disthelpers.get_active_plugins()

        if not self.plugin_name:
            _list_all_plugins(plugins, installed_plugins, active_plugins)
        else:
            _list_plugin(self.plugin_name, plugins)
示例#7
0
    def command(self) -> None:
        """Install a plugin."""
        plugins = disthelpers.get_plugins_json()
        installed_plugins = disthelpers.get_installed_plugins()
        active_plugins = disthelpers.get_active_plugins()

        try:
            self._install_plugin(plugins, installed_plugins, active_plugins)
        except disthelpers.DependencyResolutionError as exc:
            raise disthelpers.DependencyResolutionError(
                f"Selected plugin is incompatible with RepoBee {__version__}. "
                "Try upgrading RepoBee and then install the plugin again."
            ) from exc
示例#8
0
    def test_install_local_plugin_package(self, tmp_path):
        plugin_version = "1.0.0"

        junit4_local = tmp_path / "repobee-junit4"
        repo = git.Repo.clone_from("https://github.com/repobee/repobee-junit4",
                                   to_path=junit4_local)
        repo.git.checkout(f"v{plugin_version}")

        repobee.run(shlex.split(f"plugin install --local {junit4_local}"))

        install_info = disthelpers.get_installed_plugins()["junit4"]
        assert install_info["version"] == "local"
        assert install_info["path"] == str(junit4_local)
        assert get_pkg_version("repobee-junit4") == plugin_version
示例#9
0
    def command(self) -> None:
        """Activate a plugin."""
        installed_plugins = disthelpers.get_installed_plugins()
        active = disthelpers.get_active_plugins()

        names = list(installed_plugins.keys()) + list(
            disthelpers.get_builtin_plugins().keys())

        default = [i for i, name in enumerate(names) if name in active]
        selection = bullet.Check(
            choices=names,
            prompt="Select plugins to activate (space to check/un-check, "
            "enter to confirm selection):",
        ).launch(default=default)

        disthelpers.write_active_plugins(selection)
示例#10
0
    def test_install_local_plugin_package(self):
        plugin_version = "1.0.0"

        with tempfile.TemporaryDirectory() as tmpdir:
            workdir = pathlib.Path(tmpdir)
            junit4_local = workdir / "repobee-junit4"
            repo = git.Repo.clone_from(
                "https://github.com/repobee/repobee-junit4",
                to_path=junit4_local,
            )
            repo.git.checkout(f"v{plugin_version}")

            repobee.run(shlex.split(f"plugin install --local {junit4_local}"))

            install_info = disthelpers.get_installed_plugins()["junit4"]
            assert install_info["version"] == "local"
            assert install_info["path"] == str(junit4_local)
            assert get_pkg_version("repobee-junit4") == plugin_version
示例#11
0
    def test_install_local_plugin_file(self, capsys, tmp_path):
        plugin_content = """
import repobee_plug as plug
class Hello(plug.Plugin, plug.cli.Command):
    def command(self):
        return plug.Result(
            name='hello',
            status=plug.Status.SUCCESS,
            msg='Best message'
        )
"""
        hello_py = tmp_path / "hello.py"
        hello_py.write_text(plugin_content, encoding="utf8")

        repobee.run(shlex.split(f"plugin install --local {hello_py}"))

        install_info = disthelpers.get_installed_plugins()[str(hello_py)]
        assert install_info["version"] == "local"
        assert install_info["path"] == str(hello_py)