2121
2222from ruamel import yaml
2323
24+ from cwl_utils .errors import WorkflowException
2425from cwl_utils .loghandler import _logger as _cwlutilslogger
2526
2627if TYPE_CHECKING :
@@ -103,6 +104,7 @@ def main(args: Optional[List[str]] = None) -> int:
103104
104105def run (args : argparse .Namespace ) -> int :
105106 """Primary processing loop."""
107+ return_code = 0
106108 for document in args .inputs :
107109 _logger .info ("Processing %s." , document )
108110 with open (document ) as doc_handle :
@@ -128,39 +130,44 @@ def run(args: argparse.Namespace) -> int:
128130 "Sorry, %s is not a supported CWL version by this tool." , version
129131 )
130132 return - 1
131- result , modified = traverse (
132- top , not args .etools , False , args .skip_some1 , args .skip_some2
133- )
134- output = Path (args .dir ) / Path (document ).name
135- if not modified :
136- if len (args .inputs ) > 1 :
137- shutil .copyfile (document , output )
138- continue
139- else :
140- return 7
141- if not isinstance (result , MutableSequence ):
142- result_json = save (
143- result ,
144- base_url = result .loadingOptions .fileuri
145- if result .loadingOptions .fileuri
146- else "" ,
133+ try :
134+ result , modified = traverse (
135+ top , not args .etools , False , args .skip_some1 , args .skip_some2
147136 )
148- # ^^ Setting the base_url and keeping the default value
149- # for relative_uris=True means that the IDs in the generated
150- # JSON/YAML are kept clean of the path to the input document
151- else :
152- result_json = [
153- save (result_item , base_url = result_item .loadingOptions .fileuri )
154- for result_item in result
155- ]
156- yaml .scalarstring .walk_tree (result_json )
157- # ^ converts multiline strings to nice multiline YAML
158- with open (output , "w" , encoding = "utf-8" ) as output_filehandle :
159- output_filehandle .write (
160- "#!/usr/bin/env cwl-runner\n "
161- ) # TODO: teach the codegen to do this?
162- yaml .main .round_trip_dump (result_json , output_filehandle )
163- return 0
137+ output = Path (args .dir ) / Path (document ).name
138+ if not modified :
139+ if len (args .inputs ) > 1 :
140+ shutil .copyfile (document , output )
141+ continue
142+ else :
143+ return 7
144+ if not isinstance (result , MutableSequence ):
145+ result_json = save (
146+ result ,
147+ base_url = result .loadingOptions .fileuri
148+ if result .loadingOptions .fileuri
149+ else "" ,
150+ )
151+ # ^^ Setting the base_url and keeping the default value
152+ # for relative_uris=True means that the IDs in the generated
153+ # JSON/YAML are kept clean of the path to the input document
154+ else :
155+ result_json = [
156+ save (result_item , base_url = result_item .loadingOptions .fileuri )
157+ for result_item in result
158+ ]
159+ yaml .scalarstring .walk_tree (result_json )
160+ # ^ converts multiline strings to nice multiline YAML
161+ with open (output , "w" , encoding = "utf-8" ) as output_filehandle :
162+ output_filehandle .write (
163+ "#!/usr/bin/env cwl-runner\n "
164+ ) # TODO: teach the codegen to do this?
165+ yaml .main .round_trip_dump (result_json , output_filehandle )
166+ except WorkflowException as exc :
167+ return_code = 1
168+ _logger .exception ("Skipping %s due to error." , document , exc_info = exc )
169+
170+ return return_code
164171
165172
166173if __name__ == "__main__" :
0 commit comments