Skip to content

Commit 3598368

Browse files
author
Bernhard Kaindl
committed
tools/generate-settings-dataclasses.py: format with black -l88
Cleans up source formatting of generating complicated code
1 parent f2cea60 commit 3598368

File tree

1 file changed

+13
-19
lines changed

1 file changed

+13
-19
lines changed

tools/generate-settings-dataclasses.py

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ def write(msg: Any) -> None:
146146
"connection.uuid",
147147
]
148148

149+
149150
def _property_name_order_idx(name: str) -> int:
150151
"""Return the sort index for the given connection setting property"""
151152
try:
@@ -206,9 +207,7 @@ def node_get_attr(nodes: List[Optional[Any]], name: str) -> Any:
206207
return None
207208

208209

209-
def node_set_attr(
210-
dst_node: Any, name: str, nodes: List[Optional[Any]]
211-
) -> None:
210+
def node_set_attr(dst_node: Any, name: str, nodes: List[Optional[Any]]) -> None:
212211
x = node_get_attr(nodes, name)
213212
if x:
214213
dst_node.set(name, x)
@@ -239,8 +238,7 @@ def main(settings_xml_path: Path) -> None:
239238

240239
xml_roots = [ElementTree.parse(f).getroot() for f in gl_input_files]
241240
assert all(root.tag == "nm-setting-docs" for root in xml_roots)
242-
settings_roots = [node_to_dict(root, "setting", "name")
243-
for root in xml_roots]
241+
settings_roots = [node_to_dict(root, "setting", "name") for root in xml_roots]
244242

245243
# Generate the file header
246244
license = "SPDX-License-Identifier: LGPL-2.1-or-later"
@@ -265,8 +263,7 @@ def main(settings_xml_path: Path) -> None:
265263
classes = []
266264

267265
# generate the connection type settings classes:
268-
for settingname in iter_keys_of_dicts(settings_roots,
269-
key_fcn_setting_name):
266+
for settingname in iter_keys_of_dicts(settings_roots, key_fcn_setting_name):
270267
settings = [d.get(settingname) for d in settings_roots]
271268
properties = [node_to_dict(s, "property", "name") for s in settings]
272269
if properties == [OrderedDict()]:
@@ -326,8 +323,10 @@ def main(settings_xml_path: Path) -> None:
326323

327324
# Generate the attributes of the settings_class for this profile type:
328325

329-
for property in iter_keys_of_dicts(properties, key_fcn_property_name, f'{settingname}.'):
330-
property_name = property[len(settingname)+1:]
326+
for property in iter_keys_of_dicts(
327+
properties, key_fcn_property_name, f'{settingname}.'
328+
):
329+
property_name = property[len(settingname) + 1 :]
331330
properties_attrs = [p.get(property_name) for p in properties]
332331
t = node_get_attr(properties_attrs, "type")
333332
attribute = property_name.replace('-', '_')
@@ -350,16 +349,12 @@ def main(settings_xml_path: Path) -> None:
350349
if dbustype == "aa{sv}":
351350
default = node_get_attr(properties_attrs, "default")
352351
inner_cls = (
353-
property_name.title(
354-
).replace("-", "").replace("data", "Data")
352+
property_name.title().replace("-", "").replace("data", "Data")
355353
)
356-
f.write(
357-
f" {attribute}: Optional[List[{inner_cls}]] = field(\n")
358-
f.write(
359-
f" metadata={{'dbus_name': '{property_name}',\n")
354+
f.write(f" {attribute}: Optional[List[{inner_cls}]] = field(\n")
355+
f.write(f" metadata={{'dbus_name': '{property_name}',\n")
360356
f.write(f" 'dbus_type': '{dbustype}',\n")
361-
f.write(
362-
f" 'dbus_inner_class': {inner_cls}}},\n")
357+
f.write(f" 'dbus_inner_class': {inner_cls}}},\n")
363358
f.write(f" default={str(default).title()},\n )\n")
364359
else:
365360
attribute_type = dbus_type_name_map[dbustype]
@@ -369,8 +364,7 @@ def main(settings_xml_path: Path) -> None:
369364
else:
370365
f.write(f" {attribute}: {attribute_type}")
371366
f.write(" = field(\n")
372-
meta = (f"'dbus_name': '{property_name}', "
373-
f"'dbus_type':@'{dbustype}'")
367+
meta = f"'dbus_name': '{property_name}', " f"'dbus_type':@'{dbustype}'"
374368
line = "metadata={" + meta + "},"
375369
wrapper = textwrap.TextWrapper(
376370
width=80,

0 commit comments

Comments
 (0)