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)
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)
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)
def _initialize_non_default_plugins(plugin_names: List[str]) -> None: if distinfo.DIST_INSTALL: plug.log.debug("Initializing active plugins") plugin.initialize_plugins(disthelpers.get_active_plugins(), allow_filepath=True) plug.log.debug("Initializing preparser-specified plugins") plugin.initialize_plugins(plugin_names, allow_filepath=True)
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)
def test_non_interactive_activate_of_builtin_plugin(self, install_dir): plugin_name = "ghclassroom" cmd = [ *pluginmanager.plugin_category.activate.as_name_tuple(), "--plugin-name", plugin_name, ] repobee.run(cmd) assert plugin_name in disthelpers.get_active_plugins( install_dir / "installed_plugins.json")
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
def _uninstall_plugin(plugin_name: str, installed_plugins: dict): plugin_version = installed_plugins[plugin_name]["version"] plug.echo(f"Uninstalling {plugin_name}@{plugin_version}") if not installed_plugins[plugin_name].get("single_file"): _pip_uninstall_plugin(plugin_name) del installed_plugins[plugin_name] disthelpers.write_installed_plugins(installed_plugins) disthelpers.write_active_plugins([ name for name in disthelpers.get_active_plugins() if name != plugin_name ]) plug.echo(f"Successfully uninstalled {plugin_name}")
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)
def _initialize_plugins(parsed_preparser_args: argparse.Namespace) -> None: # IMPORTANT: the default plugins must be loaded before user-defined # plugins to ensure that the user-defined plugins override the defaults # in firstresult hooks plug.log.debug("Initializing default plugins") plugin.initialize_default_plugins() if distinfo.DIST_INSTALL: plug.log.debug("Initializing dist plugins") plugin.initialize_dist_plugins() if not parsed_preparser_args.no_plugins: if distinfo.DIST_INSTALL: plug.log.debug("Initializing active plugins") plugin.initialize_plugins(disthelpers.get_active_plugins(), allow_filepath=True) plug.log.debug("Initializing preparser-specified plugins") plugin_names = parsed_preparser_args.plug or [] plugin.initialize_plugins(plugin_names, allow_filepath=True)