1111import logging
1212import uuid as uuid_mod
1313from pathlib import Path
14- from typing import Any , Literal , overload
14+ from typing import Any , Callable , Literal , overload , TypedDict
1515
1616from ._labels import Labels
1717from .model import (
3636)
3737from .options import ConversionOptions
3838from .schema .gxformat2 import (
39- BaseComment ,
39+ FrameComment ,
40+ FreehandComment ,
4041 GalaxyWorkflow ,
42+ MarkdownComment ,
43+ TextComment ,
4144 WorkflowInputParameter ,
4245 WorkflowOutputParameter ,
4346 WorkflowStepOutput ,
4447)
4548from .schema .native import (
49+ NativeCreatorOrganization ,
50+ NativeCreatorPerson ,
4651 NativeInputConnection ,
4752 NativePostJobAction ,
53+ NativeReport ,
54+ NativeStepInput ,
4855 NativeStepType ,
4956 NativeWorkflowOutput ,
5057 StepPosition ,
5360
5461log = logging .getLogger (__name__ )
5562
56- POST_JOB_ACTIONS = {
63+ class _PJADef (TypedDict ):
64+ action_class : str
65+ default : Any
66+ arguments : Callable [..., dict [str , Any ]]
67+
68+
69+ POST_JOB_ACTIONS : dict [str , _PJADef ] = {
5770 "hide" : {
5871 "action_class" : "HideDatasetAction" ,
5972 "default" : False ,
@@ -180,7 +193,7 @@ def __init__(self, options: ConversionOptions):
180193
181194 def step_id (self , label_or_id : str | int ) -> int :
182195 if label_or_id in self .labels :
183- return self .labels [label_or_id ]
196+ return self .labels [label_or_id ] # type: ignore[index]
184197 return int (label_or_id )
185198
186199 def step_output (self , value : str ) -> tuple [int , str ]:
@@ -212,6 +225,8 @@ def _build_native_workflow(
212225 # Convert comments
213226 comments = _build_native_comments (wf .comments , ctx )
214227
228+ native_creators = _convert_creators_to_native (wf .creator ) if wf .creator else None
229+ report = NativeReport (markdown = wf .report .markdown ) if wf .report else None
215230 return NormalizedNativeWorkflow (
216231 a_galaxy_workflow = "true" ,
217232 format_version = "0.1" ,
@@ -221,8 +236,8 @@ def _build_native_workflow(
221236 tags = wf .tags ,
222237 license = wf .license ,
223238 release = wf .release ,
224- creator = wf . creator ,
225- report = { "markdown" : wf . report . markdown } if wf . report else None ,
239+ creator = native_creators ,
240+ report = report ,
226241 steps = native_steps ,
227242 comments = comments ,
228243 )
@@ -244,7 +259,7 @@ def _build_input_step(
244259 else :
245260 multiple = False
246261
247- type_str = input_type .value if hasattr (input_type , "value" ) else str (input_type ) if input_type else "data"
262+ type_str = input_type .value if input_type is not None and hasattr (input_type , "value" ) else str (input_type ) if input_type else "data"
248263 if type_str in ("File" , "data" , "data_input" ):
249264 step_type = NativeStepType .data_input
250265 elif type_str in ("collection" , "data_collection" , "data_collection_input" ):
@@ -290,13 +305,13 @@ def _build_input_step(
290305 return NormalizedNativeStep (
291306 id = order_index ,
292307 type_ = step_type ,
308+ in_ = in_ ,
293309 label = label ,
294310 name = raw_label ,
295311 annotation = _join_doc (inp .doc ) or "" ,
296312 tool_state = tool_state ,
297313 position = position ,
298- inputs = [{"name" : raw_label , "description" : "" }],
299- in_ = in_ ,
314+ inputs = [NativeStepInput (name = raw_label , description = "" )],
300315 )
301316
302317
@@ -482,7 +497,7 @@ def _build_pause_step(
482497 annotation = step .doc or "" ,
483498 tool_state = {"name" : name },
484499 input_connections = input_connections ,
485- inputs = [{ " name" : name , " description" : "" } ],
500+ inputs = [NativeStepInput ( name = name , description = "" ) ],
486501 position = position ,
487502 uuid = step .uuid ,
488503 )
@@ -516,7 +531,7 @@ def _build_pick_value_step(
516531 tool_state = tool_state ,
517532 input_connections = input_connections ,
518533 post_job_actions = post_job_actions ,
519- inputs = [{ " name" : name , " description" : "" } ],
534+ inputs = [NativeStepInput ( name = name , description = "" ) ],
520535 position = position ,
521536 uuid = step .uuid ,
522537 )
@@ -636,7 +651,7 @@ def _wire_workflow_outputs(
636651
637652
638653def _build_native_comments (
639- comments : list [BaseComment ],
654+ comments : list [TextComment | MarkdownComment | FrameComment | FreehandComment ],
640655 ctx : _ConversionContext ,
641656) -> list :
642657 """Convert Format2 comments to native format."""
@@ -726,6 +741,23 @@ def _default_position(position: Any, order_index: int) -> StepPosition:
726741 return StepPosition (left = 10 * order_index , top = 10 * order_index )
727742
728743
744+ _NATIVE_CREATOR_MAP : dict [str , type [NativeCreatorPerson ] | type [NativeCreatorOrganization ]] = {
745+ "Person" : NativeCreatorPerson ,
746+ "Organization" : NativeCreatorOrganization ,
747+ }
748+
749+
750+ def _convert_creators_to_native (
751+ creators : list ,
752+ ) -> list [NativeCreatorPerson | NativeCreatorOrganization ]:
753+ result : list [NativeCreatorPerson | NativeCreatorOrganization ] = []
754+ for c in creators :
755+ d = c .model_dump (by_alias = True , exclude_none = True ) if hasattr (c , "model_dump" ) else c
756+ cls = _NATIVE_CREATOR_MAP .get (d .get ("class" , "" ), NativeCreatorPerson )
757+ result .append (cls .model_validate (d ))
758+ return result
759+
760+
729761def _join_doc (doc : str | list [str ] | None ) -> str | None :
730762 if doc is None :
731763 return None
0 commit comments