Skip to content

Commit

Permalink
fix merge for ci from pr-186
Browse files Browse the repository at this point in the history
  • Loading branch information
zswang666 committed Dec 22, 2024
1 parent 3201b23 commit fc51cde
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
8 changes: 6 additions & 2 deletions genesis/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ def _repr_elem(self, elem, common_length=0):
def _repr_elem_colorized(self, elem, common_length=0):
content = self._repr_elem(elem, common_length)
idx = content.find(">")
formatted_content = f"{colors.BLUE}{formats.ITALIC}{content[:idx+1]}{formats.RESET}{content[idx+1:]}"
formatted_content = f"{colors.BLUE}{formats.ITALIC}{content[:idx + 1]}{formats.RESET}{content[idx + 1:]}"
idx = formatted_content.find(":")
if idx >= 0:
formatted_content = f"{formatted_content[:idx]}{colors.GRAY}:{colors.MINT}{formatted_content[idx+1:]}"
formatted_content = f"{formatted_content[:idx]}{colors.GRAY}:{colors.MINT}{formatted_content[idx + 1:]}"
formatted_content += formats.RESET
return formatted_content

Expand Down Expand Up @@ -73,6 +73,10 @@ def _repr_brief(self):
return repr_str

def __repr__(self):
if not __debug__:
self.__colorized__repr__()

def __colorized__repr__(self):
repr_str = f"{colors.BLUE}{self._repr_type()}(len={colors.MINT}{formats.UNDERLINE}{len(self)}{formats.RESET}{colors.BLUE}, ["

if len(self) == 0:
Expand Down
8 changes: 6 additions & 2 deletions genesis/options/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,15 @@ def copy_attributes_from(self, options, override=False):
def _repr_type(cls):
return f"<{cls.__module__}.{cls.__qualname__}>".replace("genesis", "gs")

def __repr__(self) -> str:
def __repr__(self):
if not __debug__:
self.__colorized__repr__()

def __colorized__repr__(self) -> str:
property_attrs = self.__dict__.keys()
max_attr_len = max([len(attr) for attr in property_attrs])

repr_str = f"{colors.CORN}{'─'*(max_attr_len + 3)} {formats.BOLD}{formats.ITALIC}{self._repr_type()}{formats.RESET} {colors.CORN}{'─' * (max_attr_len + 3)}\n"
repr_str = f"{colors.CORN}{'─' * (max_attr_len + 3)} {formats.BOLD}{formats.ITALIC}{self._repr_type()}{formats.RESET} {colors.CORN}{'─' * (max_attr_len + 3)}\n"

for attr in property_attrs:
formatted_str = f"{colors.BLUE}'{attr}'{formats.RESET}"
Expand Down
10 changes: 7 additions & 3 deletions genesis/repr_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ def _repr_brief(self):
repr_str += f", material: {self.material}"
return repr_str

def __repr__(self) -> str:
def __repr__(self):
if not __debug__:
self.__colorized__repr__()

def __colorized__repr__(self) -> str:
all_attrs = self.__dir__()
property_attrs = []

Expand All @@ -55,7 +59,7 @@ def __repr__(self) -> str:
continue
idx = content.find(">")
# format with italic and color
formatted_content = f"{colors.MINT}{formats.ITALIC}{content[:idx+1]}{formats.RESET}{colors.MINT}{content[idx+1:]}{formats.RESET}"
formatted_content = f"{colors.MINT}{formats.ITALIC}{content[:idx + 1]}{formats.RESET}{colors.MINT}{content[idx + 1:]}{formats.RESET}"
# in case it's multi-line
if isinstance(getattr(self, attr), gs.List):
# 4 = 2 x ' + : + space
Expand All @@ -81,7 +85,7 @@ def __repr__(self) -> str:
right_line_len = max(right_line_len, min_line_len)

repr_str = (
f"{colors.CORN}{'─'*left_line_len} {formats.BOLD}{formats.ITALIC}{self._repr_type()}{formats.RESET} {colors.CORN}{'─'*right_line_len}\n"
f"{colors.CORN}{'─' * left_line_len} {formats.BOLD}{formats.ITALIC}{self._repr_type()}{formats.RESET} {colors.CORN}{'─' * right_line_len}\n"
+ repr_str
)

Expand Down

1 comment on commit fc51cde

@ashnasri
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i really appreciate you

Please sign in to comment.