Skip to content

Commit

Permalink
adds python binder
Browse files Browse the repository at this point in the history
  • Loading branch information
pcrespov committed Oct 24, 2022
1 parent 555d92e commit 1e35016
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 36 deletions.
11 changes: 8 additions & 3 deletions hooks/post_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,14 @@ def create_repo_folder():


def check_python():
if "python" not in SELECTED_DOCKER_BASE:
Path(".osparc/osparc_binder_program.py").unlink(missing_ok=True)
Path(".osparc/requirements.txt").unlink(missing_ok=True)
is_pyconfig = "python" in SELECTED_DOCKER_BASE

for fp in Path(".osparc").glob("Python.*"):
if fp.is_file():
if is_pyconfig:
fp.rename( fp.parent / fp.name.removeprefix("Python."))
else:
fp.unlink(missing_ok=True)

# TODO: if python, then service.cli has to be removed!

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@
# typer[all]>=0.6.1,<1.0.0
# typing_extensions ; python_version<'3.8'

from curses import meta
import importlib # nopycln: import
import importlib.util # nopycln: import
import inspect
import json
import logging
import os
import sys
from contextlib import suppress
from copy import deepcopy
from curses import meta
from inspect import Parameter, Signature
from pathlib import Path
from textwrap import indent
Expand Down Expand Up @@ -66,8 +67,7 @@


class ConfigSettings(BaseModel):
image: Optional[str] = None
bind_functions: list[str]
publish_functions: list[str]


def discover_published_functions(
Expand Down Expand Up @@ -255,45 +255,58 @@ def _as_args_tuple(return_annotation: Any) -> tuple:
config_folder = DOT_OSPARC_DIR / core_func.__name__
config_folder.mkdir(parents=True, exist_ok=True)

metadata_path = config_folder / "metadata.yml"
metadata = {
"name": f"{core_func.__name__}",
"thumbnail": "https://upload.wikimedia.org/wikipedia/commons/thumb/b/bd/Test.svg/315px-Test.svg.png",
"description": "",
"key": f"simcore/services/comp/ofs-{core_func.__name__}",
"integration-version": "1.0.0",
"type": "computational",
}

try:
prev_metadata = yaml.safe_load(metadata_path.read_text())
metadata.update(prev_metadata)
except Exception:
pass

metadata.update(
**{
"inputs": inputs,
"outputs": outputs,
def _update_metadata_file():
metadata_path = config_folder / "metadata.yml"
metadata = {
"name": f"{core_func.__name__}",
"thumbnail": "https://upload.wikimedia.org/wikipedia/commons/thumb/b/bd/Test.svg/315px-Test.svg.png",
"description": "",
"key": f"simcore/services/comp/ofs-{core_func.__name__}",
"integration-version": "1.0.0",
"type": "computational",
}
)
runtime = {
"settings": [

with suppress(FileNotFoundError):
prev_metadata = yaml.safe_load(metadata_path.read_text())
metadata.update(prev_metadata)

metadata.update(
**{
"inputs": inputs,
"outputs": outputs,
}
)

with metadata_path.open("wt") as fh:
yaml.safe_dump(metadata, fh, indent=1, sort_keys=False)

def _update_runtime_file():
runtime_path = config_folder / "runtime.yml"
runtime = {"settings": []}
with suppress(FileNotFoundError):
runtime = yaml.safe_load(runtime_path.read_text())

delete = [
item for item in runtime["settings"] if item["name"] == "ContainerSpec"
]
for item in delete:
runtime["settings"].remove(item)

runtime["settings"].append(
{
"name": "ContainerSpec",
"type": "ContainerSpec",
"value": {
"Command": [".osparc/binder_program.py", core_func.__name__, "run"]
},
},
]
}
)

with (config_folder / "metadata.yml").open("wt") as fh:
yaml.safe_dump(metadata, fh, indent=1, sort_keys=False)
with runtime_path.open("wt") as fh:
yaml.safe_dump(runtime, fh, indent=1, sort_keys=False)

with (config_folder / "runtime.yml").open("wt") as fh:
yaml.safe_dump(runtime, fh, indent=1, sort_keys=False)
_update_metadata_file()
_update_runtime_file()


def echo_jsonschema(core_func: Callable):
Expand Down Expand Up @@ -467,7 +480,7 @@ def create_cli(expose: list[Callable], settings: dict[str, Any]) -> typer.Typer:

main = create_cli(
expose=discover_published_functions(
config_settings.bind_functions, dot_osparc_dir=DOT_OSPARC_DIR
config_settings.publish_functions, dot_osparc_dir=DOT_OSPARC_DIR
),
settings=config_settings,
)
Expand Down

0 comments on commit 1e35016

Please sign in to comment.