Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

finish c3 containerless operator generation #66

Merged
merged 1 commit into from
Jun 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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