48
48
from .argparser import arg_parser , generate_parser , get_default_args
49
49
from .context import LoadingContext , RuntimeContext , getdefault
50
50
from .cwlrdf import printdot , printrdf
51
- from .errors import ArgumentException , UnsupportedRequirement , WorkflowException
51
+ from .errors import (
52
+ ArgumentException ,
53
+ GraphTargetMissingException ,
54
+ UnsupportedRequirement ,
55
+ WorkflowException ,
56
+ )
52
57
from .executors import JobExecutor , MultithreadedJobExecutor , SingleJobExecutor
53
58
from .load_tool import (
54
59
default_loader ,
@@ -424,7 +429,7 @@ def init_job_order(
424
429
input_required ,
425
430
)
426
431
if args .tool_help :
427
- toolparser .print_help ()
432
+ toolparser .print_help (cast ( IO [ str ], stdout ) )
428
433
exit (0 )
429
434
cmd_line = vars (toolparser .parse_args (args .job_order ))
430
435
for record_name in records :
@@ -474,17 +479,6 @@ def init_job_order(
474
479
job_order_object = {}
475
480
job_order_object [shortname (inp ["id" ])] = inp ["default" ]
476
481
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
-
488
482
def path_to_loc (p : CWLObjectType ) -> None :
489
483
if "location" not in p and "path" in p :
490
484
p ["location" ] = p ["path" ]
@@ -574,7 +568,7 @@ def printdeps(
574
568
elif relative_deps == "cwd" :
575
569
base = os .getcwd ()
576
570
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 )
578
572
579
573
580
574
def prov_deps (
@@ -946,18 +940,18 @@ def print_targets(
946
940
for f in ("outputs" , "inputs" ):
947
941
if tool .tool [f ]:
948
942
_logger .info ("%s %s%s targets:" , prefix [:- 1 ], f [0 ].upper (), f [1 :- 1 ])
949
- stdout . write (
943
+ print (
950
944
" "
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 ,
953
947
)
954
948
if "steps" in tool .tool :
955
949
loading_context = copy .copy (loading_context )
956
950
loading_context .requirements = tool .requirements
957
951
loading_context .hints = tool .hints
958
952
_logger .info ("%s steps targets:" , prefix [:- 1 ])
959
953
for t in tool .tool ["steps" ]:
960
- stdout . write (f" { prefix } { shortname (t ['id' ])} \n " )
954
+ print (f" { prefix } { shortname (t ['id' ])} " , file = stdout )
961
955
run : Union [str , Process , Dict [str , Any ]] = t ["run" ]
962
956
if isinstance (run , str ):
963
957
process = make_tool (run , loading_context )
@@ -1040,20 +1034,20 @@ def main(
1040
1034
)
1041
1035
1042
1036
if args .version :
1043
- print (versionfunc ())
1037
+ print (versionfunc (), file = stdout )
1044
1038
return 0
1045
1039
_logger .info (versionfunc ())
1046
1040
1047
1041
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 )
1049
1043
return 0
1050
1044
1051
1045
if not args .workflow :
1052
1046
if os .path .isfile ("CWLFile" ):
1053
1047
args .workflow = "CWLFile"
1054
1048
else :
1055
1049
_logger .error ("CWL document required, no input file was provided" )
1056
- parser .print_help ()
1050
+ parser .print_help (stderr )
1057
1051
return 1
1058
1052
1059
1053
if args .ga4gh_tool_registries :
@@ -1126,7 +1120,7 @@ def main(
1126
1120
processobj , metadata = loadingContext .loader .resolve_ref (uri )
1127
1121
processobj = cast (Union [CommentedMap , CommentedSeq ], processobj )
1128
1122
if args .pack :
1129
- stdout . write (print_pack (loadingContext , uri ))
1123
+ print (print_pack (loadingContext , uri ), file = stdout )
1130
1124
return 0
1131
1125
1132
1126
if args .provenance and runtimeContext .research_obj :
@@ -1136,29 +1130,45 @@ def main(
1136
1130
)
1137
1131
1138
1132
if args .print_pre :
1139
- stdout . write (
1133
+ print (
1140
1134
json_dumps (
1141
1135
processobj ,
1142
1136
indent = 4 ,
1143
1137
sort_keys = True ,
1144
1138
separators = ("," , ": " ),
1145
1139
default = str ,
1146
- )
1140
+ ),
1141
+ file = stdout ,
1147
1142
)
1148
1143
return 0
1149
1144
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
+
1151
1160
if args .make_template :
1152
1161
make_template (tool )
1153
1162
return 0
1154
1163
1155
1164
if args .validate :
1156
- print (f"{ args .workflow } is valid CWL." )
1165
+ print (f"{ args .workflow } is valid CWL." , file = stdout )
1157
1166
return 0
1158
1167
1159
1168
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 ,
1162
1172
)
1163
1173
return 0
1164
1174
@@ -1194,14 +1204,15 @@ def main(
1194
1204
if args .print_subgraph :
1195
1205
if "name" in tool .tool :
1196
1206
del tool .tool ["name" ]
1197
- stdout . write (
1207
+ print (
1198
1208
json_dumps (
1199
1209
tool .tool ,
1200
1210
indent = 4 ,
1201
1211
sort_keys = True ,
1202
1212
separators = ("," , ": " ),
1203
1213
default = str ,
1204
- )
1214
+ ),
1215
+ file = stdout ,
1205
1216
)
1206
1217
return 0
1207
1218
@@ -1361,8 +1372,10 @@ def loc_to_path(obj: CWLObjectType) -> None:
1361
1372
# Unsetting the Generation from final output object
1362
1373
visit_class (out , ("File" ,), MutationManager ().unset_generation )
1363
1374
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
+ )
1366
1379
if hasattr (stdout , "flush" ):
1367
1380
stdout .flush ()
1368
1381
0 commit comments