Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update _process_stdout within SlingResource to handle Emojis #27241

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions python_modules/libraries/dagster-sling/dagster_sling/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,27 @@ def _clean_line(self, line: str) -> str:

def _process_stdout(self, stdout: IO[AnyStr], encoding="utf8") -> Iterator[str]:
"""Process stdout from the Sling CLI."""
emoji_pattern = re.compile(
"["
"\U0001f600-\U0001f64f" # emoticons
"\U0001f300-\U0001f5ff" # symbols & pictographs
"\U0001f680-\U0001f6ff" # transport & map symbols
"\U0001f700-\U0001f77f" # alchemical symbols
"\U0001f780-\U0001f7ff" # Geometric Shapes Extended
"\U0001f800-\U0001f8ff" # Supplemental Arrows-C
"\U0001f900-\U0001f9ff" # Supplemental Symbols and Pictographs
"\U0001fa00-\U0001fa6f" # Chess Symbols
"\U0001fa70-\U0001faff" # Symbols and Pictographs Extended-A
"\U00002702-\U000027b0" # Dingbats
"\U000024c2-\U0001f251"
"]+",
flags=re.UNICODE,
)

for line in stdout:
assert isinstance(line, bytes)
fmt_line = bytes.decode(line, encoding=encoding, errors="replace")
fmt_line = emoji_pattern.sub(r"", fmt_line)
yield self._clean_line(fmt_line)

def _exec_sling_cmd(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import io

import pytest
from dagster import AssetKey, AutoMaterializePolicy, FreshnessPolicy, JsonMetadataValue
from dagster_sling import SlingResource
from dagster_sling.dagster_sling_translator import DagsterSlingTranslator


Expand Down Expand Up @@ -152,3 +155,23 @@ def test_freshness_policy_from_get_asset_spec(stream, expected):
def test_auto_materialize_policy_from_get_asset_spec(stream, expected):
translator = DagsterSlingTranslator()
assert translator.get_asset_spec(stream).auto_materialize_policy == expected


def test_process_stdout():
# Example stdout containing a variety of emojis and text
example_stdout = io.BytesIO(
b"Hello World\xf0\x9f\x91\x8b\n" # Wave emoji
b"Does this line have an emoji?\xf0\x9f\x91\x94\n" # Thinking emoji
b"It should not have one if you ask me\xf0\x9f\x99\x87\n" # Shrugging emoji
b"It was the pointing finger emoji that caused trouble!\xf0\x9f\x91\x89\n" # Pointing right emoji
)

sling_resource = SlingResource(connections=[])
processed_lines = [line.strip() for line in sling_resource._process_stdout(example_stdout)] # noqa: SLF001

assert processed_lines == [
"Hello World",
"Does this line have an emoji?",
"It should not have one if you ask me",
"It was the pointing finger emoji that caused trouble!",
]