Skip to content

Commit f5b1502

Browse files
authored
[Ready for Review] Make TOGGLE_DECOSPECS only add default decorator once. (#2097)
* do not let default decospec overwrite existing --with updat econfig merge add more temp code * change to default_decospecs * remove unnecessary space * avoid dup deco * fix card initialization * update decospecs insert time * update to DEFAULT_DECOSPECS * update according to comments * update according to comments
1 parent e8efc78 commit f5b1502

File tree

3 files changed

+23
-26
lines changed

3 files changed

+23
-26
lines changed

metaflow/cli.py

-22
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
from .flowspec import _FlowState
1717
from .graph import FlowGraph
1818
from .metaflow_config import (
19-
DECOSPECS,
2019
DEFAULT_DATASTORE,
2120
DEFAULT_ENVIRONMENT,
2221
DEFAULT_EVENT_LOGGER,
@@ -106,26 +105,6 @@ def logger(body="", system_msg=False, head="", bad=False, timestamp=True, nl=Tru
106105
click.secho(body, bold=system_msg, fg=LOGGER_BAD_COLOR if bad else None, nl=nl)
107106

108107

109-
def config_merge_cb(ctx, param, value):
110-
# Callback to:
111-
# - read the Click auto_envvar variable from both the
112-
# environment AND the configuration
113-
# - merge that value with the value passed in the command line (value)
114-
# - return the value as a tuple
115-
# Note that this function gets called even if there is no option passed on the
116-
# command line.
117-
# NOTE: Assumes that ctx.auto_envvar_prefix is set to METAFLOW (same as in
118-
# from_conf)
119-
120-
# Special case where DECOSPECS and value are the same. This happens
121-
# when there is no --with option at the TL and DECOSPECS is read from
122-
# the env var. In this case, click also passes it as value
123-
splits = DECOSPECS.split()
124-
if len(splits) == len(value) and all([a == b for (a, b) in zip(splits, value)]):
125-
return value
126-
return tuple(list(value) + DECOSPECS.split())
127-
128-
129108
@click.group(
130109
cls=LazyGroup,
131110
lazy_subcommands={
@@ -284,7 +263,6 @@ def version(obj):
284263
multiple=True,
285264
help="Add a decorator to all steps. You can specify this option "
286265
"multiple times to attach multiple decorators in steps.",
287-
callback=config_merge_cb,
288266
)
289267
@click.option(
290268
"--pylint/--no-pylint",

metaflow/cli_components/run_cmds.py

+19
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from ..exception import CommandException
99
from ..graph import FlowGraph
1010
from ..metaflow_current import current
11+
from ..metaflow_config import DEFAULT_DECOSPECS
1112
from ..package import MetaflowPackage
1213
from ..runtime import NativeRuntime
1314
from ..system import _system_logger
@@ -70,6 +71,23 @@ def write_file(file_path, content):
7071
f.write(str(content))
7172

7273

74+
def config_merge_cb(ctx, param, value):
75+
# Callback to:
76+
# - read the Click auto_envvar variable from both the
77+
# environment AND the configuration
78+
# - merge that value with the value passed in the command line (value)
79+
# - return the value as a tuple
80+
# Note that this function gets called even if there is no option passed on the
81+
# command line.
82+
# NOTE: Assumes that ctx.auto_envvar_prefix is set to METAFLOW (same as in
83+
# from_conf)
84+
85+
# Read decospecs options from the environment (METAFLOW_DEFAULT_DECOSPECS=...)
86+
# and merge them with the one provided as --with.
87+
splits = DEFAULT_DECOSPECS.split()
88+
return tuple(list(value) + splits)
89+
90+
7391
def common_run_options(func):
7492
@click.option(
7593
"--tag",
@@ -109,6 +127,7 @@ def common_run_options(func):
109127
help="Add a decorator to all steps. You can specify this "
110128
"option multiple times to attach multiple decorators "
111129
"in steps.",
130+
callback=config_merge_cb,
112131
)
113132
@click.option(
114133
"--run-id-file",

metaflow/metaflow_config.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@
284284
###
285285
# Format is a space separated string of decospecs (what is passed
286286
# using --with)
287-
DECOSPECS = from_conf("DECOSPECS", "")
287+
DEFAULT_DECOSPECS = from_conf("DEFAULT_DECOSPECS", "")
288288

289289
###
290290
# AWS Batch configuration
@@ -577,9 +577,9 @@ def _new_get_pinned_conda_libs(
577577
_TOGGLE_DECOSPECS.extend(o)
578578
elif not n.startswith("__") and not isinstance(o, types.ModuleType):
579579
globals()[n] = o
580-
# If DECOSPECS is set, use that, else extrapolate from extensions
581-
if not DECOSPECS:
582-
DECOSPECS = " ".join(_TOGGLE_DECOSPECS)
580+
# If DEFAULT_DECOSPECS is set, use that, else extrapolate from extensions
581+
if not DEFAULT_DECOSPECS:
582+
DEFAULT_DECOSPECS = " ".join(_TOGGLE_DECOSPECS)
583583

584584
finally:
585585
# Erase all temporary names to avoid leaking things

0 commit comments

Comments
 (0)