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

add component.Info() support lists #2338

Merged
merged 5 commits into from
Jul 25, 2024
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Vector-search vector-loading bug fixed
- Bugs related to new queuing paradigm
- Remove --user from make install_devkit as it supposed to run on a virtualenv.
- component info support list

## [0.3.0](https://github.com/superduper-io/superduper/compare/0.3.0...0.2.0]) (2024-Jun-21)

Expand Down
22 changes: 20 additions & 2 deletions superduper/misc/special_dicts.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,16 +408,34 @@ def _display_component(obj, verbosity=1):

console = Console()

MAX_STR_LENGTH = 50

def _handle_list(lst):
handled_list = []
for item in lst:
if isinstance(item, Leaf):
if len(str(item)) > MAX_STR_LENGTH:
handled_list.append(str(item)[:MAX_STR_LENGTH] + "...")
else:
handled_list.append(str(item))
elif isinstance(item, (list, tuple)):
handled_list.append(_handle_list(item))
else:
handled_list.append(str(item))
return handled_list

def _component_info(obj):
base_component = []
for key, value in obj.__dict__.items():
if value is None:
continue
if isinstance(value, Leaf):
if len(str(value)) > 50:
value = str(value)[:50] + "..."
if len(str(value)) > MAX_STR_LENGTH:
value = str(value)[:MAX_STR_LENGTH] + "..."
else:
value = str(value)
elif isinstance(value, (tuple, list)):
value = _handle_list(value)
base_component.append(f"[magenta]{key}[/magenta]: [blue]{value}[/blue]")

base_component = "\n".join(base_component)
Expand Down
Loading