Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Mauro Carvalho Chehab and committed by
Jonathan Corbet
6e0d7b63 e896174e

+15 -3
+15 -3
tools/lib/python/kdoc/kdoc_yaml_file.py
··· 126 126 else: 127 127 key = "rst" 128 128 129 - expected_dict[key]= out_style.output_symbols(fname, [arg]) 129 + expected_dict[key]= out_style.output_symbols(fname, [arg]).strip() 130 130 131 131 name = f"{base_name}_{i:03d}" 132 132 ··· 148 148 """ 149 149 import yaml 150 150 151 + # Helper function to better handle multilines 152 + def str_presenter(dumper, data): 153 + if "\n" in data: 154 + return dumper.represent_scalar("tag:yaml.org,2002:str", data, style="|") 155 + 156 + return dumper.represent_scalar("tag:yaml.org,2002:str", data) 157 + 158 + # Register the representer 159 + yaml.add_representer(str, str_presenter) 160 + 151 161 data = {"tests": self.tests} 152 162 153 163 with open(self.test_file, "w", encoding="utf-8") as fp: 154 - yaml.safe_dump(data, fp, sort_keys=False, default_style="|", 155 - default_flow_style=False, allow_unicode=True) 164 + yaml.dump(data, fp, 165 + sort_keys=False, width=120, indent=2, 166 + default_flow_style=False, allow_unicode=True, 167 + explicit_start=False, explicit_end=False)