@@ -15,19 +15,20 @@ def convert_v0_1_to_v0_2(config: v0_1.PartialConfiguration) -> v0_2.Configuratio
1515 Returns:
1616 The corresponding configuration expressed in yMMSL v0.2.
1717 """
18- description = ' Please add a description'
18+ description = " Please add a description"
1919 if config .description :
2020 description = config .description
2121 models = [convert_model (config .model )] if config .model is not None else None
2222 settings = deepcopy (config .settings )
2323 programs = [
24- convert_implementation (impl ) for impl in config .implementations .values ()]
24+ convert_implementation (impl ) for impl in config .implementations .values ()
25+ ]
2526 if programs :
2627 warnings .warn (
27- ' In yMMSL v0.2 implementations have become programs, and you can now'
28- ' specify the ports of a program in the yMMSL description. If your'
29- ' program has fixed ports then you should do this, because it will make'
30- ' incorrect wiring easier to debug. While there, add a description too!' ,
28+ " In yMMSL v0.2 implementations have become programs, and you can now"
29+ " specify the ports of a program in the yMMSL description. If your"
30+ " program has fixed ports then you should do this, because it will make"
31+ " incorrect wiring easier to debug. While there, add a description too!" ,
3132 stacklevel = 2 ,
3233 )
3334
@@ -36,27 +37,40 @@ def convert_v0_1_to_v0_2(config: v0_1.PartialConfiguration) -> v0_2.Configuratio
3637 resume = deepcopy (config .resume )
3738
3839 warnings .warn (
39- ' Comments can unfortunately not be read by this converter, and so have been'
40- ' ignored. Please copy them into an appropriate description field.' ,
40+ " Comments can unfortunately not be read by this converter, and so have been"
41+ " ignored. Please copy them into an appropriate description field." ,
4142 stacklevel = 2 ,
4243 )
4344
4445 return v0_2 .Configuration (
45- description , None , models , None , settings , programs , resources , checkpoints ,
46- resume )
46+ description ,
47+ None ,
48+ models ,
49+ None ,
50+ settings ,
51+ programs ,
52+ resources ,
53+ checkpoints ,
54+ resume ,
55+ )
4756
4857
4958def convert_component (component : v0_1 .Component ) -> v0_2 .Component :
5059 """Convert a v0.1 Component object to a v0.2 Component."""
5160 ports = component .ports if component .ports else v0_1 .Ports ()
52- description = ' Please add a description'
61+ description = " Please add a description"
5362 implementation : Optional [str ] = None
5463 if component .implementation is not None :
5564 implementation = str (component .implementation )
5665
5766 return v0_2 .Component (
58- str (component .name ), convert_ports (ports ), description , implementation ,
59- False , component .multiplicity )
67+ str (component .name ),
68+ convert_ports (ports ),
69+ description ,
70+ implementation ,
71+ False ,
72+ component .multiplicity ,
73+ )
6074
6175
6276def convert_conduit (conduit : v0_1 .Conduit ) -> v0_2 .Conduit :
@@ -77,27 +91,31 @@ def infer_ports(components: List[v0_2.Component], conduits: List[v0_2.Conduit])
7791 for conduit in conduits :
7892 if conduit .sending_component () == component .name :
7993 component .ports [conduit .sending_port ()] = v0_2 .Port (
80- conduit .sending_port (), v0_2 .Operator .O_F ,
81- v0_2 . Timeline ( '' ) )
94+ conduit .sending_port (), v0_2 .Operator .O_F , v0_2 . Timeline ( "" )
95+ )
8296 if component .name not in changed_components :
8397 changed_components .append (component .name )
8498
8599 if conduit .receiving_component () == component .name :
86100 component .ports [conduit .receiving_port ()] = v0_2 .Port (
87- conduit .receiving_port (), v0_2 .Operator .F_INIT ,
88- v0_2 .Timeline ('' ))
101+ conduit .receiving_port (),
102+ v0_2 .Operator .F_INIT ,
103+ v0_2 .Timeline ("" ),
104+ )
89105 if component .name not in changed_components :
90106 changed_components .append (component .name )
91107
92108 if changed_components :
93- ch_comp_list = ' \n - ' + ' \n - ' .join (map (str , changed_components ))
109+ ch_comp_list = " \n - " + " \n - " .join (map (str , changed_components ))
94110 warnings .warn (
95- 'In yMMSL v0.2 components are required to declare their ports. The'
96- ' following components did not have a ports declaration, so one has'
97- ' been added based on the connected conduits. THIS MAY BE WRONG,'
98- ' because the operators have all been set to F_INIT and O_F, while they'
99- ' may really be O_I or S. Please check these components and adjust'
100- f' as needed: { ch_comp_list } ' , stacklevel = 4 )
111+ "In yMMSL v0.2 components are required to declare their ports. The"
112+ " following components did not have a ports declaration, so one has"
113+ " been added based on the connected conduits. THIS MAY BE WRONG,"
114+ " because the operators have all been set to F_INIT and O_F, while they"
115+ " may really be O_I or S. Please check these components and adjust"
116+ f" as needed: { ch_comp_list } " ,
117+ stacklevel = 4 ,
118+ )
101119
102120
103121def convert_model (model : v0_1 .ModelReference ) -> v0_2 .Model :
@@ -109,14 +127,15 @@ def convert_model(model: v0_1.ModelReference) -> v0_2.Model:
109127 Returns:
110128 The corresponding configuration expressed in yMMSL v0.2.
111129 """
112- description = ' Please add a description'
130+ description = " Please add a description"
113131
114132 if isinstance (model , v0_1 .Model ):
115133 components = list (map (convert_component , model .components ))
116134 conduits = list (map (convert_conduit , model .conduits ))
117135 infer_ports (components , conduits )
118136 return v0_2 .Model (
119- str (model .name ), None , description , None , components , conduits )
137+ str (model .name ), None , description , None , components , conduits
138+ )
120139 else :
121140 return v0_2 .Model (str (model .name ), None , description , None , [], [])
122141
@@ -133,7 +152,7 @@ def convert_implementation(impl: v0_1.Implementation) -> v0_2.Program:
133152 Returns:
134153 The corresponding program expressed in yMMSL v0.2.
135154 """
136- description = ' Please add a description'
155+ description = " Please add a description"
137156 base_env : Optional [v0_1 .BaseEnv ] = impl .base_env
138157 env : Optional [Dict [str , str ]] = impl .env
139158
@@ -146,9 +165,21 @@ def convert_implementation(impl: v0_1.Implementation) -> v0_2.Program:
146165 env = None
147166
148167 return v0_2 .Program (
149- str (impl .name ), None , description , None , base_env , impl .modules ,
150- impl .virtual_env , env , execution_model , impl .executable , impl .args ,
151- impl .script , impl .can_share_resources , impl .keeps_state_for_next_use )
168+ str (impl .name ),
169+ None ,
170+ description ,
171+ None ,
172+ base_env ,
173+ impl .modules ,
174+ impl .virtual_env ,
175+ env ,
176+ execution_model ,
177+ impl .executable ,
178+ impl .args ,
179+ impl .script ,
180+ impl .can_share_resources ,
181+ impl .keeps_state_for_next_use ,
182+ )
152183
153184
154185def convert_ports (ports : v0_1 .Ports ) -> v0_2 .Ports :
@@ -161,23 +192,26 @@ def convert_ports(ports: v0_1.Ports) -> v0_2.Ports:
161192 The corresponding ports expressed in yMMSL v0.2.
162193 """
163194 return v0_2 .Ports (
164- list (map (str , ports .f_init )),
165- list (map (str , ports .o_i )),
166- list (map (str , ports .s )),
167- list (map (str , ports .o_f )))
195+ list (map (str , ports .f_init )),
196+ list (map (str , ports .o_i )),
197+ list (map (str , ports .s )),
198+ list (map (str , ports .o_f )),
199+ )
168200
169201
170202def convert_resources (
171- resources : MutableMapping [v0_1 .Reference , v0_1 .ResourceRequirements ],
172- models : Optional [List [v0_2 .Model ]]
173- ) -> MutableMapping [v0_2 .Reference , v0_2 .ResourceRequirements ]:
203+ resources : MutableMapping [v0_1 .Reference , v0_1 .ResourceRequirements ],
204+ models : Optional [List [v0_2 .Model ]],
205+ ) -> MutableMapping [v0_2 .Reference , v0_2 .ResourceRequirements ]:
174206 if not models :
175207 warnings .warn (
176- 'When specifying resources in yMMSL v0.2, component names must be'
177- ' prefixed with the name of the top (outermost) model, e.g. as'
178- ' my_model.my_component rather than just my_component. This file'
179- ' does not contain a model, so its name cannot be added automatically.'
180- ' Please add the model name yourself.' , stacklevel = 3 )
208+ "When specifying resources in yMMSL v0.2, component names must be"
209+ " prefixed with the name of the top (outermost) model, e.g. as"
210+ " my_model.my_component rather than just my_component. This file"
211+ " does not contain a model, so its name cannot be added automatically."
212+ " Please add the model name yourself." ,
213+ stacklevel = 3 ,
214+ )
181215 return deepcopy (resources )
182216 else :
183217 mname = models [0 ].name
0 commit comments