summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaphaël Barrois <raphael.barrois@polyconseil.fr>2019-11-21 12:42:50 +0100
committerRaphaël Barrois <raphael.barrois@polyconseil.fr>2019-11-21 12:42:50 +0100
commit371faaf6453b07f5316e356e68d7f26ae44b0df9 (patch)
tree413ba1270809496358f495cb9e0c7195a7170fac
parentcfb86ab34051d2cf935b112d4b7a5e7800e703b3 (diff)
downloadsemantic-version-371faaf6453b07f5316e356e68d7f26ae44b0df9.tar.gz
Add Clause.prettyprint() for debug.
This function allows developers to preview the structure of the resulting clause parsed from a spec, usable with `print(spec.clause.prettyprint())`. Apply typical PEP8 indentation rules.
-rw-r--r--semantic_version/base.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/semantic_version/base.py b/semantic_version/base.py
index 078d83d..4327fa1 100644
--- a/semantic_version/base.py
+++ b/semantic_version/base.py
@@ -673,6 +673,19 @@ class Clause(object):
def __eq__(self, other):
raise NotImplementedError()
+ def prettyprint(self, indent='\t'):
+ """Pretty-print the clause.
+ """
+ return '\n'.join(self._pretty()).replace('\t', indent)
+
+ def _pretty(self):
+ """Actual pretty-printing logic.
+
+ Yields:
+ A list of string. Indentation is performed with \t.
+ """
+ yield repr(self)
+
def __ne__(self, other):
return not self == other
@@ -733,6 +746,15 @@ class AnyOf(Clause):
def __repr__(self):
return 'AnyOf(%s)' % ', '.join(sorted(repr(c) for c in self.clauses))
+ def _pretty(self):
+ yield 'AnyOF('
+ for clause in self.clauses:
+ lines = list(clause._pretty())
+ for line in lines[:-1]:
+ yield '\t' + line
+ yield '\t' + lines[-1] + ','
+ yield ')'
+
class AllOf(Clause):
__slots__ = ['clauses']
@@ -789,6 +811,15 @@ class AllOf(Clause):
def __repr__(self):
return 'AllOf(%s)' % ', '.join(sorted(repr(c) for c in self.clauses))
+ def _pretty(self):
+ yield 'AllOF('
+ for clause in self.clauses:
+ lines = list(clause._pretty())
+ for line in lines[:-1]:
+ yield '\t' + line
+ yield '\t' + lines[-1] + ','
+ yield ')'
+
class Matcher(Clause):
__slots__ = []