Skip to content

Commit 1345511

Browse files
author
Andrei Neagu
committed
Revert "use version 1.1.0 of integration interface (#67)"
This reverts commit 3b2839e.
1 parent e638535 commit 1345511

30 files changed

+179
-196
lines changed

.cookiecutterrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ default_context:
3535
project_slug: 'osparc-python-runner'
3636
project_type: 'computational'
3737
release_date: '2020'
38-
version: '2.0.0'
38+
version: '1.3.0'

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.0.0
1+
1.3.0

VERSION_INTEGRATION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.1.0
1+
1.0.0

docker-compose-meta.yml

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,24 @@ services:
1717
input data file", "type": "data:*/*"}, "input_5": {"displayOrder": 5, "label":
1818
"Additional input data - optional", "description": "Any additional input
1919
data file", "type": "data:*/*"}}}'
20-
io.simcore.integration-version: '{"integration-version": "1.1.0"}'
20+
io.simcore.integration-version: '{"integration-version": "1.0.0"}'
2121
io.simcore.key: '{"key": "simcore/services/comp/osparc-python-runner"}'
2222
io.simcore.name: '{"name": "oSparc Python Runner"}'
2323
io.simcore.outputs: '{"outputs": {"output_1": {"displayOrder": 1, "label":
2424
"Output data", "description": "The data produced by the script and saved
25-
under OUTPUT_FOLDER/output_1 as output_1.zip", "type": "data:*/*"}, "output_2":
26-
{"displayOrder": 2, "label": "Output data", "description": "The data produced
27-
by the script and saved under OUTPUT_FOLDER/output_2 as output_2.zip", "type":
28-
"data:*/*"}, "output_3": {"displayOrder": 3, "label": "Output data", "description":
29-
"The data produced by the script and saved under OUTPUT_FOLDER/output_3
30-
as output_3.zip", "type": "data:*/*"}, "output_4": {"displayOrder": 4, "label":
25+
under OUTPUT_FOLDER/output_1 as output_1.zip", "type": "data:*/*", "fileToKeyMap":
26+
{"output_1.zip": "output_1"}}, "output_2": {"displayOrder": 2, "label":
3127
"Output data", "description": "The data produced by the script and saved
32-
under OUTPUT_FOLDER/output_4 as output_4.zip", "type": "data:*/*"}}}'
28+
under OUTPUT_FOLDER/output_2 as output_2.zip", "type": "data:*/*", "fileToKeyMap":
29+
{"output_2.zip": "output_2"}}, "output_3": {"displayOrder": 3, "label":
30+
"Output data", "description": "The data produced by the script and saved
31+
under OUTPUT_FOLDER/output_3 as output_3.zip", "type": "data:*/*", "fileToKeyMap":
32+
{"output_3.zip": "output_3"}}, "output_4": {"displayOrder": 4, "label":
33+
"Output data", "description": "The data produced by the script and saved
34+
under OUTPUT_FOLDER/output_4 as output_4.zip", "type": "data:*/*", "fileToKeyMap":
35+
{"output_4.zip": "output_4"}}}}'
3336
io.simcore.type: '{"type": "computational"}'
34-
io.simcore.version: '{"version": "2.0.0"}'
37+
io.simcore.version: '{"version": "1.3.0"}'
3538
org.label-schema.build-date: ${BUILD_DATE}
3639
org.label-schema.schema-version: '1.0'
3740
org.label-schema.vcs-ref: ${VCS_REF}

