Skip to content

Commit

Permalink
Merge pull request #66 from romeokienzler/main
Browse files Browse the repository at this point in the history
finish  c3 containerless operator generation
  • Loading branch information
romeokienzler authored Jun 26, 2024
2 parents ddc26d5 + 0245adf commit bd1c19a
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/c3/create_containerless_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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()
Expand Down

0 comments on commit bd1c19a

Please sign in to comment.