Add Runnable.get_graph() to get a graph representation of a Runnable (#15040)

It can be drawn in ascii with Runnable.get_graph().draw()
This commit is contained in:
Nuno Campos
2023-12-22 11:40:45 -08:00
committed by GitHub
parent aad3d8bd47
commit 7d5800ee51
12 changed files with 739 additions and 27 deletions

View File

@@ -12,6 +12,7 @@ from typing import (
List,
Mapping,
Optional,
Sequence,
Type,
TypeVar,
Union,
@@ -163,6 +164,9 @@ class ContextGet(RunnableSerializable):
key: Union[str, List[str]]
def __str__(self) -> str:
return f"ContextGet({_print_keys(self.key)})"
@property
def ids(self) -> List[str]:
prefix = self.prefix + "/" if self.prefix else ""
@@ -243,6 +247,9 @@ class ContextSet(RunnableSerializable):
prefix=prefix,
)
def __str__(self) -> str:
return f"ContextSet({_print_keys(list(self.keys.keys()))})"
@property
def ids(self) -> List[str]:
prefix = self.prefix + "/" if self.prefix else ""
@@ -345,3 +352,10 @@ class PrefixContext:
**kwargs: SetValue,
) -> ContextSet:
return ContextSet(_key, _value, prefix=self.prefix, **kwargs)
def _print_keys(keys: Union[str, Sequence[str]]) -> str:
if isinstance(keys, str):
return f"'{keys}'"
else:
return ", ".join(f"'{k}'" for k in keys)