Skip to content

Commit fc51cde

Browse files
committed
fix merge for ci from pr-186
1 parent 3201b23 commit fc51cde

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

genesis/datatypes.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ def _repr_elem(self, elem, common_length=0):
4242
def _repr_elem_colorized(self, elem, common_length=0):
4343
content = self._repr_elem(elem, common_length)
4444
idx = content.find(">")
45-
formatted_content = f"{colors.BLUE}{formats.ITALIC}{content[:idx+1]}{formats.RESET}{content[idx+1:]}"
45+
formatted_content = f"{colors.BLUE}{formats.ITALIC}{content[:idx + 1]}{formats.RESET}{content[idx + 1:]}"
4646
idx = formatted_content.find(":")
4747
if idx >= 0:
48-
formatted_content = f"{formatted_content[:idx]}{colors.GRAY}:{colors.MINT}{formatted_content[idx+1:]}"
48+
formatted_content = f"{formatted_content[:idx]}{colors.GRAY}:{colors.MINT}{formatted_content[idx + 1:]}"
4949
formatted_content += formats.RESET
5050
return formatted_content
5151

@@ -73,6 +73,10 @@ def _repr_brief(self):
7373
return repr_str
7474

7575
def __repr__(self):
76+
if not __debug__:
77+
self.__colorized__repr__()
78+
79+
def __colorized__repr__(self):
7680
repr_str = f"{colors.BLUE}{self._repr_type()}(len={colors.MINT}{formats.UNDERLINE}{len(self)}{formats.RESET}{colors.BLUE}, ["
7781

7882
if len(self) == 0:

genesis/options/options.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,15 @@ def copy_attributes_from(self, options, override=False):
4343
def _repr_type(cls):
4444
return f"<{cls.__module__}.{cls.__qualname__}>".replace("genesis", "gs")
4545

46-
def __repr__(self) -> str:
46+
def __repr__(self):
47+
if not __debug__:
48+
self.__colorized__repr__()
49+
50+
def __colorized__repr__(self) -> str:
4751
property_attrs = self.__dict__.keys()
4852
max_attr_len = max([len(attr) for attr in property_attrs])
4953

50-
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"
54+
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"
5155

5256
for attr in property_attrs:
5357
formatted_str = f"{colors.BLUE}'{attr}'{formats.RESET}"

genesis/repr_base.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ def _repr_brief(self):
3131
repr_str += f", material: {self.material}"
3232
return repr_str
3333

34-
def __repr__(self) -> str:
34+
def __repr__(self):
35+
if not __debug__:
36+
self.__colorized__repr__()
37+
38+
def __colorized__repr__(self) -> str:
3539
all_attrs = self.__dir__()
3640
property_attrs = []
3741

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

8387
repr_str = (
84-
f"{colors.CORN}{'─'*left_line_len} {formats.BOLD}{formats.ITALIC}{self._repr_type()}{formats.RESET} {colors.CORN}{'─'*right_line_len}\n"
88+
f"{colors.CORN}{'─' * left_line_len} {formats.BOLD}{formats.ITALIC}{self._repr_type()}{formats.RESET} {colors.CORN}{'─' * right_line_len}\n"
8589
+ repr_str
8690
)
8791

0 commit comments

Comments
 (0)