|
1 | | -from osparc_client import ValuesValue |
2 | 1 | from osparc_client import JobInputs as _JobInputs |
3 | 2 | from osparc_client import JobOutputs as _JobOutputs |
4 | | -from typing import Dict, Any |
| 3 | +from osparc_client import JobMetadata as _JobMetadata |
| 4 | +from .models import File |
| 5 | +from typing import Dict, Union, List |
5 | 6 | from pydantic import BaseModel, StrictStr, Field |
6 | 7 |
|
7 | 8 |
|
8 | | -def _values_dict(v: Dict[str, Any]) -> Dict[str, ValuesValue | None]: |
9 | | - result = {} |
10 | | - for k, v in v.items(): |
11 | | - if v is not None: |
12 | | - result[k] = ValuesValue(v) |
13 | | - else: |
14 | | - result[k] = v |
15 | | - return result |
16 | | - |
17 | | - |
18 | | -class JobInputs(_JobInputs): |
19 | | - def __init__(self, *args, **kwargs): |
20 | | - if len(args) == 1 and len(kwargs) == 0: |
21 | | - input = args[0] |
22 | | - assert isinstance(input, dict) |
23 | | - super().__init__(values=_values_dict(input)) |
24 | | - return |
25 | | - if len(args) == 0 and len(kwargs) == 1: |
26 | | - values = kwargs.get("values") |
27 | | - if values is None: |
28 | | - raise RuntimeError("When passing a single kwarg it must be 'values'") |
29 | | - super().__init__(values=_values_dict(values)) |
30 | | - return |
31 | | - else: |
32 | | - super().__init__(*args, **kwargs) |
| 9 | +class JobInputs(BaseModel): |
| 10 | + values: Dict[str, Union[File, List[object], bool, float, int, str, None]] = Field( |
| 11 | + kw_only=False |
| 12 | + ) |
| 13 | + |
| 14 | + def __init__( |
| 15 | + self, values: Dict[str, Union[File, List[object], bool, float, int, str, None]] |
| 16 | + ): |
| 17 | + super().__init__(values=values) |
| 18 | + |
| 19 | + |
| 20 | +assert set(_JobInputs.model_fields.keys()) == set(JobInputs.model_fields.keys()) |
33 | 21 |
|
34 | 22 |
|
35 | 23 | class JobOutputs(BaseModel): |
36 | 24 | job_id: StrictStr = Field(description="Job that produced this output") |
37 | | - results: Dict[str, Any] |
38 | | - |
39 | | - @classmethod |
40 | | - def from_osparc_client_job_outputs(cls, outputs: _JobOutputs) -> "JobOutputs": |
41 | | - _results = {} |
42 | | - for k, v in outputs.results.items(): |
43 | | - if isinstance(v, ValuesValue): |
44 | | - _results[k] = v.actual_instance |
45 | | - else: |
46 | | - _results[k] = v |
47 | | - |
48 | | - return cls(job_id=outputs.job_id, results=_results) |
| 25 | + results: Dict[str, Union[File, List[object], bool, float, int, str, None]] |
| 26 | + |
| 27 | + |
| 28 | +assert set(_JobOutputs.model_fields.keys()) == set(JobOutputs.model_fields.keys()) |
| 29 | + |
| 30 | + |
| 31 | +class JobMetadata(BaseModel): |
| 32 | + job_id: StrictStr |
| 33 | + metadata: Dict[str, Union[bool, float, int, str, None]] |
| 34 | + url: str | None |
| 35 | + |
| 36 | + |
| 37 | +assert set(_JobMetadata.model_fields.keys()) == set(JobMetadata.model_fields.keys()) |
0 commit comments