Skip to content

Commit

Permalink
feat: support init job for example job tests
Browse files Browse the repository at this point in the history
  • Loading branch information
makkus committed Dec 27, 2023
1 parent f27bf71 commit 96f927e
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 10 deletions.
2 changes: 2 additions & 0 deletions src/kiara/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@

KIARA_DEFAULT_STAGES_EXTRACTION_TYPE = "early"

INIT_EXAMPLE_NAME = "init"

# USER_PIPELINES_FOLDER = os.path.join(kiara_app_dirs.user_config_dir, "pipelines")


Expand Down
3 changes: 3 additions & 0 deletions src/kiara/interfaces/python_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1992,6 +1992,9 @@ def queue_job(
This is a convenience method that auto-detects what is meant by the 'operation' string input argument.
If the 'operation' is a JobDesc instance, and that JobDesc instance has the 'save' attribute
set, it will be ignored, so you'll have to store any results manually.
Arguments:
operation: a module name, operation id, or a path to a pipeline file (resolved in this order, until a match is found)..
inputs: the operation inputs
Expand Down
20 changes: 17 additions & 3 deletions src/kiara/interfaces/python_api/models/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -1483,10 +1483,13 @@ def _create_renderable_list(self, **config) -> RenderableType:
include_internal_operations = config.get("include_internal_operations", True)
full_doc = config.get("full_doc", False)
filter = config.get("filter", [])
show_internal_column = config.get("show_internal_column", False)

table = Table(box=box.SIMPLE, show_header=True)
table.add_column("Id", no_wrap=True, style="i")
table.add_column("Type(s)", style="green")
if show_internal_column:
table.add_column("Internal", justify="center")
table.add_column("Description")

for op_id, op_info in self.item_infos.items():
Expand All @@ -1508,6 +1511,9 @@ def _create_renderable_list(self, **config) -> RenderableType:
else:
desc = Markdown(op_info.documentation.description)

is_internal = op_info.operation.module.characteristics.is_internal
is_internal_str = "\u2714" if is_internal else ""

if filter:
match = True
for f in filter:
Expand All @@ -1518,10 +1524,16 @@ def _create_renderable_list(self, **config) -> RenderableType:
match = False
break
if match:
table.add_row(op_id, ", ".join(types), desc)
if not show_internal_column:
table.add_row(op_id, ", ".join(types), desc)
else:
table.add_row(op_id, ", ".join(types), is_internal_str, desc)

else:
table.add_row(op_id, ", ".join(types), desc)
if not show_internal_column:
table.add_row(op_id, ", ".join(types), desc)
else:
table.add_row(op_id, ", ".join(types), is_internal_str, desc)

return table

Expand Down Expand Up @@ -1887,7 +1899,9 @@ def create_renderable(self, **config: Any) -> RenderableType:
if include_module_types:
table.add_row("module_types", self.module_types.create_renderable(**config))
if include_operations:
table.add_row("operations", self.operations.create_renderable(**config))
config_ops = config.copy()
config_ops["show_internal_column"] = True
table.add_row("operations", self.operations.create_renderable(**config_ops))
if include_operation_types:
table.add_row(
"operation_types", self.operation_types.create_renderable(**config)
Expand Down
14 changes: 8 additions & 6 deletions src/kiara/interfaces/python_api/models/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ class JobDesc(KiaraModel):
_kiara_model_id: ClassVar = "instance.job_desc"

@classmethod
def create_from_file(cls, path: Union[str, Path]):
def create_from_file(cls, path: Union[str, Path]) -> "JobDesc":
run_data = cls.parse_from_file(path)
return cls(**run_data)

@classmethod
def parse_from_file(cls, path: Union[str, Path]):
def parse_from_file(cls, path: Union[str, Path]) -> Mapping[str, Any]:

if isinstance(path, str):
path = Path(path)
Expand Down Expand Up @@ -59,7 +59,7 @@ def parse_data(
data: Mapping[str, Any],
var_repl_dict: Union[Mapping[str, Any], None] = None,
alias: Union[str, None] = None,
):
) -> Mapping[str, Any]:

if not isinstance(data, Mapping):
raise KiaraException("Job description data is not a mapping.")
Expand All @@ -68,9 +68,11 @@ def parse_data(
raise KiaraException("Missing 'operation' key")

if var_repl_dict:
run_data = replace_var_names_in_obj(data, repl_dict=var_repl_dict)
run_data: Dict[str, Any] = replace_var_names_in_obj(
data, repl_dict=var_repl_dict
)
else:
run_data = data
run_data = dict(data)

if alias:
run_data["job_alias"] = alias
Expand Down Expand Up @@ -101,7 +103,7 @@ def create_from_data(
default_factory=DocumentationMetadataModel.create,
)
save: Dict[str, str] = Field(
description="Configuration on how/whether to save the job results.",
description="Configuration on how/whether to save the job results. Key is the output field name, value is the alias to use for saving.",
default_factory=dict,
)

Expand Down
3 changes: 3 additions & 0 deletions src/kiara/modules/included_core_modules/render_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ def retrieve_supported_render_combinations(cls) -> Iterable[Tuple[str, str]]:
_config_cls = RenderValueModuleConfig
_module_type_name: str = None # type: ignore

def _retrieve_module_characteristics(self) -> ModuleCharacteristics:
return DEFAULT_IDEMPOTENT_INTERNAL_MODULE_CHARACTERISTICS

def create_inputs_schema(
self,
) -> Mapping[str, Union[ValueSchema, Mapping[str, Any]]]:
Expand Down
23 changes: 22 additions & 1 deletion src/kiara/utils/testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,34 @@
from pathlib import Path
from typing import Any, Callable, Dict, Mapping, Union

from kiara.defaults import INIT_EXAMPLE_NAME
from kiara.interfaces.python_api import JobDesc
from kiara.utils import log_exception
from kiara.utils.files import get_data_from_file


def get_init_job(jobs_folder: Path) -> Union[None, JobDesc]:

init_test_yaml = jobs_folder / f"{INIT_EXAMPLE_NAME}.yaml"
if init_test_yaml.is_file():
return JobDesc.create_from_file(init_test_yaml)

init_test_json = jobs_folder / f"{INIT_EXAMPLE_NAME}.json"
if init_test_json.is_file():
return JobDesc.create_from_file(init_test_json)

return None


def list_job_descs(jobs_folder: Path):
for f in jobs_folder.glob("*"):

init_job = get_init_job(jobs_folder)
if init_job is not None:
yield init_job

for f in sorted(jobs_folder.glob("*")):
if f.name in [f"{INIT_EXAMPLE_NAME}.yaml", f"{INIT_EXAMPLE_NAME}.json"]:
continue
try:
job_desc = JobDesc.create_from_file(f)
yield job_desc
Expand Down

0 comments on commit 96f927e

Please sign in to comment.