summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMauro Carvalho Chehab <mchehab+huawei@kernel.org>2026-03-23 10:10:47 +0100
committerJonathan Corbet <corbet@lwn.net>2026-03-25 13:36:45 -0600
commit6e0d7b63676b85490bbaf01c9a8ebcd692bed981 (patch)
treea0785eb4fb169db0fa3045599da0871433b9d77a
parente896174e466f593f3a62fd4dd779e6686bf32f40 (diff)
downloadlwn-6e0d7b63676b85490bbaf01c9a8ebcd692bed981.tar.gz
lwn-6e0d7b63676b85490bbaf01c9a8ebcd692bed981.zip
docs: kdoc_yaml_file: add a representer to make strings look nicer
The strings representation is not ok, currently. Add a helper function to improve it, and drop blank lines at beginning and at the end of the dumps Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org> Signed-off-by: Jonathan Corbet <corbet@lwn.net> Message-ID: <422041a8b49b2609de5749092fe074b7948c32a6.1774256269.git.mchehab+huawei@kernel.org>
-rw-r--r--tools/lib/python/kdoc/kdoc_yaml_file.py18
1 files changed, 15 insertions, 3 deletions
diff --git a/tools/lib/python/kdoc/kdoc_yaml_file.py b/tools/lib/python/kdoc/kdoc_yaml_file.py
index db131503c3f6..18737abb1176 100644
--- a/tools/lib/python/kdoc/kdoc_yaml_file.py
+++ b/tools/lib/python/kdoc/kdoc_yaml_file.py
@@ -126,7 +126,7 @@ class KDocTestFile():
else:
key = "rst"
- expected_dict[key]= out_style.output_symbols(fname, [arg])
+ expected_dict[key]= out_style.output_symbols(fname, [arg]).strip()
name = f"{base_name}_{i:03d}"
@@ -148,8 +148,20 @@ class KDocTestFile():
"""
import yaml
+ # Helper function to better handle multilines
+ def str_presenter(dumper, data):
+ if "\n" in data:
+ return dumper.represent_scalar("tag:yaml.org,2002:str", data, style="|")
+
+ return dumper.represent_scalar("tag:yaml.org,2002:str", data)
+
+ # Register the representer
+ yaml.add_representer(str, str_presenter)
+
data = {"tests": self.tests}
with open(self.test_file, "w", encoding="utf-8") as fp:
- yaml.safe_dump(data, fp, sort_keys=False, default_style="|",
- default_flow_style=False, allow_unicode=True)
+ yaml.dump(data, fp,
+ sort_keys=False, width=120, indent=2,
+ default_flow_style=False, allow_unicode=True,
+ explicit_start=False, explicit_end=False)