Skip to content

Commit

Permalink
Merge pull request #211 from abhinavmuta/indent-log
Browse files Browse the repository at this point in the history
Indent equations in log file add __len__ to MultiStageEquations
  • Loading branch information
prabhuramachandran committed May 16, 2019
2 parents 741d25f + 0c97bc8 commit f07ec07
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions pysph/sph/equation.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ def camel_to_underscore(name):
return re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).lower()


def indent(text, prefix=' '):
"""Prepend prefix to every line in the text"""
return ''.join(prefix + line for line in text.splitlines(True))


##############################################################################
# `Context` class.
##############################################################################
Expand Down Expand Up @@ -505,11 +510,11 @@ def __init__(self, equations, real=True, update_nnps=False, iterate=False,
##########################################################################
def __repr__(self):
cls = self.__class__.__name__
eqs = [repr(eq) for eq in self.equations]
eqs = ', \n'.join(repr(eq) for eq in self.equations)
ignore = ['equations']
kws = ', '.join(get_init_args(self, self.__init__, ignore))
return '%s(equations=[\n%s\n ],\n %s)' % (
cls, ',\n'.join(eqs), kws
return '%s(equations=[\n%s\n],\n %s)' % (
cls, indent(eqs), kws
)

def _has_code(self, kind='loop'):
Expand Down Expand Up @@ -913,7 +918,13 @@ def __init__(self, groups):

def __repr__(self):
name = self.__class__.__name__
kw = [', \n'.join(str(grps) for grps in stg) for stg in self.groups]
return '%s(groups=[[\n%s\n ]]\n)' % (
name, '], [\n'.join(kw)
groups = [', \n'.join(str(stg_grps) for stg_grps in stg)
for stg in self.groups]
kw = indent('\n], [\n'.join(groups))
s = '%s(groups=[\n[\n%s\n ]\n])' % (
name, kw,
)
return s

def __len__(self):
return len(self.groups)

0 comments on commit f07ec07

Please sign in to comment.