Write structured config file.
(configname, cfg)
| 241 | |
| 242 | |
| 243 | def write_config(configname, cfg): |
| 244 | """Write structured config file.""" |
| 245 | with open(configname, "w") as cf: |
| 246 | cfg_file, ruamelFile = create_config_template(cfg.get("multianimalproject", False)) |
| 247 | for key in cfg.keys(): |
| 248 | cfg_file[key] = cfg[key] |
| 249 | |
| 250 | # Adding default value for variable skeleton and skeleton_color for backward compatibility. |
| 251 | if "skeleton" not in cfg.keys(): |
| 252 | cfg_file["skeleton"] = [] |
| 253 | cfg_file["skeleton_color"] = "black" |
| 254 | # Use a very large width so long strings (e.g., file paths or keys with spaces) |
| 255 | # are kept on a single line instead of being wrapped, which can otherwise cause |
| 256 | # them to be emitted as complex keys. See also: |
| 257 | # https://stackoverflow.com/questions/31197268/pyyaml-yaml-dump-produces-complex-key-for-string-key-122-chars/31199123#31199123 |
| 258 | ruamelFile.width = 1_000_000 |
| 259 | ruamelFile.dump(cfg_file, cf) |
| 260 | |
| 261 | |
| 262 | def edit_config(configname, edits, output_name=""): |
no test coverage detected