From 0245adf717f50c00f0656e4788fc033678479cbe Mon Sep 17 00:00:00 2001 From: Romeo Kienzler Date: Wed, 26 Jun 2024 16:42:20 +0200 Subject: [PATCH] finish c3 containerless operator generation --- src/c3/create_containerless_operator.py | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/c3/create_containerless_operator.py b/src/c3/create_containerless_operator.py index 4135f84..b72f48d 100644 --- a/src/c3/create_containerless_operator.py +++ b/src/c3/create_containerless_operator.py @@ -6,11 +6,12 @@ import re from c3.create_operator import create_cwl_component from c3.pythonscript import Pythonscript - +from c3.templates import component_setup_code_wo_logging, python_component_setup_code def create_containerless_operator( file_path, version, + skip_logging = False ): if version is None: @@ -32,13 +33,29 @@ def create_containerless_operator( all_pip_packages_found += (f' {pip_packages}') logging.info(f'all PIP packages found: {all_pip_packages_found}') + + # prepend init code to script + target_code = 'runnable.py' + + if os.path.exists(target_code): + os.remove(target_code) + + with open(file_path, 'r') as f: + script = f.read() + if skip_logging: + script = component_setup_code_wo_logging + script + else: + script = python_component_setup_code + script + with open(target_code, 'w') as f: + f.write(script) + subprocess.run(';'.join(['rm -Rf claimedenv','python -m venv claimedenv', 'source ./claimedenv/bin/activate', f'pip install {all_pip_packages_found.strip()}', 'pip list', - f'zip -r claimed-{filename}:{version}.zip {file_path} claimedenv', - 'rm -Rf claimedenv']), shell=True) - + f'zip -r claimed-{filename}:{version}.zip {target_code} claimedenv', + 'rm -Rf claimedenv', + f'rm {target_code}']), shell=True) script_data = Pythonscript(file_path) inputs = script_data.get_inputs() outputs = script_data.get_outputs()