From d163d077cc6e021e9e9631971bf6930273775ba4 Mon Sep 17 00:00:00 2001 From: Christophe COSSOU Date: Fri, 21 Jul 2023 10:08:31 +0200 Subject: [PATCH] In config writer: default value now write on multiple lines when a list of values is encountered (e.g. quality criteria) --- ctapipe/core/config_writer.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/ctapipe/core/config_writer.py b/ctapipe/core/config_writer.py index 7dcba704638..d2df93e95cc 100644 --- a/ctapipe/core/config_writer.py +++ b/ctapipe/core/config_writer.py @@ -73,16 +73,29 @@ def _trait_to_str(trait, help=True, indent_level=0): trait_repr += f"{wrap_comment(h_msg, indent_level=indent_level)}\n" trait_value = trait.default() + # add quotes for strings if isinstance(trait, traitlets.Unicode): trait_value = f"'{trait_value}'" + # Make sure that list of values end up on multiple lines (In particular quality criteria) + value_repr = "" + if isinstance(trait_value, list): + for v in trait_value: + # tuples are not correctly handled by yaml, so we convert them to list here. They'll be converted to tuple + # when reading again. + if isinstance(v, tuple): + v = list(v) + value_repr += f"\n{indent_str * indent_level}- {v}" + else: + value_repr += f"{trait_value}" + # Automatically comment all parameters that are unvalid commented = "" if trait_value == traitlets.Undefined: commented = "#" - trait_repr += f"{indent_str*indent_level}{commented}{trait.name}: {trait_value}\n" + trait_repr += f"{indent_str*indent_level}{commented}{trait.name}: {value_repr}\n" return trait_repr