4848from .argparser import arg_parser , generate_parser , get_default_args
4949from .context import LoadingContext , RuntimeContext , getdefault
5050from .cwlrdf import printdot , printrdf
51- from .errors import ArgumentException , UnsupportedRequirement , WorkflowException
51+ from .errors import (
52+ ArgumentException ,
53+ GraphTargetMissingException ,
54+ UnsupportedRequirement ,
55+ WorkflowException ,
56+ )
5257from .executors import JobExecutor , MultithreadedJobExecutor , SingleJobExecutor
5358from .load_tool import (
5459 default_loader ,
@@ -424,7 +429,7 @@ def init_job_order(
424429 input_required ,
425430 )
426431 if args .tool_help :
427- toolparser .print_help ()
432+ toolparser .print_help (cast ( IO [ str ], stdout ) )
428433 exit (0 )
429434 cmd_line = vars (toolparser .parse_args (args .job_order ))
430435 for record_name in records :
@@ -474,17 +479,6 @@ def init_job_order(
474479 job_order_object = {}
475480 job_order_object [shortname (inp ["id" ])] = inp ["default" ]
476481
477- if len (job_order_object ) == 0 :
478- if process .tool ["inputs" ]:
479- if toolparser is not None :
480- print (f"\n Options for { args .workflow } " )
481- toolparser .print_help ()
482- _logger .error ("" )
483- _logger .error ("Input object required, use --help for details" )
484- exit (1 )
485- else :
486- job_order_object = {}
487-
488482 def path_to_loc (p : CWLObjectType ) -> None :
489483 if "location" not in p and "path" in p :
490484 p ["location" ] = p ["path" ]
@@ -574,7 +568,7 @@ def printdeps(
574568 elif relative_deps == "cwd" :
575569 base = os .getcwd ()
576570 visit_class (deps , ("File" , "Directory" ), functools .partial (make_relative , base ))
577- stdout . write (json_dumps (deps , indent = 4 , default = str ))
571+ print (json_dumps (deps , indent = 4 , default = str ), file = stdout )
578572
579573
580574def prov_deps (
@@ -946,18 +940,18 @@ def print_targets(
946940 for f in ("outputs" , "inputs" ):
947941 if tool .tool [f ]:
948942 _logger .info ("%s %s%s targets:" , prefix [:- 1 ], f [0 ].upper (), f [1 :- 1 ])
949- stdout . write (
943+ print (
950944 " "
951- + "\n " .join ([f"{ prefix } { shortname (t ['id' ])} " for t in tool .tool [f ]])
952- + " \n "
945+ + "\n " .join ([f"{ prefix } { shortname (t ['id' ])} " for t in tool .tool [f ]]),
946+ file = stdout ,
953947 )
954948 if "steps" in tool .tool :
955949 loading_context = copy .copy (loading_context )
956950 loading_context .requirements = tool .requirements
957951 loading_context .hints = tool .hints
958952 _logger .info ("%s steps targets:" , prefix [:- 1 ])
959953 for t in tool .tool ["steps" ]:
960- stdout . write (f" { prefix } { shortname (t ['id' ])} \n " )
954+ print (f" { prefix } { shortname (t ['id' ])} " , file = stdout )
961955 run : Union [str , Process , Dict [str , Any ]] = t ["run" ]
962956 if isinstance (run , str ):
963957 process = make_tool (run , loading_context )
@@ -1040,20 +1034,20 @@ def main(
10401034 )
10411035
10421036 if args .version :
1043- print (versionfunc ())
1037+ print (versionfunc (), file = stdout )
10441038 return 0
10451039 _logger .info (versionfunc ())
10461040
10471041 if args .print_supported_versions :
1048- print ("\n " .join (supported_cwl_versions (args .enable_dev )))
1042+ print ("\n " .join (supported_cwl_versions (args .enable_dev )), file = stdout )
10491043 return 0
10501044
10511045 if not args .workflow :
10521046 if os .path .isfile ("CWLFile" ):
10531047 args .workflow = "CWLFile"
10541048 else :
10551049 _logger .error ("CWL document required, no input file was provided" )
1056- parser .print_help ()
1050+ parser .print_help (stderr )
10571051 return 1
10581052
10591053 if args .ga4gh_tool_registries :
@@ -1126,7 +1120,7 @@ def main(
11261120 processobj , metadata = loadingContext .loader .resolve_ref (uri )
11271121 processobj = cast (Union [CommentedMap , CommentedSeq ], processobj )
11281122 if args .pack :
1129- stdout . write (print_pack (loadingContext , uri ))
1123+ print (print_pack (loadingContext , uri ), file = stdout )
11301124 return 0
11311125
11321126 if args .provenance and runtimeContext .research_obj :
@@ -1136,29 +1130,45 @@ def main(
11361130 )
11371131
11381132 if args .print_pre :
1139- stdout . write (
1133+ print (
11401134 json_dumps (
11411135 processobj ,
11421136 indent = 4 ,
11431137 sort_keys = True ,
11441138 separators = ("," , ": " ),
11451139 default = str ,
1146- )
1140+ ),
1141+ file = stdout ,
11471142 )
11481143 return 0
11491144
1150- tool = make_tool (uri , loadingContext )
1145+ try :
1146+ tool = make_tool (uri , loadingContext )
1147+ except GraphTargetMissingException as main_missing_exc :
1148+ if args .validate :
1149+ logging .warn (
1150+ "File contains $graph of multiple objects and no default "
1151+ "process (#main). Validating all objects:"
1152+ )
1153+ for entry in workflowobj ["$graph" ]:
1154+ entry_id = entry ["id" ]
1155+ make_tool (entry_id , loadingContext )
1156+ print (f"{ entry_id } is valid CWL." , file = stdout )
1157+ else :
1158+ raise main_missing_exc
1159+
11511160 if args .make_template :
11521161 make_template (tool )
11531162 return 0
11541163
11551164 if args .validate :
1156- print (f"{ args .workflow } is valid CWL." )
1165+ print (f"{ args .workflow } is valid CWL." , file = stdout )
11571166 return 0
11581167
11591168 if args .print_rdf :
1160- stdout .write (
1161- printrdf (tool , loadingContext .loader .ctx , args .rdf_serializer )
1169+ print (
1170+ printrdf (tool , loadingContext .loader .ctx , args .rdf_serializer ),
1171+ file = stdout ,
11621172 )
11631173 return 0
11641174
@@ -1194,14 +1204,15 @@ def main(
11941204 if args .print_subgraph :
11951205 if "name" in tool .tool :
11961206 del tool .tool ["name" ]
1197- stdout . write (
1207+ print (
11981208 json_dumps (
11991209 tool .tool ,
12001210 indent = 4 ,
12011211 sort_keys = True ,
12021212 separators = ("," , ": " ),
12031213 default = str ,
1204- )
1214+ ),
1215+ file = stdout ,
12051216 )
12061217 return 0
12071218
@@ -1361,8 +1372,10 @@ def loc_to_path(obj: CWLObjectType) -> None:
13611372 # Unsetting the Generation from final output object
13621373 visit_class (out , ("File" ,), MutationManager ().unset_generation )
13631374
1364- stdout .write (json_dumps (out , indent = 4 , ensure_ascii = False , default = str ))
1365- stdout .write ("\n " )
1375+ print (
1376+ json_dumps (out , indent = 4 , ensure_ascii = False , default = str ),
1377+ file = stdout ,
1378+ )
13661379 if hasattr (stdout , "flush" ):
13671380 stdout .flush ()
13681381
0 commit comments