1313)
1414
1515import yaml
16- from gxformat2 import (
17- from_galaxy_native ,
18- ImporterGalaxyInterface ,
19- ImportOptions ,
20- python_to_workflow ,
21- )
2216from gxformat2 .abstract import from_dict
2317from gxformat2 .cytoscape import to_cytoscape
2418from gxformat2 .yaml import ordered_dump
109103 RawTextTerm ,
110104)
111105from galaxy .work .context import WorkRequestContext
106+ from galaxy .workflow .format2 import (
107+ convert_from_format2 ,
108+ convert_to_format2 ,
109+ )
112110from galaxy .workflow .modules import (
113111 module_factory ,
114112 ToolModule ,
@@ -610,10 +608,7 @@ def read_workflow_from_path(self, app, user, path, allow_in_directory=None) -> m
610608 workflow_class , as_dict , object_id = artifact_class (trans , as_dict , allow_in_directory = allow_in_directory )
611609 assert workflow_class == "GalaxyWorkflow"
612610 # Format 2 Galaxy workflow.
613- galaxy_interface = Format2ConverterGalaxyInterface ()
614- import_options = ImportOptions ()
615- import_options .deduplicate_subworkflows = True
616- as_dict = python_to_workflow (as_dict , galaxy_interface , workflow_directory = None , import_options = import_options )
611+ as_dict = convert_from_format2 (as_dict , None )
617612 raw_description = RawWorkflowDescription (as_dict )
618613 created_workflow = self .build_workflow_from_raw_description (trans , raw_description , WorkflowCreateOptions ())
619614 return created_workflow .workflow
@@ -640,15 +635,7 @@ def normalize_workflow_format(self, trans, as_dict):
640635 workflow_class , as_dict , object_id = artifact_class (trans , as_dict )
641636 if workflow_class == "GalaxyWorkflow" or "yaml_content" in as_dict :
642637 # Format 2 Galaxy workflow.
643- galaxy_interface = Format2ConverterGalaxyInterface ()
644- import_options = ImportOptions ()
645- import_options .deduplicate_subworkflows = True
646- try :
647- as_dict = python_to_workflow (
648- as_dict , galaxy_interface , workflow_directory = workflow_directory , import_options = import_options
649- )
650- except yaml .scanner .ScannerError as e :
651- raise exceptions .MalformedContents (str (e ))
638+ as_dict = convert_from_format2 (as_dict , workflow_directory )
652639
653640 return RawWorkflowDescription (as_dict , workflow_path )
654641
@@ -927,8 +914,8 @@ def workflow_to_dict(self, trans, stored, style="export", version=None, history=
927914 fields like 'url' and 'url' and actual unencoded step ids instead of 'order_index'.
928915 """
929916
930- def to_format_2 (wf_dict , ** kwds ):
931- return from_galaxy_native (wf_dict , None , ** kwds )
917+ def to_format_2 (wf_dict , json_wrapper : bool ):
918+ return convert_to_format2 (wf_dict , json_wrapper = json_wrapper )
932919
933920 if version == "" :
934921 version = None
@@ -955,7 +942,7 @@ def to_format_2(wf_dict, **kwds):
955942 wf_dict = self ._workflow_to_dict_preview (trans , workflow = workflow )
956943 elif style == "format2" :
957944 wf_dict = self ._workflow_to_dict_export (trans , stored , workflow = workflow )
958- wf_dict = to_format_2 (wf_dict )
945+ wf_dict = to_format_2 (wf_dict , json_wrapper = False )
959946 elif style == "format2_wrapped_yaml" :
960947 wf_dict = self ._workflow_to_dict_export (trans , stored , workflow = workflow )
961948 wf_dict = to_format_2 (wf_dict , json_wrapper = True )
@@ -1006,7 +993,7 @@ def store_workflow_to_path(self, workflow_path, stored_workflow, workflow, **kwd
1006993 ordered_dump (abstract_dict , f )
1007994 else :
1008995 wf_dict = self ._workflow_to_dict_export (trans , stored_workflow , workflow = workflow )
1009- wf_dict = from_galaxy_native (wf_dict , None , json_wrapper = True )
996+ wf_dict = convert_to_format2 (wf_dict , json_wrapper = True )
1010997 f .write (wf_dict ["yaml_content" ])
1011998
1012999 def _workflow_to_dict_run (self , trans : ProvidesUserContext , stored , workflow , history = None ):
@@ -2237,13 +2224,6 @@ def __init__(self, as_dict, workflow_path=None):
22372224 self .workflow_path = workflow_path
22382225
22392226
2240- class Format2ConverterGalaxyInterface (ImporterGalaxyInterface ):
2241- def import_workflow (self , workflow , ** kwds ):
2242- raise NotImplementedError (
2243- "Direct format 2 import of nested workflows is not yet implemented, use bioblend client."
2244- )
2245-
2246-
22472227def _get_stored_workflow (session , workflow_uuid , workflow_id , by_stored_id ):
22482228 stmt = select (StoredWorkflow )
22492229 if workflow_uuid is not None :
0 commit comments