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 repr in ipython #350

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