metadata/metadata.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
name: oSparc Python Runner
22
key: simcore/services/comp/osparc-python-runner
33
type: computational
4-
integration-version: 1.1.0
5-
version: 2.0.0
4+
integration-version: 1.0.0
5+
version: 1.3.0
66
description: oSparc Python Runner
77
88
authors:
@@ -44,18 +44,26 @@ outputs:
4444
label: Output data
4545
description: The data produced by the script and saved under OUTPUT_FOLDER/output_1 as output_1.zip
4646
type: data:*/*
47+
fileToKeyMap:
48+
output_1.zip: output_1
4749
output_2:
4850
displayOrder: 2
4951
label: Output data
5052
description: The data produced by the script and saved under OUTPUT_FOLDER/output_2 as output_2.zip
5153
type: data:*/*
54+
fileToKeyMap:
55+
output_2.zip: output_2
5256
output_3:
5357
displayOrder: 3
5458
label: Output data
5559
description: The data produced by the script and saved under OUTPUT_FOLDER/output_3 as output_3.zip
5660
type: data:*/*
61+
fileToKeyMap:
62+
output_3.zip: output_3
5763
output_4:
5864
displayOrder: 4
5965
label: Output data
6066
description: The data produced by the script and saved under OUTPUT_FOLDER/output_4 as output_4.zip
6167
type: data:*/*
68+
fileToKeyMap:
69+
output_4.zip: output_4

requirements.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ black
88
coverage
99
docker
1010
jsonschema
11-
pylint
1211
pytest
1312
pytest-cookies
1413
pytest-cov

requirements.txt

Lines changed: 30 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44
#
55
# pip-compile --output-file=requirements.txt
66
#
7-
arrow==1.2.3
7+
arrow==1.2.2
88
# via jinja2-time
9-
astroid==2.15.4
10-
# via pylint
11-
attrs==23.1.0
9+
attrs==21.4.0
1210
# via
1311
# jsonschema
1412
# referencing
@@ -20,48 +18,38 @@ bump2version==1.0.1
2018
# via bumpversion
2119
bumpversion==0.6.0
2220
# via -r requirements.in
23-
certifi==2023.7.22
21+
certifi==2021.10.8
2422
# via requests
25-
chardet==5.0.0
23+
chardet==4.0.0
2624
# via binaryornot
27-
charset-normalizer==2.1.1
25+
charset-normalizer==2.0.12
2826
# via requests
29-
click==8.1.3
27+
click==8.1.0
3028
# via
3129
# black
3230
# cookiecutter
3331
cookiecutter==2.1.1
3432
# via pytest-cookies
35-
coverage[toml]==6.4.4
33+
coverage[toml]==6.3.2
3634
# via
3735
# -r requirements.in
3836
# pytest-cov
39-
dill==0.3.6
40-
# via pylint
41-
docker==6.1.3
37+
docker==6.0.0
4238
# via -r requirements.in
43-
idna==3.4
39+
idna==3.3
4440
# via requests
4541
iniconfig==1.1.1
4642
# via pytest
47-
isort==5.10.1
48-
# via pylint
49-
jinja2==3.1.2
43+
jinja2==3.1.1
5044
# via
5145
# cookiecutter
5246
# jinja2-time
5347
jinja2-time==0.2.0
5448
# via cookiecutter
5549
jsonschema==4.19.0
5650
# via -r requirements.in
57-
jsonschema-specifications==2023.6.1
58-
# via jsonschema
59-
lazy-object-proxy==1.7.1
60-
# via astroid
6151
markupsafe==2.1.1
6252
# via jinja2
63-
mccabe==0.7.0
64-
# via pylint
6553
mypy-extensions==0.4.3
6654
# via black
6755
packaging==23.0
@@ -70,17 +58,19 @@ packaging==23.0
7058
# docker
7159
# pytest
7260
# pytest-sugar
73-
pathspec==0.10.1
61+
pathspec==0.9.0
62+
# via black
63+
platformdirs==2.5.1
7464
# via black
75-
platformdirs==2.5.2
76-
# via
77-
# black
78-
# pylint
7965
pluggy==1.0.0
8066
# via pytest
81-
pylint==2.17.3
82-
# via -r requirements.in
83-
pytest==7.4.0
67+
py==1.11.0
68+
# via pytest
69+
pyparsing==3.0.7
70+
# via packaging
71+
pyrsistent==0.18.1
72+
# via jsonschema
73+
pytest==7.1.3
8474
# via
8575
# -r requirements.in
8676
# pytest-cookies
@@ -100,17 +90,13 @@ pytest-sugar==0.9.7
10090
# via -r requirements.in
10191
python-dateutil==2.8.2
10292
# via arrow
103-
python-slugify==6.1.2
93+
python-slugify==6.1.1
10494
# via cookiecutter
10595
pyyaml==6.0.1
10696
# via
10797
# -r requirements.in
10898
# cookiecutter
109-
referencing==0.29.1
110-
# via
111-
# jsonschema
112-
# jsonschema-specifications
113-
requests==2.31.0
99+
requests==2.27.1
114100
# via
115101
# cookiecutter
116102
# docker
@@ -120,17 +106,18 @@ rpds-py==0.8.10
120106
# referencing
121107
six==1.16.0
122108
# via python-dateutil
123-
termcolor==2.2.0
109+
termcolor==1.1.0
124110
# via pytest-sugar
125111
text-unidecode==1.3
126112
# via python-slugify
127-
tomlkit==0.11.4
128-
# via pylint
129-
urllib3==1.26.12
113+
tomli==2.0.1
114+
# via
115+
# black
116+
# coverage
117+
# pytest
118+
urllib3==1.26.9
130119
# via
131120
# docker
132121
# requests
133-
websocket-client==1.4.1
122+
websocket-client==1.3.2
134123
# via docker
135-
wrapt==1.14.1
136-
# via astroid

