summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlf Magnusson <ulfalizer@gmail.com>2018-11-06 11:16:28 +0100
committerUlf Magnusson <ulfalizer@gmail.com>2018-11-06 11:48:42 +0100
commit7992519be5d59a69dc71f43ec2f34c5594afdb14 (patch)
tree04b7448bc49a63a3d86703edf9a34e1f4dbe22a5
parent9c9f0c884366ff1f0acc00e430f0eeb1b4391658 (diff)
Always strip trailing whitespace in 'MenuNode.help' and __str__()
Previously, you could get either one or two newlines at the end of MenuNode.help and the various __str__() methods, though this wasn't documented. Always stripping trailing whitespace is cleaner e.g. when using print(), which automatically appends a trailing newline, and makes things consistent. Hopefully nothing relied on the old undocumented behavior. It's fine for genrest.py at least.
-rw-r--r--kconfiglib.py33
-rw-r--r--testsuite.py13
2 files changed, 26 insertions, 20 deletions
diff --git a/kconfiglib.py b/kconfiglib.py
index 61661c5..b88bd6e 100644
--- a/kconfiglib.py
+++ b/kconfiglib.py
@@ -2904,7 +2904,7 @@ class Kconfig(object):
self._linenr += len(help_lines)
- node.help = "\n".join(help_lines).rstrip() + "\n"
+ node.help = "\n".join(help_lines).rstrip()
self._line_after_help(line)
def _parse_expr(self, transform_m):
@@ -4251,7 +4251,8 @@ class Symbol(object):
defined in multiple locations will return a string with all
definitions.
- An empty string is returned for undefined and constant symbols.
+ The returned string does not end in a newline. An empty string is
+ returned for undefined and constant symbols.
"""
return self.custom_str(standard_sc_expr_str)
@@ -4260,8 +4261,8 @@ class Symbol(object):
Works like Symbol.__str__(), but allows a custom format to be used for
all symbol/choice references. See expr_str().
"""
- return "\n".join(node.custom_str(sc_expr_str_fn)
- for node in self.nodes)
+ return "\n\n".join(node.custom_str(sc_expr_str_fn)
+ for node in self.nodes)
#
# Private methods
@@ -4826,6 +4827,8 @@ class Choice(object):
matching the Kconfig format (though without the contained choice
symbols).
+ The returned string does not end in a newline.
+
See Symbol.__str__() as well.
"""
return self.custom_str(standard_sc_expr_str)
@@ -4835,8 +4838,8 @@ class Choice(object):
Works like Choice.__str__(), but allows a custom format to be used for
all symbol/choice references. See expr_str().
"""
- return "\n".join(node.custom_str(sc_expr_str_fn)
- for node in self.nodes)
+ return "\n\n".join(node.custom_str(sc_expr_str_fn)
+ for node in self.nodes)
#
# Private methods
@@ -5006,6 +5009,10 @@ class MenuNode(object):
It is possible to have a separate help text at each location if a symbol
is defined in multiple locations.
+ Trailing whitespace (including a final newline) is stripped from the help
+ text. This was not the case before Kconfiglib 10.21.0, where the format
+ was undocumented.
+
dep:
The 'depends on' dependencies for the menu node, or self.kconfig.y if
there are no dependencies. Parent dependencies are propagated to this
@@ -5195,6 +5202,8 @@ class MenuNode(object):
locations), properties that aren't associated with a particular menu
node are shown on all menu nodes ('option env=...', 'optional' for
choices, etc.).
+
+ The returned string does not end in a newline.
"""
return self.custom_str(standard_sc_expr_str)
@@ -5208,14 +5217,14 @@ class MenuNode(object):
self._sym_choice_node_str(sc_expr_str_fn)
def _menu_comment_node_str(self, sc_expr_str_fn):
- s = '{} "{}"\n'.format("menu" if self.item is MENU else "comment",
- self.prompt[0])
+ s = '{} "{}"'.format("menu" if self.item is MENU else "comment",
+ self.prompt[0])
if self.dep is not self.kconfig.y:
- s += "\tdepends on {}\n".format(expr_str(self.dep, sc_expr_str_fn))
+ s += "\n\tdepends on {}".format(expr_str(self.dep, sc_expr_str_fn))
if self.item is MENU and self.visibility is not self.kconfig.y:
- s += "\tvisible if {}\n".format(expr_str(self.visibility,
+ s += "\n\tvisible if {}".format(expr_str(self.visibility,
sc_expr_str_fn))
return s
@@ -5289,7 +5298,7 @@ class MenuNode(object):
for line in self.help.splitlines():
indent_add(" " + line)
- return "\n".join(lines) + "\n"
+ return "\n".join(lines)
class Variable(object):
"""
@@ -5988,7 +5997,7 @@ def _found_dep_loop(loop, cur):
if isinstance(item, Symbol) and item.choice:
msg += "the choice symbol "
- msg += "{}, with definition...\n\n{}\n" \
+ msg += "{}, with definition...\n\n{}\n\n" \
.format(_name_and_loc(item), item)
# Small wart: Since we reuse the already calculated
diff --git a/testsuite.py b/testsuite.py
index 6f05b6a..65ce4aa 100644
--- a/testsuite.py
+++ b/testsuite.py
@@ -489,10 +489,11 @@ def run_selftests():
print("Testing Symbol.__str__()/custom_str() and def_{int,hex,string}")
def verify_str(item, s):
- verify_equal(str(item), s[1:])
+ verify_equal(str(item), s[1:-1])
def verify_custom_str(item, s):
- verify_equal(item.custom_str(lambda sc: "[{}]".format(sc.name)), s[1:])
+ verify_equal(item.custom_str(lambda sc: "[{}]".format(sc.name)),
+ s[1:-1])
c = Kconfig("Kconfiglib/tests/Kstr", warn=False)
@@ -936,7 +937,7 @@ comment "advanced comment"
c = Kconfig("Kconfiglib/tests/Khelp")
def verify_help(node, s):
- verify_equal(node.help, s[1:])
+ verify_equal(node.help, s[1:-1])
verify_help(c.syms["TWO_HELP_STRINGS"].nodes[0], """
first help string
@@ -2553,13 +2554,11 @@ config BOOL
prompt "foo" if DEF || !UNDEF_1
default UNDEF_2
-
- Referenced at Kconfiglib/tests/Kundef:19:
menu "menu"
depends on UNDEF_1
visible if UNDEF_3
-
warning: undefined symbol UNDEF_2:
- Referenced at Kconfiglib/tests/Kundef:4:
@@ -2569,7 +2568,6 @@ config BOOL
prompt "foo" if DEF || !UNDEF_1
default UNDEF_2
-
- Referenced at Kconfiglib/tests/Kundef:8:
config INT
@@ -2577,7 +2575,6 @@ config INT
range UNDEF_2 8
range 5 15
default 10
-
warning: undefined symbol UNDEF_3:
- Referenced at Kconfiglib/tests/Kundef:19:
@@ -2585,7 +2582,7 @@ warning: undefined symbol UNDEF_3:
menu "menu"
depends on UNDEF_1
visible if UNDEF_3
-"""[1:])
+"""[1:-1])
os.environ.pop("KCONFIG_WARN_UNDEF")