metaflow icon indicating copy to clipboard operation
metaflow copied to clipboard

Make it possible to disable certain options

Open tuulos opened this issue 3 years ago • 1 comments

A system administrator may want to disable an option, e.g. --max-workers to enforce a system-wide setting. We could provide a way to disable selected options, or override any settings globally.

Context: https://outerbounds-community.slack.com/archives/C02116BBNTU/p1643346664124169

tuulos avatar Jan 28 '22 06:01 tuulos

Thanks for opening this issue @tuulos.

In the meantime, I'll share a solution that worked for me. Adding a decorator on the flow that removed unwanted cli options:

def drop_cli_args(*arguments):
    def decorator(pipeline):
        def wrapper():
            for arg in arguments:
                if arg in sys.argv:
                    ind = sys.argv.index(arg)
                    sys.argv.pop(ind) # drop the arg
                    sys.argv.pop(ind) # drop the val
            return pipeline()
        return wrapper
    return decorator

@drop_cli_args("--max-workers")
class MFPipeline(FlowSpec):
....

In the above example, the user will not be able to override the max-workers system default as the --max-workers flag will be dropped before the flow is called. To do the same for other system defaults, you can just add more arguments to the decorator e.g. @drop_cli_args("--max-workers", "--max-num-splits")

p.s. I am yet to test this in production trying this out locally works fine.

MusHusKat avatar Jan 28 '22 07:01 MusHusKat