@@ -315,6 +315,86 @@ def run_pipeline(
315
315
pipeline_instance ()
316
316
317
317
318
+ @pipeline .command (
319
+ "create-run-template" ,
320
+ help = "Create a run template for a pipeline. The SOURCE argument needs to "
321
+ "be an importable source path resolving to a ZenML pipeline instance, e.g. "
322
+ "`my_module.my_pipeline_instance`." ,
323
+ )
324
+ @click .argument ("source" )
325
+ @click .option (
326
+ "--name" ,
327
+ "-n" ,
328
+ type = str ,
329
+ required = True ,
330
+ help = "Name for the template" ,
331
+ )
332
+ @click .option (
333
+ "--config" ,
334
+ "-c" ,
335
+ "config_path" ,
336
+ type = click .Path (exists = True , dir_okay = False ),
337
+ required = False ,
338
+ help = "Path to configuration file for the build." ,
339
+ )
340
+ @click .option (
341
+ "--stack" ,
342
+ "-s" ,
343
+ "stack_name_or_id" ,
344
+ type = str ,
345
+ required = False ,
346
+ help = "Name or ID of the stack to use for the build." ,
347
+ )
348
+ def create_run_template (
349
+ source : str ,
350
+ name : str ,
351
+ config_path : Optional [str ] = None ,
352
+ stack_name_or_id : Optional [str ] = None ,
353
+ ) -> None :
354
+ """Create a run template for a pipeline.
355
+
356
+ Args:
357
+ source: Importable source resolving to a pipeline instance.
358
+ name: Name of the run template.
359
+ config_path: Path to pipeline configuration file.
360
+ stack_name_or_id: Name or ID of the stack for which the template should
361
+ be created.
362
+ """
363
+ if not Client ().root :
364
+ cli_utils .warning (
365
+ "You're running the `zenml pipeline create-run-template` command "
366
+ "without a ZenML repository. Your current working directory will "
367
+ "be used as the source root relative to which the registered step "
368
+ "classes will be resolved. To silence this warning, run `zenml "
369
+ "init` at your source code root."
370
+ )
371
+
372
+ try :
373
+ pipeline_instance = source_utils .load (source )
374
+ except ModuleNotFoundError as e :
375
+ source_root = source_utils .get_source_root ()
376
+ cli_utils .error (
377
+ f"Unable to import module `{ e .name } `. Make sure the source path is "
378
+ f"relative to your source root `{ source_root } `."
379
+ )
380
+ except AttributeError as e :
381
+ cli_utils .error ("Unable to load attribute from module: " + str (e ))
382
+
383
+ if not isinstance (pipeline_instance , Pipeline ):
384
+ cli_utils .error (
385
+ f"The given source path `{ source } ` does not resolve to a pipeline "
386
+ "object."
387
+ )
388
+
389
+ with cli_utils .temporary_active_stack (stack_name_or_id = stack_name_or_id ):
390
+ pipeline_instance = pipeline_instance .with_options (
391
+ config_path = config_path
392
+ )
393
+ template = pipeline_instance .create_run_template (name = name )
394
+
395
+ cli_utils .declare (f"Created run template `{ template .id } `." )
396
+
397
+
318
398
@pipeline .command ("list" , help = "List all registered pipelines." )
319
399
@list_options (PipelineFilter )
320
400
def list_pipelines (** kwargs : Any ) -> None :
0 commit comments