From 5e5b47c4cf9b238ca426d22fb924e6bb14136aeb Mon Sep 17 00:00:00 2001 From: Jim Edwards Date: Fri, 3 Nov 2017 09:48:57 -0600 Subject: [PATCH 1/4] improve error messages for compset names --- scripts/lib/CIME/XML/component.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/lib/CIME/XML/component.py b/scripts/lib/CIME/XML/component.py index 1f4ae93162c..caf291c03c5 100644 --- a/scripts/lib/CIME/XML/component.py +++ b/scripts/lib/CIME/XML/component.py @@ -198,8 +198,8 @@ def _get_description_v3(self, compsetname, comp_class): # cpl and esp components may not have a description if comp_class not in ['cpl','esp']: expect(len(desc) > 0, - "No description found for comp_class {} matching compsetname {} in file {}"\ - .format(comp_class,compsetname, self.filename)) + "No description found for comp_class {} matching compsetname {} in file {}, expected match in {} % {}"\ + .format(comp_class,compsetname, self.filename, list(reqset), list(opt_parts))) return desc def _get_description_match(self, compsetname, reqset, fullset, modifier_mode): @@ -239,13 +239,13 @@ def _get_description_match(self, compsetname, reqset, fullset, modifier_mode): if cset == reqset or (cset > reqset and cset <= fullset): if modifier_mode == '1': expect(len(complist) == 2, - "Expected exactly one modifer found {}".format(len(complist)-1)) + "Expected exactly one modifer found {} in {}".format(len(complist)-1,complist)) elif modifier_mode == '+': expect(len(complist) >= 2, - "Expected one or more modifers found {}".format(len(complist)-1)) + "Expected one or more modifers found {} in {}".format(len(complist)-1, list(reqset))) elif modifier_mode == '?': expect(len(complist) <= 2, - "Expected 0 or one modifers found {}".format(len(complist)-1)) + "Expected 0 or one modifers found {} in {}".format(len(complist)-1, complist)) expect(not match,"Found multiple matches in file {} for {}".format(self.filename,comp)) match = True # found a match From faf0876f8dee1c0edbec555d47a311034c584044 Mon Sep 17 00:00:00 2001 From: Jim Edwards Date: Fri, 3 Nov 2017 09:52:05 -0600 Subject: [PATCH 2/4] improve error messages --- scripts/lib/CIME/XML/component.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/lib/CIME/XML/component.py b/scripts/lib/CIME/XML/component.py index caf291c03c5..1ff473f260b 100644 --- a/scripts/lib/CIME/XML/component.py +++ b/scripts/lib/CIME/XML/component.py @@ -215,11 +215,11 @@ def _get_description_match(self, compsetname, reqset, fullset, modifier_mode): >>> obj._get_description_match("1850_DATM_Barn",set(["DATM"]), set(["DATM","CRU","HSI"]), "1") Traceback (most recent call last): ... - SystemExit: ERROR: Expected exactly one modifer found 0 + SystemExit: ERROR: Expected exactly one modifer found 0 in ['DATM'] >>> obj._get_description_match("1850_DATM%CRU%HSI_Barn",set(["DATM"]), set(["DATM","CRU","HSI"]), "1") Traceback (most recent call last): ... - SystemExit: ERROR: Expected exactly one modifer found 2 + SystemExit: ERROR: Expected exactly one modifer found 2 in ['DATM', 'CRU', 'HSI'] >>> obj._get_description_match("1850_CAM50%WCCM%RCO2_Barn",set(["CAM50", "WCCM"]), set(["CAM50","WCCM","RCO2"]), "*") True From ec25073198965437d1a8ce44a7a5683d3eec9e7a Mon Sep 17 00:00:00 2001 From: Jim Edwards Date: Fri, 3 Nov 2017 13:24:09 -0600 Subject: [PATCH 3/4] fix compset descriptions --- scripts/lib/CIME/XML/component.py | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/scripts/lib/CIME/XML/component.py b/scripts/lib/CIME/XML/component.py index 1ff473f260b..4ad598ac349 100644 --- a/scripts/lib/CIME/XML/component.py +++ b/scripts/lib/CIME/XML/component.py @@ -162,7 +162,6 @@ def _get_description_v3(self, compsetname, comp_class): modifier_mode = '*' expect(modifier_mode in ('*','1','?','+'), "Invalid modifier_mode {} in file {}".format(modifier_mode, self.filename)) - optiondesc = {} if comp_class == "forcing": for node in desc_nodes: @@ -176,25 +175,31 @@ def _get_description_v3(self, compsetname, comp_class): desc = compsetname.split('_')[0] return desc + # first pass just make a hash of the option descriptions for node in desc_nodes: option = node.get('option') if option is not None: optiondesc[option] = node.text + #second pass find a comp_class match + desc = "" for node in desc_nodes: compdesc = node.get(comp_class) - if compdesc is None: - continue - opt_parts = [ x.rstrip("]") for x in compdesc.split("[%") ] - parts = opt_parts.pop(0).split("%") + if compdesc is not None: + opt_parts = [ x.rstrip("]") for x in compdesc.split("[%") ] + parts = opt_parts.pop(0).split("%") + reqset = set(parts) + fullset = set(parts+opt_parts) + match, complist = self._get_description_match(compsetname, reqset, fullset, modifier_mode) + if match: + desc = node.text + for opt in complist: + if opt in optiondesc: + desc += optiondesc[opt] + - reqset = set(parts) - fullset = set(parts+opt_parts) - if self._get_description_match(compsetname, reqset, fullset, modifier_mode): - desc = node.text - break # cpl and esp components may not have a description if comp_class not in ['cpl','esp']: expect(len(desc) > 0, @@ -233,6 +238,8 @@ def _get_description_match(self, compsetname, reqset, fullset, modifier_mode): """ match = False comparts = compsetname.split('_') + matchcomplist = None + for comp in comparts: complist = comp.split('%') cset = set(complist) @@ -248,9 +255,10 @@ def _get_description_match(self, compsetname, reqset, fullset, modifier_mode): "Expected 0 or one modifers found {} in {}".format(len(complist)-1, complist)) expect(not match,"Found multiple matches in file {} for {}".format(self.filename,comp)) match = True + matchcomplist = complist # found a match - return match + return match, matchcomplist From 3d8c3b5eaaffffd7ba6b611043d38b0e27e2b7c7 Mon Sep 17 00:00:00 2001 From: Jim Edwards Date: Fri, 3 Nov 2017 13:51:02 -0600 Subject: [PATCH 4/4] fix unit tests --- scripts/lib/CIME/XML/component.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/scripts/lib/CIME/XML/component.py b/scripts/lib/CIME/XML/component.py index 4ad598ac349..f3821ea8d52 100644 --- a/scripts/lib/CIME/XML/component.py +++ b/scripts/lib/CIME/XML/component.py @@ -212,11 +212,11 @@ def _get_description_match(self, compsetname, reqset, fullset, modifier_mode): >>> obj = Component('testingonly', 'ATM') >>> obj._get_description_match("1850_DATM%CRU_FRED",set(["DATM"]), set(["DATM","CRU","HSI"]), "*") - True + (True, ['DATM', 'CRU']) >>> obj._get_description_match("1850_DATM%FRED_Barn",set(["DATM"]), set(["DATM","CRU","HSI"]), "*") - False + (False, None) >>> obj._get_description_match("1850_DATM_Barn",set(["DATM"]), set(["DATM","CRU","HSI"]), "?") - True + (True, ['DATM']) >>> obj._get_description_match("1850_DATM_Barn",set(["DATM"]), set(["DATM","CRU","HSI"]), "1") Traceback (most recent call last): ... @@ -226,15 +226,15 @@ def _get_description_match(self, compsetname, reqset, fullset, modifier_mode): ... SystemExit: ERROR: Expected exactly one modifer found 2 in ['DATM', 'CRU', 'HSI'] >>> obj._get_description_match("1850_CAM50%WCCM%RCO2_Barn",set(["CAM50", "WCCM"]), set(["CAM50","WCCM","RCO2"]), "*") - True + (True, ['CAM50', 'WCCM', 'RCO2']) # The following is not allowed because the required WCCM field is missing >>> obj._get_description_match("1850_CAM50%RCO2_Barn",set(["CAM50", "WCCM"]), set(["CAM50","WCCM","RCO2"]), "*") - False + (False, None) >>> obj._get_description_match("1850_CAM50_Barn",set(["CAM50", "WCCM"]), set(["CAM50","WCCM","RCO2"]), "+") - False + (False, None) >>> obj._get_description_match("1850_CAM50%WCCM_Barn",set(["CAM50", "WCCM"]), set(["CAM50","WCCM","RCO2"]), "+") - True + (True, ['CAM50', 'WCCM']) """ match = False comparts = compsetname.split('_')