service.cli/run

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,6 @@ INPUT_4=$INPUT_FOLDER/input_4
1919
export INPUT_4
2020
INPUT_5=$INPUT_FOLDER/input_5
2121
export INPUT_5
22-
OUTPUT_1=$OUTPUT_FOLDER/output_1
23-
export OUTPUT_1
24-
OUTPUT_2=$OUTPUT_FOLDER/output_2
25-
export OUTPUT_2
26-
OUTPUT_3=$OUTPUT_FOLDER/output_3
27-
export OUTPUT_3
28-
OUTPUT_4=$OUTPUT_FOLDER/output_4
29-
export OUTPUT_4
3022

3123
exec execute.sh
3224

src/osparc_python_runner/main.py

Lines changed: 65 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,28 @@
11
import json
22
import logging
33
import os
4+
import shutil
45
import subprocess
56
import sys
67
from pathlib import Path
8+
from typing import Dict
79

810
logging.basicConfig(level=logging.INFO)
911
logger = logging.getLogger("osparc-python-main")
1012

1113

12-
INPUT_1 = Path(os.environ["INPUT_1"])
14+
ENVIRONS = ["INPUT_FOLDER", "OUTPUT_FOLDER"]
15+
try:
16+
INPUT_FOLDER, OUTPUT_FOLDER = [Path(os.environ[v]) for v in ENVIRONS]
17+
except KeyError:
18+
raise ValueError("Required env vars {ENVIRONS} were not set")
19+
20+
# NOTE: sync with schema in metadata!!
21+
NUM_INPUTS = 5
22+
NUM_OUTPUTS = 4
23+
OUTPUT_SUBFOLDER_ENV_TEMPLATE = "OUTPUT_{}"
24+
OUTPUT_SUBFOLDER_TEMPLATE = "output_{}"
25+
OUTPUT_FILE_TEMPLATE = "output_{}.zip"
1326

1427

1528
def _find_user_code_entrypoint(code_dir: Path) -> Path:
@@ -45,44 +58,59 @@ def _ensure_pip_requirements(code_dir: Path) -> Path:
4558
f"pipreqs --savepath={requirements} --force {code_dir}".split(),
4659
shell=False,
4760
check=True,
48-
cwd=INPUT_1,
61+
cwd=INPUT_FOLDER,
4962
)
5063

5164
# TODO log subprocess.run
5265

5366
else:
5467
requirements = requirements[0]
55-
logger.info("Found: %s", requirements)
68+
logger.info(f"Found: {requirements}")
5669
return requirements
5770

5871

