From 8b5871af0ed26c1d74346fc87641f41b0f866691 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Sun, 22 Oct 2023 01:41:19 +0200 Subject: [PATCH] [Fix] `platyvenv` should also execute the `before` and `after` blocks. Before this fix, `platyvenv`, unlike `platydock`, didn't take into account any extra before/after installation commands that individual integrations may instruct to run in their manifest files. --- platypush/platyvenv/__init__.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/platypush/platyvenv/__init__.py b/platypush/platyvenv/__init__.py index 3e1aa83f4..84d88879e 100755 --- a/platypush/platyvenv/__init__.py +++ b/platypush/platyvenv/__init__.py @@ -6,7 +6,6 @@ virtual environment for Platypush starting from a configuration file. from contextlib import contextmanager import logging import os -import re import shutil import subprocess import sys @@ -63,7 +62,23 @@ class VenvBuilder(BaseBuilder): """ for cmd in deps.to_pkg_install_commands(): logger.info('Installing system packages: %s', cmd) - subprocess.call(re.split(r'\s+', cmd.strip())) + subprocess.run(cmd, shell=True, check=True) + + def _run_before_commands(self, deps: Dependencies): + """ + Runs any commands that should be executed before the installation. + """ + for cmd in deps.before: + logger.info('Running: %s', cmd) + subprocess.run(cmd, shell=True, check=True) + + def _run_after_commands(self, deps: Dependencies): + """ + Runs any commands that should be executed after the installation. + """ + for cmd in deps.after: + logger.info('Running: %s', cmd) + subprocess.run(cmd, shell=True, check=True) @contextmanager def _prepare_src_dir(self) -> Generator[str, None, None]: @@ -146,12 +161,15 @@ class VenvBuilder(BaseBuilder): install_context=InstallContext.VENV, ) + self._run_before_commands(deps) self._install_system_packages(deps) with self._prepare_src_dir(): self._prepare_venv() self._install_extra_pip_packages(deps) + self._run_after_commands(deps) + self._print_instructions( textwrap.dedent( f"""