1
1
from typing import Dict , List , Union , Optional , Callable , Any
2
- from scabha .cargo import Parameter , _UNSET_DEFAULT , EmptyDictDefault , ParameterPolicies
2
+ from scabha .cargo import Parameter , _UNSET_DEFAULT , EmptyListDefault
3
+ from scabha .cargo import EmptyDictDefault , ParameterPolicies , Cargo
3
4
from scabha .basetypes import File , Directory
4
5
from scabha .validate import validate_parameters
5
6
from dataclasses import dataclass
10
11
@dataclass
11
12
class OldParameter :
12
13
name : str
13
- dtype : str
14
+ dtype : Any
14
15
info : str
15
16
default : Any = None
16
17
required : bool = False
17
- choices : List [Any ] = None
18
- io : str = None
19
- mapping : str = None
18
+ choices : Optional [ List [Any ] ] = None
19
+ io : Optional [ str ] = ""
20
+ mapping : Optional [ str ] = ""
20
21
check_io : bool = False
21
22
deprecated : bool = False
22
23
positional : bool = False
23
24
24
25
25
26
@dataclass
27
+ class OldCab :
28
+ task : str
29
+ base : str
30
+ version : List [str ]
31
+ binary : str = ""
32
+ description : str = "<documentation>"
33
+ prefix : str = "--"
34
+ parameters : Optional [List [Dict ]] = None
35
+ tag : Optional [List [str ]] = None
36
+ junk : Optional [List [str ]] = None
37
+ msdir : bool = False
38
+ wranglers : Optional [List [str ]] = None
39
+
26
40
class SimpleCab :
27
- inputs : Dict [str , Any ] = EmptyDictDefault ()
28
- outputs : Dict [str , Any ] = EmptyDictDefault ()
41
+ def __init__ (self , oldfile : File ):
42
+ self .oldfile = oldfile
43
+ cab_strct = OmegaConf .structured (OldCab )
44
+ param_strct = OmegaConf .structured (OldParameter )
45
+ _oldcab = OmegaConf .load (oldfile )
46
+ self .oldcab = OmegaConf .merge (cab_strct ,
47
+ OmegaConf .load (oldfile ))
48
+ self .parameters = []
49
+ for param in _oldcab .parameters :
50
+ pardict = OmegaConf .merge (param_strct , param )
51
+ self .parameters .append (pardict )
52
+
53
+
29
54
30
55
def __to_new_dtype (self , param :OldParameter ) -> str :
31
56
new_dtype = []
@@ -58,27 +83,31 @@ def __to_new_dtype(self, param:OldParameter) -> str:
58
83
return "Union[" + "," .join (new_dtype ) + "]"
59
84
else :
60
85
return new_dtype [0 ]
86
+
61
87
62
- def init_from_old_cab (self , oldcab_file : File ):
88
+ def to_new_params (self , set_inputs = True ):
63
89
"""AI is creating summary for init_from_old_cab
64
90
65
91
Args:
66
92
oldcab (File): [description]
67
93
"""
68
- oldcab = OmegaConf .load (oldcab_file )
69
-
70
- self .inputs = {}
71
- self .outputs = {}
72
- for param in oldcab .parameters :
94
+ param_struct = OmegaConf .structured (Parameter )
95
+ params = {}
96
+ for param in self .parameters :
73
97
dtype = self .__to_new_dtype (param )
74
- oldparam = OldParameter (** param )
75
98
76
- policies = ParameterPolicies (positional = oldparam .positional )
77
-
78
- self .inputs [param .name ] = Parameter (info = oldparam .info , dtype = dtype , policies = policies ,
79
- nom_de_guerre = oldparam .mapping ,
80
- must_exist = oldparam .check_io )
99
+ policies = ParameterPolicies (positional = param .positional )
81
100
101
+ params [param .name ] = OmegaConf .merge (param_struct ,
102
+ dict (info = param .info , dtype = dtype , policies = policies ,
103
+ nom_de_guerre = param .mapping ,
104
+ must_exist = param .check_io ))
105
+ if set_inputs :
106
+ self .inputs = params
107
+ self .outputs = {}
108
+ return OmegaConf .create (params )
109
+
110
+
82
111
def save (self , path : str ):
83
112
"""_summary_
84
113
@@ -88,6 +117,7 @@ def save(self, path: str):
88
117
Returns:
89
118
_type_: _description_
90
119
"""
120
+
91
121
outdict = OmegaConf .create ({"inputs" : self .inputs ,
92
122
"outputs" : self .outputs ,
93
123
})
0 commit comments