2020 WorkflowInputParameter ,
2121 WorkflowStep ,
2222)
23+ from cwl_utils .parser .utils import load_inputfile
2324from rich import print_json
2425from rich .console import Console
2526from schema_salad .exceptions import ValidationException
7475@app .command ("submit" )
7576def submit_production_client (
7677 task_path : str = typer .Argument (..., help = "Path to the CWL file" ),
78+ inputs_file : str | None = typer .Option (None , help = "Path to the CWL inputs file" ),
79+ chunk : str | None = typer .Option (None , help = "Split an array input into jobs: PARAM=SIZE (e.g., input-data=3)" ),
7780 # Specific parameter for the purpose of the prototype
7881 local : Optional [bool ] = typer .Option (True , help = "Run the job locally instead of submitting it to the router" ),
7982):
@@ -86,10 +89,49 @@ def submit_production_client(
8689 """
8790 os .environ ["DIRAC_PROTO_LOCAL" ] = "0"
8891
92+ # --chunk and --inputs-file must be used together
93+ if chunk and not inputs_file :
94+ console .print ("[red]:heavy_multiplication_x:[/red] [bold]CLI:[/bold] --chunk requires --inputs-file." )
95+ return typer .Exit (code = 1 )
96+ if inputs_file and not chunk :
97+ console .print ("[red]:heavy_multiplication_x:[/red] [bold]CLI:[/bold] --inputs-file requires --chunk." )
98+ return typer .Exit (code = 1 )
99+
89100 # Validate the workflow
90101 console .print ("[blue]:information_source:[/blue] [bold]CLI:[/bold] Validating the production..." )
91102 try :
92103 task = load_document (pack (task_path ))
104+
105+ # Load Production inputs and inject into the first step's hint
106+ if inputs_file and chunk :
107+ from dirac_cwl .transformation import _parse_chunk
108+
109+ all_inputs = load_inputfile (task .cwlVersion , inputs_file )
110+ chunk_param , chunk_size = _parse_chunk (chunk )
111+
112+ if chunk_param not in all_inputs :
113+ console .print (
114+ f"[red]:heavy_multiplication_x:[/red] [bold]CLI:[/bold] "
115+ f"Parameter '{ chunk_param } ' not found in inputs file. "
116+ f"Available parameters: { list (all_inputs .keys ())} "
117+ )
118+ return typer .Exit (code = 1 )
119+ if not isinstance (all_inputs [chunk_param ], list ):
120+ console .print (
121+ f"[red]:heavy_multiplication_x:[/red] [bold]CLI:[/bold] "
122+ f"Parameter '{ chunk_param } ' must be an array type for --chunk."
123+ )
124+ return typer .Exit (code = 1 )
125+
126+ input_data = {chunk_param : all_inputs [chunk_param ]}
127+
128+ # Inject into the first step's hint
129+ if task .steps :
130+ from dirac_cwl .execution_hooks import TransformationExecutionHooksHint
131+
132+ hint_update = TransformationExecutionHooksHint (group_size = chunk_size , input_data = input_data )
133+ TransformationExecutionHooksHint .update_cwl (task .steps [0 ].run , hint_update )
134+
93135 except FileNotFoundError as ex :
94136 console .print (f"[red]:heavy_multiplication_x:[/red] [bold]CLI:[/bold] Failed to load the task:\n { ex } " )
95137 return typer .Exit (code = 1 )
@@ -99,11 +141,10 @@ def submit_production_client(
99141 console .print (f"\t [green]:heavy_check_mark:[/green] Task { task_path } " )
100142 console .print ("\t [green]:heavy_check_mark:[/green] Metadata" )
101143
102- # Create the production
103144 production = ProductionSubmissionModel (task = task )
104145 console .print ("[green]:heavy_check_mark:[/green] [bold]CLI:[/bold] Production validated." )
105146
106- # Submit the tranaformation
147+ # Submit the transformation
107148 console .print ("[blue]:information_source:[/blue] [bold]CLI:[/bold] Submitting the production..." )
108149 print_json (production .model_dump_json (indent = 4 ))
109150 if not submit_production_router (production ):
@@ -161,12 +202,7 @@ def _get_transformations(
161202
162203 for step in production .task .steps :
163204 step_task = _create_subworkflow (step , str (production .task .cwlVersion ), production .task .inputs )
164-
165- transformations .append (
166- TransformationSubmissionModel (
167- task = step_task ,
168- )
169- )
205+ transformations .append (TransformationSubmissionModel (task = step_task ))
170206 return transformations
171207
172208
0 commit comments