Skip to content

Commit

Permalink
Adds a FlyteDeck markdown renderer to core (flyteorg#2246)
Browse files Browse the repository at this point in the history
* Adds FlyteDeck's markdown renderer to core

Signed-off-by: Thomas J. Fan <[email protected]>

* Deprecated MarkdownRenderer

Signed-off-by: Thomas J. Fan <[email protected]>

---------

Signed-off-by: Thomas J. Fan <[email protected]>
  • Loading branch information
thomasjpfan authored Mar 7, 2024
1 parent 75ef57e commit 64b8468
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 3 deletions.
3 changes: 2 additions & 1 deletion flytekit/deck/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
Deck
TopFrameRenderer
MarkdownRenderer
"""

from .deck import Deck
from .renderer import TopFrameRenderer
from .renderer import MarkdownRenderer, TopFrameRenderer
8 changes: 8 additions & 0 deletions flytekit/deck/renderer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import TYPE_CHECKING, Any

from markdown_it import MarkdownIt
from typing_extensions import Protocol, runtime_checkable

from flytekit import lazy_module
Expand Down Expand Up @@ -48,3 +49,10 @@ class ArrowRenderer:
def to_html(self, df: "pyarrow.Table") -> str:
assert isinstance(df, pyarrow.Table)
return df.to_string()


class MarkdownRenderer:
"""Convert a markdown string to HTML and return HTML as a unicode string."""

def to_html(self, text: str) -> str:
return MarkdownIt().render(text)
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import warnings
from typing import TYPE_CHECKING, List, Optional, Union

from flytekit import lazy_module
Expand Down Expand Up @@ -69,6 +70,10 @@ class MarkdownRenderer:
necessary extensions and runs the parser on the given text.
"""

def __init__(self):
msg = "flytekitplugins.deck.MarkdownRenderer is deprecated. Please use flytekit.deck.MarkdownRenderer instead"
warnings.warn(msg, FutureWarning)

def to_html(self, text: str) -> str:
return markdown.markdown(text)

Expand Down
4 changes: 3 additions & 1 deletion plugins/flytekit-deck-standard/tests/test_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ def test_frame_profiling_renderer():

def test_markdown_renderer():
md_text = "#Hello Flyte\n##Hello Flyte\n###Hello Flyte"
renderer = MarkdownRenderer()

with pytest.warns(FutureWarning):
renderer = MarkdownRenderer()
assert renderer.to_html(md_text) == markdown.markdown(md_text)


Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ dependencies = [
"joblib",
"jsonpickle",
"keyring>=18.0.1",
"markdown-it-py",
"marshmallow-enum",
"marshmallow-jsonschema>=0.12.0",
"mashumaro>=3.9.1",
Expand Down
11 changes: 10 additions & 1 deletion tests/flytekit/unit/deck/test_deck.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
import sys

import pytest
from markdown_it import MarkdownIt
from mock import mock

import flytekit
from flytekit import Deck, FlyteContextManager, task
from flytekit.deck import TopFrameRenderer
from flytekit.deck import MarkdownRenderer, TopFrameRenderer
from flytekit.deck.deck import _output_deck


Expand Down Expand Up @@ -153,3 +154,11 @@ def test_get_deck():
ctx.user_space_params._decks = [ctx.user_space_params.default_deck]
ctx.user_space_params._decks[0] = flytekit.Deck("test", html)
_output_deck("test_task", ctx.user_space_params)


def test_markdown_render():
renderer = MarkdownRenderer()
md_text = "#Hello Flyte\n##Hello Flyte\n###Hello Flyte"

md = MarkdownIt()
assert renderer.to_html(md_text) == md.render(md_text)

0 comments on commit 64b8468

Please sign in to comment.