diff --git a/e3sm_diags/parser/core_parser.py b/e3sm_diags/parser/core_parser.py index 2d1defd23..d823de253 100644 --- a/e3sm_diags/parser/core_parser.py +++ b/e3sm_diags/parser/core_parser.py @@ -815,21 +815,21 @@ def _get_cfg_parameters( parameters = [] cfg_file_obj = self._create_cfg_hash_titles(cfg_file) - kwargs = ( - {"strict": False} if sys.version_info[0] >= 3 else {} - ) # 'strict' keyword doesn't work in Python 2. - config = configparser.ConfigParser( # type: ignore - **kwargs - ) # Allow for two lines to be the same. - config.readfp(cfg_file_obj) - - for section in config.sections(): + + # Setting `strict=False` enables the parser to allow for any section + # or duplicates while reading from a single source. This is required + # because .cfg diagnostic files might contain duplicate sections with + # slight tweaks based on the set. + parser = configparser.ConfigParser(strict=False) + parser.read_file(cfg_file_obj) + + for section in parser.sections(): p = self._parameter_cls() # Remove all of the variables. p.__dict__.clear() - for k, v in config.items(section): + for k, v in parser.items(section): v = yaml.safe_load(v) setattr(p, k, v)