Skip to content

Commit

Permalink
[card-core][MET-104] revert MetaflowCard.render signature to original
Browse files Browse the repository at this point in the history
- Introduced a `runtime_data` property that has access to the final data object when `render` is called.
- Remove the usage of `inspect`
  • Loading branch information
valayDave committed Nov 21, 2023
1 parent 2484871 commit 993d6f0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 24 deletions.
37 changes: 15 additions & 22 deletions metaflow/plugins/cards/card_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import json
import uuid
import signal
import inspect
import random
from contextlib import contextmanager
from functools import wraps
Expand Down Expand Up @@ -427,7 +426,7 @@ def update_card(mf_card, mode, task, data, timeout_value=None):
"""

def _reload_token():
if data is None or "render_seq" not in data:
if "render_seq" not in data:
return "never"

if data["render_seq"] == "final":
Expand Down Expand Up @@ -461,27 +460,21 @@ def _safe_call_function(func, *args, **kwargs):
return None, False

def _call():
# check compatibility with old render()-method that doesn't accept the data arg
new_render = "data" in inspect.getfullargspec(mf_card.render).args
if mode == "render":
if new_render:
output = _add_token_html(mf_card.render(task, data))
return CardRenderInfo(
mode=mode,
is_implemented=True,
data=output,
timed_out=False,
timeout_stack_trace=None,
)
else:
output = _add_token_html(mf_card.render(task))
return CardRenderInfo(
mode=mode,
is_implemented=True,
data=output,
timed_out=False,
timeout_stack_trace=None,
)
setattr(
mf_card.__class__,
"runtime_data",
property(fget=lambda _, data=data: data),
)
output = _add_token_html(mf_card.render(task))
return CardRenderInfo(
mode=mode,
is_implemented=True,
data=output,
timed_out=False,
timeout_stack_trace=None,
)

elif mode == "render_runtime":
# Since many cards created by metaflow users may not have implemented a
# `render_time` / `refresh` methods, it can result in an exception and thereby
Expand Down
6 changes: 4 additions & 2 deletions metaflow/plugins/cards/card_modules/card.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ class MetaflowCard(object):

scope = "task" # can be task | run

# FIXME document runtime_data
runtime_data = None

def __init__(self, options={}, components=[], graph=None):
pass

Expand All @@ -74,8 +77,7 @@ def _get_mustache(self):
except ImportError:
return None

# FIXME document data
def render(self, task, data=None) -> str:
def render(self, task) -> str:
"""
Produce custom card contents in HTML.
Expand Down

0 comments on commit 993d6f0

Please sign in to comment.