Skip to content

Commit

Permalink
Merge pull request #350 from Genesis-Embodied-AI/zhenjia/fix_ipython_…
Browse files Browse the repository at this point in the history
…repr

fix repr in ipython
  • Loading branch information
zhenjia-xu authored Dec 27, 2024
2 parents 35a2fe8 + d89a7b4 commit 2362f88
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
4 changes: 0 additions & 4 deletions genesis/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,6 @@ 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}, ["

Expand Down
13 changes: 11 additions & 2 deletions genesis/repr_base.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import inspect

import genesis as gs
import genesis.utils.repr as ru
from genesis.styles import colors, formats, styless
Expand Down Expand Up @@ -31,9 +33,16 @@ def _repr_brief(self):
repr_str += f", material: {self.material}"
return repr_str

def _is_debugger(self) -> bool:
"""Detect if running under a debugger (VSCode or PyCharm)."""
for frame in inspect.stack():
if any(module in frame.filename for module in ("debugpy", "ptvsd", "pydevd")):
return True
return False

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

def __colorized__repr__(self) -> str:
all_attrs = self.__dir__()
Expand Down

0 comments on commit 2362f88

Please sign in to comment.