@@ -30,7 +30,7 @@ class PlanOptions(t.TypedDict):
3030 execution_time : t .NotRequired [TimeLike ]
3131 create_from : t .NotRequired [str ]
3232 skip_tests : t .NotRequired [bool ]
33- restate_models : t .NotRequired [t .Iterable [str ]]
33+ restate_models : t .NotRequired [t .Collection [str ]]
3434 no_gaps : t .NotRequired [bool ]
3535 skip_backfill : t .NotRequired [bool ]
3636 forward_only : t .NotRequired [bool ]
@@ -276,19 +276,57 @@ def run_sqlmesh_thread(
276276
277277 def plan_and_run (
278278 self ,
279+ * ,
280+ select_models : list [str ] | None = None ,
281+ restate_selected : bool = False ,
282+ start : TimeLike | None = None ,
283+ end : TimeLike | None = None ,
279284 categorizer : t .Optional [SnapshotCategorizer ] = None ,
280285 default_catalog : t .Optional [str ] = None ,
281286 plan_options : t .Optional [PlanOptions ] = None ,
282287 run_options : t .Optional [RunOptions ] = None ,
288+ skip_run : bool = False ,
283289 ):
284- run_options = run_options or {}
285- plan_options = plan_options or {}
290+ """Executes a plan and run operation
291+
292+ This is an opinionated interface for running a plan and run operation in
293+ a single thread. It is recommended to use this method for most use cases.
294+ """
295+ run_options = run_options or RunOptions ()
296+ plan_options = plan_options or PlanOptions ()
297+
298+ if plan_options .get ("select_models" ) or run_options .get ("select_models" ):
299+ raise ValueError (
300+ "select_models should not be set in plan_options or run_options use the `select_models` or `select_models_func` arguments instead"
301+ )
302+ if plan_options .get ("restate_models" ):
303+ raise ValueError (
304+ "restate_models should not be set in plan_options use the `restate_selected` argument with `select_models` or `select_models_func` instead"
305+ )
306+ select_models = select_models or []
307+
308+ if start :
309+ plan_options ["start" ] = start
310+ run_options ["start" ] = start
311+ if end :
312+ plan_options ["end" ] = end
313+ run_options ["end" ] = end
314+
315+ if select_models :
316+ if restate_selected :
317+ plan_options ["restate_models" ] = select_models
318+ plan_options ["select_models" ] = select_models
319+ else :
320+ plan_options ["select_models" ] = select_models
321+ run_options ["select_models" ] = select_models
286322
287323 try :
288324 self .logger .debug ("starting sqlmesh plan" )
325+ self .logger .debug (f"selected models: { select_models } " )
289326 yield from self .plan (categorizer , default_catalog , ** plan_options )
290327 self .logger .debug ("starting sqlmesh run" )
291- yield from self .run (** run_options )
328+ if not skip_run :
329+ yield from self .run (** run_options )
292330 except Exception as e :
293331 self .logger .error (f"Error during sqlmesh plan and run: { e } " )
294332 raise e
@@ -442,15 +480,26 @@ def plan(
442480 def plan_and_run (
443481 self ,
444482 environment : str ,
483+ * ,
445484 categorizer : t .Optional [SnapshotCategorizer ] = None ,
485+ select_models : list [str ] | None = None ,
486+ restate_selected : bool = False ,
487+ start : TimeLike | None = None ,
488+ end : TimeLike | None = None ,
446489 default_catalog : t .Optional [str ] = None ,
447490 plan_options : t .Optional [PlanOptions ] = None ,
448491 run_options : t .Optional [RunOptions ] = None ,
492+ skip_run : bool = False ,
449493 ):
450494 with self .instance (environment , "plan_and_run" ) as mesh :
451495 yield from mesh .plan_and_run (
496+ start = start ,
497+ end = end ,
498+ select_models = select_models ,
499+ restate_selected = restate_selected ,
452500 categorizer = categorizer ,
453501 default_catalog = default_catalog ,
454502 plan_options = plan_options ,
455503 run_options = run_options ,
504+ skip_run = skip_run ,
456505 )
0 commit comments