From 03b4f1fb8136f12f9f7c80ee6dff771384916b7e Mon Sep 17 00:00:00 2001 From: Alexis de Talhouët Date: Fri, 19 Apr 2019 09:31:54 -0400 Subject: Add support for requirements.txt for pip deps MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I10bbe95a4d06ce9361d3ab6553953022e1196a3d Issue-ID: CCCSDK-125 Signed-off-by: Alexis de Talhouët --- .../src/main/python/command_executor_handler.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'ms') diff --git a/ms/command-executor/src/main/python/command_executor_handler.py b/ms/command-executor/src/main/python/command_executor_handler.py index 9eb36fb2d..1fb3e2679 100644 --- a/ms/command-executor/src/main/python/command_executor_handler.py +++ b/ms/command-executor/src/main/python/command_executor_handler.py @@ -24,6 +24,8 @@ import venv import utils import proto.CommandExecutor_pb2 as CommandExecutor_pb2 +REQUIREMENTS_TXT = "requirements.txt" + class CommandExecutorHandler(): @@ -80,12 +82,12 @@ class CommandExecutorHandler(): for package in request.packages: if package.type == type: f.write("Installed %s packages:\r\n" % CommandExecutor_pb2.PackageType.Name(type)) - for python_package in package.package: - f.write(" %s\r\n" % python_package) + for p in package.package: + f.write(" %s\r\n" % p) if package.type == CommandExecutor_pb2.pip: - success = self.install_python_packages(python_package, results) + success = self.install_python_packages(p, results) else: - success = self.install_ansible_packages(python_package, results) + success = self.install_ansible_packages(p, results) if not success: f.close() os.remove(self.installed) @@ -95,7 +97,11 @@ class CommandExecutorHandler(): def install_python_packages(self, package, results): self.logger.info( "{} - Install Python package({}) in Python Virtual Environment".format(self.blueprint_id, package)) - command = ["pip", "install", package] + + if REQUIREMENTS_TXT == package: + command = ["pip", "install", "-r", self.venv_home + "/Environments/" + REQUIREMENTS_TXT] + else: + command = ["pip", "install", package] env = dict(os.environ) if "https_proxy" in os.environ: -- cgit 1.2.3-korg