59-
def _show_io_environments() -> None:
60-
for io_type in ["input", "output"]:
61-
logger.info(
62-
"%s ENVs available: %s",
63-
io_type.capitalize(),
64-
json.dumps(
65-
list(
66-
filter(
67-
lambda x, io_type=io_type: f"{io_type.upper()}_" in x,
68-
os.environ,
69-
)
70-
),
71-
indent=2,
72-
),
73-
)
72+
# TODO: Next version of integration will take care of this and maybe the ENVs as well
73+
def _ensure_output_subfolders_exist() -> Dict[str, str]:
74+
output_envs = {}
75+
for n in range(1, NUM_OUTPUTS + 1):
76+
output_sub_folder_env = f"OUTPUT_{n}"
77+
output_sub_folder = OUTPUT_FOLDER / OUTPUT_SUBFOLDER_TEMPLATE.format(n)
78+
# NOTE: exist_ok for forward compatibility in case they are already created
79+
output_sub_folder.mkdir(parents=True, exist_ok=True)
80+
output_envs[output_sub_folder_env] = f"{output_sub_folder}"
81+
logger.info(
82+
"Output ENVs available: %s",
83+
json.dumps(output_envs, indent=2),
84+
)
85+
return output_envs
86+
87+
88+
def _ensure_input_environment() -> Dict[str, str]:
89+
input_envs = {
90+
f"INPUT_{n}": os.environ[f"INPUT_{n}"] for n in range(1, NUM_INPUTS + 1)
91+
}
92+
logger.info(
93+
"Input ENVs available: %s",
94+
json.dumps(input_envs, indent=2),
95+
)
96+
return input_envs
7497

7598

7699
def setup():
77-
_show_io_environments()
100+
input_envs = _ensure_input_environment()
101+
output_envs = _ensure_output_subfolders_exist()
78102
logger.info("Available data:")
79103
os.system("ls -tlah")
80104

81-
user_code_entrypoint = _find_user_code_entrypoint(INPUT_1)
82-
requirements_txt = _ensure_pip_requirements(INPUT_1)
105+
user_code_entrypoint = _find_user_code_entrypoint(INPUT_FOLDER)
106+
requirements_txt = _ensure_pip_requirements(INPUT_FOLDER)
83107

84108
logger.info("Preparing launch script ...")
85109
venv_dir = Path.home() / ".venv"
110+
bash_input_env_export = [f"export {env}={path}" for env, path in input_envs.items()]
111+
bash_output_env_export = [
112+
f"export {env}='{path}'" for env, path in output_envs.items()
113+
]
86114
script = [
87115
"#!/bin/sh",
88116
"set -o errexit",
@@ -92,16 +120,30 @@ def setup():
92120
f'python3 -m venv --system-site-packages --symlinks --upgrade "{venv_dir}"',
93121
f'"{venv_dir}/bin/pip" install -U pip wheel setuptools',
94122
f'"{venv_dir}/bin/pip" install -r "{requirements_txt}"',
123+
"\n".join(bash_input_env_export),
124+
"\n".join(bash_output_env_export),
95125
f'echo "Executing code {user_code_entrypoint.name}..."',
96126
f'"{venv_dir}/bin/python3" "{user_code_entrypoint}"',
97127
'echo "DONE ..."',
98128
]
99129
main_script_path = Path("main.sh")
100-
main_script_path.write_text("\n".join(script), encoding="utf-8")
130+
main_script_path.write_text("\n".join(script))
101131

102132

103133
def teardown():
104-
logger.info("Completed")
134+
logger.info("Zipping output...")
135+
for n in range(1, NUM_OUTPUTS + 1):
136+
output_path = OUTPUT_FOLDER / f"output_{n}"
137+
archive_file_path = OUTPUT_FOLDER / OUTPUT_FILE_TEMPLATE.format(n)
138+
logger.info("Zipping %s into %s...", output_path, archive_file_path)
139+
shutil.make_archive(
140+
f"{(archive_file_path.parent / archive_file_path.stem)}",
141+
format="zip",
142+
root_dir=output_path,
143+
logger=logger,
144+
)
145+
logger.info("Zipping %s into %s done", output_path, archive_file_path)
146+
logger.info("Zipping done.")
105147

106148

107149
if __name__ == "__main__":

0 commit comments

Comments
 (0)