Skip to content

Commit

Permalink
feat: string representation for base classes
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrugman committed Jun 28, 2022
1 parent 6891039 commit f618e74
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
8 changes: 8 additions & 0 deletions popmon/base/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,11 @@ def transform(self, *args):
:rtype: dict
"""
raise NotImplementedError

def __repr__(self):
"""String representation for modules when printing a pipeline/list of modules"""
name = self.__class__.__name__
input_keys = [f"{v}='{getattr(self, v)}'" for v in self._input_keys]
output_keys = [f"{v}='{getattr(self, v)}'" for v in self._output_keys]
params = ", ".join(input_keys + output_keys)
return f"{name}({params})"
9 changes: 9 additions & 0 deletions popmon/base/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,12 @@ def transform(self, datastore):
self.logger.debug(f"transform {module.__class__.__name__}")
datastore = module.transform(datastore)
return datastore

def __repr__(self):
"""String representation for pipeline"""
name = self.__class__.__name__
ret = f"{name}: [\n"
for m in self.modules:
ret += "\t" + str(m).replace("\n", "\n\t") + "\n"
ret += "]"
return ret

0 comments on commit f618e74

Please sign in to comment.