5555 fetch_document ,
5656 jobloaderctx ,
5757 load_overrides ,
58+ load_tool ,
5859 make_tool ,
5960 resolve_and_validate_document ,
6061 resolve_overrides ,
@@ -776,72 +777,76 @@ def inherit_reqshints(tool: Process, parent: Process) -> None:
776777 found = True
777778 break
778779 if not found :
779- tool .hints .append (parent_req )
780+ tool .hints .append (parent_hint )
780781
781782
782783def choose_target (
783784 args : argparse .Namespace ,
784785 tool : Process ,
785- loadingContext : LoadingContext ,
786+ loading_context : LoadingContext ,
786787) -> Optional [Process ]:
787788 """Walk the Workflow, extract the subset matches all the args.targets."""
788- if loadingContext .loader is None :
789- raise Exception ("loadingContext .loader cannot be None" )
789+ if loading_context .loader is None :
790+ raise Exception ("loading_context .loader cannot be None" )
790791
791792 if isinstance (tool , Workflow ):
792793 url = urllib .parse .urlparse (tool .tool ["id" ])
793794 if url .fragment :
794795 extracted = get_subgraph (
795- [tool .tool ["id" ] + "/" + r for r in args .target ], tool
796+ [tool .tool ["id" ] + "/" + r for r in args .target ], tool , loading_context
796797 )
797798 else :
798799 extracted = get_subgraph (
799800 [
800- loadingContext .loader .fetcher .urljoin (tool .tool ["id" ], "#" + r )
801+ loading_context .loader .fetcher .urljoin (tool .tool ["id" ], "#" + r )
801802 for r in args .target
802803 ],
803804 tool ,
805+ loading_context ,
804806 )
805807 else :
806808 _logger .error ("Can only use --target on Workflows" )
807809 return None
808- if isinstance (loadingContext .loader .idx , MutableMapping ):
809- loadingContext .loader .idx [extracted ["id" ]] = extracted
810- tool = make_tool (extracted ["id" ], loadingContext )
810+ if isinstance (loading_context .loader .idx , MutableMapping ):
811+ loading_context .loader .idx [extracted ["id" ]] = extracted
812+ tool = make_tool (extracted ["id" ], loading_context )
811813 else :
812- raise Exception ("Missing loadingContext .loader.idx!" )
814+ raise Exception ("Missing loading_context .loader.idx!" )
813815
814816 return tool
815817
816818
817819def choose_step (
818820 args : argparse .Namespace ,
819821 tool : Process ,
820- loadingContext : LoadingContext ,
822+ loading_context : LoadingContext ,
821823) -> Optional [Process ]:
822824 """Walk the given Workflow and extract just args.single_step."""
823- if loadingContext .loader is None :
824- raise Exception ("loadingContext .loader cannot be None" )
825+ if loading_context .loader is None :
826+ raise Exception ("loading_context .loader cannot be None" )
825827
826828 if isinstance (tool , Workflow ):
827829 url = urllib .parse .urlparse (tool .tool ["id" ])
828830 if url .fragment :
829- extracted = get_step (tool , tool .tool ["id" ] + "/" + args .single_step )
831+ extracted = get_step (
832+ tool , tool .tool ["id" ] + "/" + args .single_step , loading_context
833+ )
830834 else :
831835 extracted = get_step (
832836 tool ,
833- loadingContext .loader .fetcher .urljoin (
837+ loading_context .loader .fetcher .urljoin (
834838 tool .tool ["id" ], "#" + args .single_step
835839 ),
840+ loading_context ,
836841 )
837842 else :
838843 _logger .error ("Can only use --single-step on Workflows" )
839844 return None
840- if isinstance (loadingContext .loader .idx , MutableMapping ):
841- loadingContext .loader .idx [extracted ["id" ]] = extracted
842- tool = make_tool (extracted ["id" ], loadingContext )
845+ if isinstance (loading_context .loader .idx , MutableMapping ):
846+ loading_context .loader .idx [extracted ["id" ]] = extracted
847+ tool = make_tool (extracted ["id" ], loading_context )
843848 else :
844- raise Exception ("Missing loadingContext .loader.idx!" )
849+ raise Exception ("Missing loading_context .loader.idx!" )
845850
846851 return tool
847852
@@ -866,7 +871,7 @@ def choose_process(
866871 extracted , step_pos = get_process (
867872 tool ,
868873 step_id ,
869- loadingContext . loader . idx ,
874+ loadingContext ,
870875 )
871876 else :
872877 _logger .error ("Can only use --single-process on Workflows" )
@@ -909,6 +914,33 @@ def check_working_directories(
909914 return None
910915
911916
917+ def print_targets (
918+ tool : Process ,
919+ stdout : Union [TextIO , StreamWriter ],
920+ loading_context : LoadingContext ,
921+ prefix : str = "" ,
922+ ) -> None :
923+ """Recursively find targets for --subgraph and friends."""
924+ for f in ("outputs" , "inputs" ):
925+ if tool .tool [f ]:
926+ _logger .info ("%s %s%s targets:" , prefix [:- 1 ], f [0 ].upper (), f [1 :- 1 ])
927+ stdout .write (
928+ " "
929+ + "\n " .join ([f"{ prefix } { shortname (t ['id' ])} " for t in tool .tool [f ]])
930+ + "\n "
931+ )
932+ if "steps" in tool .tool :
933+ _logger .info ("%s steps targets:" , prefix [:- 1 ])
934+ for t in tool .tool ["steps" ]:
935+ stdout .write (f" { prefix } { shortname (t ['id' ])} \n " )
936+ run : Union [str , Process ] = t ["run" ]
937+ if isinstance (run , str ):
938+ process = load_tool (run , loading_context )
939+ else :
940+ process = run
941+ print_targets (process , stdout , loading_context , shortname (t ["id" ]) + "/" )
942+
943+
912944def main (
913945 argsl : Optional [List [str ]] = None ,
914946 args : Optional [argparse .Namespace ] = None ,
@@ -1106,14 +1138,7 @@ def main(
11061138 return 0
11071139
11081140 if args .print_targets :
1109- for f in ("outputs" , "steps" , "inputs" ):
1110- if tool .tool [f ]:
1111- _logger .info ("%s%s targets:" , f [0 ].upper (), f [1 :- 1 ])
1112- stdout .write (
1113- " "
1114- + "\n " .join ([shortname (t ["id" ]) for t in tool .tool [f ]])
1115- + "\n "
1116- )
1141+ print_targets (tool , stdout , loadingContext )
11171142 return 0
11181143
11191144 if args .target :
0 commit comments