Skip to content

Commit

Permalink
Make cards work well with configs
Browse files Browse the repository at this point in the history
  • Loading branch information
romain-intel committed Dec 17, 2024
1 parent 7c1922e commit d6a6318
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions metaflow/plugins/cards/card_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ def _run_cards_subprocess(
executable,
sys.argv[0],
]

cmd += self._top_level_options + [
"card",
"create",
Expand Down
22 changes: 19 additions & 3 deletions metaflow/plugins/cards/card_decorator.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from metaflow.decorators import StepDecorator
from metaflow.metaflow_current import current
from metaflow.user_configs.config_options import ConfigInput
from metaflow.util import to_unicode
from .component_serializer import CardComponentCollector, get_card_class
from .card_creator import CardCreator
Expand Down Expand Up @@ -111,6 +112,14 @@ def step_init(
self._logger = logger
self.card_options = None

# We check for configuration options. We do this here before they are
# converted to properties.
self._config_values = [
(config.name, ConfigInput.make_key_name(config.name))
for _, config in flow._get_parameters()
if config.IS_CONFIG_PARAMETER
]

self.card_options = self.attributes["options"]

evt_name = "step-init"
Expand Down Expand Up @@ -179,7 +188,7 @@ def task_pre_step(
# we need to ensure that `current.card` has `CardComponentCollector` instantiated only once.
if not self._is_event_registered("pre-step"):
self._register_event("pre-step")
self._set_card_creator(CardCreator(self._create_top_level_args()))
self._set_card_creator(CardCreator(self._create_top_level_args(flow)))

current._update_env(
{"card": CardComponentCollector(self._logger, self.card_creator)}
Expand Down Expand Up @@ -232,9 +241,13 @@ def _options(mapping):
for value in v:
yield "--%s" % k
if not isinstance(value, bool):
yield to_unicode(value)
if isinstance(value, tuple):
for val in value:
yield to_unicode(val)
else:
yield to_unicode(value)

def _create_top_level_args(self):
def _create_top_level_args(self, flow):
top_level_options = {
"quiet": True,
"metadata": self._metadata.TYPE,
Expand All @@ -247,4 +260,7 @@ def _create_top_level_args(self):
# We don't provide --with as all execution is taking place in
# the context of the main process
}
if self._config_values:
top_level_options["config-value"] = self._config_values

return list(self._options(top_level_options))

0 comments on commit d6a6318

Please sign in to comment.