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

fix merge for ci from pr-186 #229

Merged
merged 1 commit into from
Dec 22, 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
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