|
5 | 5 | from typing import Any, List, Optional, Union |
6 | 6 |
|
7 | 7 | from rich.pretty import pretty_repr |
8 | | -from tomlkit import dump, load, string, table |
| 8 | +from tomlkit import array, dump, inline_table, items, load, string, table |
9 | 9 |
|
10 | 10 | from somesy.core.models import Entity, Person, ProjectMetadata |
11 | 11 | from somesy.core.writer import FieldKeyMapping, IgnoreKey, ProjectMetadataWriter |
@@ -99,7 +99,24 @@ def _set_property(self, key: Union[str, List[str], IgnoreKey], value: Any) -> No |
99 | 99 | if key not in curr: |
100 | 100 | curr.add(key, table()) |
101 | 101 | curr = curr[key] |
102 | | - curr[key_path[-1]] = value |
| 102 | + |
| 103 | + # Handle arrays with proper formatting |
| 104 | + if isinstance(value, list): |
| 105 | + arr = array() |
| 106 | + arr.extend(value) |
| 107 | + arr.multiline(True) |
| 108 | + # Ensure whitespace after commas in inline tables |
| 109 | + for item in arr: |
| 110 | + if isinstance(item, items.InlineTable): |
| 111 | + # Rebuild the inline table with desired formatting |
| 112 | + formatted_item = inline_table() |
| 113 | + for k, v in item.value.items(): |
| 114 | + formatted_item[k] = v |
| 115 | + formatted_item.trivia.trail = " " # Add space after each comma |
| 116 | + arr[arr.index(item)] = formatted_item |
| 117 | + curr[key_path[-1]] = arr |
| 118 | + else: |
| 119 | + curr[key_path[-1]] = value |
103 | 120 |
|
104 | 121 | @staticmethod |
105 | 122 | def _from_person(person: Union[Person, Entity]): |
|
0 commit comments