def _pip_uninstall_plugin(plugin_name: str) -> None: uninstalled = ( disthelpers.pip( "uninstall", "-y", f"{PLUGIN_PREFIX}{plugin_name}" ).returncode == 0 ) if not uninstalled: raise plug.PlugError(f"could not uninstall {plugin_name}")
def _install_plugin_from_url_nocheck( install_url: str, ) -> subprocess.CompletedProcess: return disthelpers.pip( "install", install_url, f"repobee=={__version__}", # force RepoBee to stay the same version upgrade=True, )
def get_pkg_version(pkg_name: str) -> Optional[str]: """Get the version of this package from the distribution environment.""" pip_proc = disthelpers.pip("list", format="json") installed_packages = { pkg_info["name"]: pkg_info for pkg_info in json.loads( pip_proc.stdout.decode(sys.getdefaultencoding())) } return (installed_packages[pkg_name]["version"] if pkg_name in installed_packages else None)
def _install_plugin(name: str, version: str, plugins: dict) -> None: install_url = f"git+{plugins[name]['url']}@{version}" install_proc = disthelpers.pip( "install", install_url, f"repobee=={__version__}", # force RepoBee to stay the same version upgrade=True, ) if install_proc.returncode != 0: raise plug.PlugError(f"could not install {name} {version}")
def _install_local_plugin(plugin_path: pathlib.Path, installed_plugins: dict): install_info: Dict[str, Any] = dict(version="local", path=str(plugin_path)) if plugin_path.is_dir(): _check_has_plugin_prefix(plugin_path.name) disthelpers.pip( "install", "-e", str(plugin_path), f"repobee=={__version__}", upgrade=True, ) ident = plugin_path.name[len(PLUGIN_PREFIX) :] else: ident = str(plugin_path) install_info["single_file"] = True installed_plugins[ident] = install_info disthelpers.write_installed_plugins(installed_plugins) plug.echo(f"Installed {ident}")
def _install_local_plugin(plugin_path: pathlib.Path, installed_plugins: dict): install_info: Dict[str, Any] = dict(version="local", path=str(plugin_path)) if plugin_path.is_dir(): if not plugin_path.name.startswith("repobee-"): raise plug.PlugError( "RepoBee plugin package names must be prefixed with " "'repobee-'") disthelpers.pip( "install", "-e", str(plugin_path), f"repobee=={__version__}", upgrade=True, ) ident = plugin_path.name[len("repobee-"):] else: ident = str(plugin_path) install_info["single_file"] = True installed_plugins[ident] = install_info disthelpers.write_installed_plugins(installed_plugins) plug.echo(f"Installed {ident}")
def command(self) -> None: """Upgrade RepoBee to the latest version.""" plug.echo(f"Upgrading RepoBee from v{_installed_version()}...") repobee_requirement = f"repobee{self.version_spec or ''}" upgrade = disthelpers.pip( "install", repobee_requirement, upgrade=True, no_cache=True, force_reinstall=True, ) if upgrade.returncode != 0: raise plug.PlugError("failed to upgrade RepoBee") plug.echo(f"RepoBee succesfully upgraded to v{_installed_version()}!")
def _installed_version(package: str = "repobee") -> str: return next(entry for entry in json.loads( disthelpers.pip("list", format="json").stdout.decode( sys.getdefaultencoding())) if entry["name"] == package)["version"]