@@ -270,6 +270,7 @@ def add_decorator_options(cmd):
270270
271271 seen = {}
272272 existing_params = set (p .name .lower () for p in cmd .params )
273+
273274 # Add decorator options
274275 for deco in flow_decorators (flow_cls ):
275276 for option , kwargs in deco .options .items ():
@@ -290,13 +291,43 @@ def add_decorator_options(cmd):
290291 kwargs ["envvar" ] = "METAFLOW_FLOW_%s" % option .upper ()
291292 seen [option ] = deco .name
292293 cmd .params .insert (0 , click .Option (("--" + option ,), ** kwargs ))
294+
295+ # Add flow mutator options
296+ for mutator in flow_mutators (flow_cls ):
297+ for option , kwargs in mutator .options .items ():
298+ mutator_name = mutator .__class__ .__name__
299+ if option in seen :
300+ msg = (
301+ "Flow mutator '%s' uses an option '%s' which is also "
302+ "used by '%s'. This is a bug in Metaflow. "
303+ "Please file a ticket on GitHub."
304+ % (mutator_name , option , seen [option ])
305+ )
306+ raise MetaflowInternalError (msg )
307+ elif mutator_name .lower () in existing_params :
308+ raise MetaflowInternalError (
309+ "Flow mutator '%s' uses an option '%s' which is a reserved "
310+ "keyword. Please use a different option name."
311+ % (mutator_name , option )
312+ )
313+ else :
314+ kwargs ["envvar" ] = "METAFLOW_FLOW_%s" % option .upper ()
315+ seen [option ] = mutator_name
316+ cmd .params .insert (0 , click .Option (("--" + option ,), ** kwargs ))
317+
293318 return cmd
294319
295320
296321def flow_decorators (flow_cls ):
297322 return [d for deco_list in flow_cls ._flow_decorators .values () for d in deco_list ]
298323
299324
325+ def flow_mutators (flow_cls ):
326+ from metaflow .flowspec import _FlowState
327+
328+ return flow_cls ._flow_state .get (_FlowState .FLOW_MUTATORS , [])
329+
330+
300331class StepDecorator (Decorator ):
301332 """
302333 Base class for all step decorators.
@@ -797,6 +828,7 @@ def _init_step_decorators(
797828 pre_mutate = False ,
798829 statically_defined = deco .statically_defined ,
799830 inserted_by = inserted_by_value ,
831+ mutator = deco ,
800832 )
801833 # Sanity check to make sure we are applying the decorator to the right
802834 # class
0 commit comments