From f230fa79bbb636ee25921d7fa22c366232acb08b Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Wed, 23 Aug 2023 11:51:53 +0200 Subject: [PATCH] `to_pkg_install_commands` should skip already installed sys packages. --- platypush/utils/manifest.py | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/platypush/utils/manifest.py b/platypush/utils/manifest.py index 1c14316542..b6c5a7f7fb 100644 --- a/platypush/utils/manifest.py +++ b/platypush/utils/manifest.py @@ -353,22 +353,28 @@ class Dependencies: wants_sudo = not (self._is_docker or os.getuid() == 0) pkg_manager = self.pkg_manager or PackageManagers.scan() + if self.packages and pkg_manager: - yield ' '.join( - [ - *(['sudo'] if wants_sudo else []), - *pkg_manager.value.install, - *sorted( - pkg - for pkg in self.packages # type: ignore - if not ( - self.install_context == InstallContext.VENV - and self._is_python_pkg(pkg) - ) - ), - ] + installed_packages = pkg_manager.value.get_installed() + to_install = sorted( + pkg + for pkg in self.packages # type: ignore + if pkg not in installed_packages + and not ( + self.install_context == InstallContext.VENV + and self._is_python_pkg(pkg) + ) ) + if to_install: + yield ' '.join( + [ + *(['sudo'] if wants_sudo else []), + *pkg_manager.value.install, + *to_install, + ] + ) + def to_pip_install_commands(self, full_command=True) -> Generator[str, None, None]: """ Generates the pip commands required to install the given dependencies on