Skip to content

Commit

Permalink
Adding possibility to extract information about updaters
Browse files Browse the repository at this point in the history
  • Loading branch information
stammler committed Jul 19, 2023
1 parent e50b9ed commit e1fea4c
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 2 deletions.
24 changes: 23 additions & 1 deletion simframe/frame/heartbeat.py
@@ -1,4 +1,5 @@
from simframe.frame.updater import Updater
from simframe.utils.color import colorize


class Heartbeat(object):
Expand Down Expand Up @@ -35,7 +36,28 @@ def __str__(self):
return "{}".format(str(self.__name__))

def __repr__(self):
return self.__str__()
s = self.__str__() + "\n"
s += (len(s)-1)*"-" + "\n"
s += "\n"
s += "{} {}".format(colorize("Systole: ", color="red"),
str(self.systole._func)) + "\n"
s += "{} {}".format(colorize("Updater: ", color="red"),
str(self.updater._func)) + "\n"
s += "{} {}".format(colorize("Diastole:", color="red"),
str(self.diastole._func)) + "\n"
s += "\n"
s += "Docstrings" + "\n"
s += 10*"-" + "\n"
s += "\n"
s += colorize("Systole:", color="red") + "\n"
s += str(self.systole._func.__doc__ or None) + "\n"
s += "\n"
s += colorize("Updater:", color="red") + "\n"
s += str(self.updater._func.__doc__ or None) + "\n"
s += "\n"
s += colorize("Diastole:", color="red") + "\n"
s += str(self.diastole._func.__doc__ or None)
return s

@property
def systole(self):
Expand Down
36 changes: 35 additions & 1 deletion simframe/frame/updater.py
@@ -1,3 +1,7 @@
import inspect
from simframe.utils.color import colorize


class Updater():
"""Class that manages how a ``Group`` or ``Field`` is updated."""

Expand Down Expand Up @@ -25,7 +29,37 @@ def update(self, owner, *args, **kwargs):
return self._func(owner, *args, **kwargs)

def __str__(self):
return "{}".format(str(self.__name__))
s = "{}".format(str(self.__name__)) + "\n"
s += (len(s)-1)*"-" + "\n"
s += "\n"
# Signature
try:
sig = "{}{}".format(self._func.__name__,
inspect.signature(self._func))
s += "{} {}".format(colorize("Signature:",
color="red"), str(sig)) + "\n"
except:
pass
# Source/Docstring
try:
source = inspect.getsource(self._func)
cat = colorize("Source:", color="red") + "\n"
except:
source = self._func.__doc__
cat = colorize("Docstring:", color="red") + "\n"
if source is not None:
s += cat
s += source
# File
try:
fn = inspect.getfile(self._func)
s += "{} {}".format(colorize("File:", color="red"), fn) + "\n"
except:
pass
# Type
cls = self._func.__class__.__name__
s += "{} {}".format(colorize("Type:", color="red"), cls)
return s

def __repr__(self):
return self.__str__()

0 comments on commit e1fea4c

Please sign in to comment.