Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Mandana Vaziri <[email protected]>
  • Loading branch information
vazirim committed Sep 9, 2024
1 parent 3fca3f0 commit 21cb8be
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
4 changes: 2 additions & 2 deletions pdl/pdl_interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@
from .pdl_location_utils import append, get_loc_string
from .pdl_parser import PDLParseError, parse_file
from .pdl_scheduler import (
CodeYieldResultMessage,
ModelCallMessage,
ModelYieldResultMessage,
YieldBackgroundMessage,
YieldMessage,
YieldResultMessage,
CodeYieldResultMessage,
ModelYieldResultMessage,
schedule,
)
from .pdl_schema_validator import type_check_args, type_check_spec
Expand Down
8 changes: 6 additions & 2 deletions pdl/pdl_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ def step_to_completion(gen: Generator[Any, Any, GeneratorReturnT]) -> GeneratorR
pass
return w.value


MODEL_COLOR = "\033[92m" # Green
CODE_COLOR = "\033[95m" # Purple
END_COLOR = "\033[0m" # End color
NO_COLOR = ""


class MessageKind(Enum):
Expand All @@ -57,7 +59,7 @@ class YieldMessage:
@dataclass
class YieldResultMessage(YieldMessage):
kind = MessageKind.RESULT
color = None
color = NO_COLOR
result: Any


Expand Down Expand Up @@ -107,7 +109,9 @@ def schedule(
try:
msg = gen.send(v)
match msg:
case ModelYieldResultMessage(result=result) | CodeYieldResultMessage(result=result):
case ModelYieldResultMessage(
result=result
) | CodeYieldResultMessage(result=result):
print(msg.color + stringify(result) + END_COLOR, end="")
todo_next.append((i, gen, None))
case YieldResultMessage(result=result):
Expand Down
2 changes: 2 additions & 0 deletions tests/test_line_table.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from pdl.pdl_interpreter import generate
from pdl.pdl_scheduler import CODE_COLOR, END_COLOR, MODEL_COLOR


def do_test(t, capsys):
generate(t["file"], None, None, {}, None)
captured = capsys.readouterr()
Expand All @@ -9,6 +10,7 @@ def do_test(t, capsys):
print(output)
assert set(output) == set(t["errors"])


def remove_coloring(text):
return text.replace(MODEL_COLOR, "").replace(CODE_COLOR, "").replace(END_COLOR, "")

Expand Down

0 comments on commit 21cb8be

Please sign in to comment.