Skip to content

Commit

Permalink
Merge pull request #4631 from ESMCI/fix-quiet-lockedfiles
Browse files Browse the repository at this point in the history
The xmlchange tool should not raise an exception when a diff is detected.

Test suite:
Test baseline:
Test namelist changes:
Test status: [bit for bit, roundoff, climate changing]

Fixes [CIME Github issue #]
User interface changes?:
Update gh-pages html (Y/N)?:
  • Loading branch information
jasonb5 authored Jun 13, 2024
2 parents 548b136 + 70dc6cd commit f903115
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 84 deletions.
31 changes: 27 additions & 4 deletions CIME/Tools/xmlchange
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def parse_command_line(args, description):


def xmlchange_single_value(
case, xmlid, xmlval, subgroup, append, force, dryrun, env_test
case, xmlid, xmlval, subgroup, append, force, dryrun, env_test, caseroot, xmlfile
):
if xmlid in [
"THREAD_COUNT",
Expand Down Expand Up @@ -227,7 +227,12 @@ def xmlchange_single_value(

expect(result is not None, 'No variable "%s" found' % xmlid)

check_lockedfiles(case, skip=["env_case"])
if xmlfile is not None:
xmlfile = [xmlfile]
# Pass caseroot, in cases where --file is used and case does not have access to env_case.xml
check_lockedfiles(
case, skip=["env_case"], quiet=True, caseroot=caseroot, whitelist=xmlfile
)
else:
logger.warning("'%s' = '%s'", xmlid, xmlval)

Expand Down Expand Up @@ -283,11 +288,29 @@ def xmlchange(
)
(xmlid, xmlval) = pair
xmlchange_single_value(
case, xmlid, xmlval, subgroup, append, force, dryrun, env_test
case,
xmlid,
xmlval,
subgroup,
append,
force,
dryrun,
env_test,
caseroot,
xmlfile,
)
else:
xmlchange_single_value(
case, xmlid, xmlval, subgroup, append, force, dryrun, env_test
case,
xmlid,
xmlval,
subgroup,
append,
force,
dryrun,
env_test,
caseroot,
xmlfile,
)

if not noecho:
Expand Down
106 changes: 39 additions & 67 deletions CIME/data/config/cesm/config_files.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<type>char</type>
<default_value>$SRCROOT/ccs_config/config_grids.xml</default_value>
<values>
<value comp_interface="nuopc">$SRCROOT/ccs_config/config_grids_nuopc.xml</value>
<value >$SRCROOT/ccs_config/config_grids_nuopc.xml</value>
</values>
<group>case_last</group>
<file>env_case.xml</file>
Expand Down Expand Up @@ -122,12 +122,10 @@
<entry id="COMP_ROOT_DIR_ATM">
<type>char</type>
<values>
<value component="datm" comp_interface="nuopc" >$SRCROOT/components/cdeps/datm</value>
<value component="datm" comp_interface="mct" >$SRCROOT/components/cpl7/components/data_comps_$COMP_INTERFACE/datm</value>
<value component="satm" comp_interface="nuopc" >$CIMEROOT/CIME/non_py/src/components/stub_comps_$COMP_INTERFACE/satm</value>
<value component="satm" comp_interface="mct" >$SRCROOT/components/cpl7/components/stub_comps_$COMP_INTERFACE/satm</value>
<value component="xatm" comp_interface="nuopc" >$CIMEROOT/CIME/non_py/src/components/xcpl_comps_$COMP_INTERFACE/xatm</value>
<value component="xatm" comp_interface="mct" >$SRCROOT/components/cpl7/components/xcpl_comps_$COMP_INTERFACE/xatm</value>
<value component="datm" >$SRCROOT/components/cdeps/datm</value>
<value component="satm" >$CIMEROOT/CIME/non_py/src/components/stub_comps_$COMP_INTERFACE/satm</value>
<value component="xatm" >$CIMEROOT/CIME/non_py/src/components/xcpl_comps_$COMP_INTERFACE/xatm</value>

<value component="cam" >$SRCROOT/components/cam/</value>
<value component="ufsatm" >$SRCROOT/components/fv3/</value>
</values>
Expand All @@ -140,12 +138,9 @@
<entry id="COMP_ROOT_DIR_CPL">
<type>char</type>
<values>
<value comp_interface="nuopc" >$SRCROOT/components/cmeps</value>
<value comp_interface="nuopc" component="cpl" >$SRCROOT/components/cmeps</value>
<value comp_interface="nuopc" component="drv" >$SRCROOT/components/cmeps</value>
<value comp_interface="mct" >$SRCROOT/components/cpl7/driver</value>
<value comp_interface="mct" component="cpl" >$SRCROOT/components/cpl7/driver</value>
<value comp_interface="mct" component="drv" >$SRCROOT/components/cpl7/driver</value>
<value >$SRCROOT/components/cmeps</value>
<value component="cpl" >$SRCROOT/components/cmeps</value>
<value component="drv" >$SRCROOT/components/cmeps</value>
</values>
<group>case_comps</group>
<file>env_case.xml</file>
Expand All @@ -161,12 +156,9 @@
<value component="mom" >$SRCROOT/components/mom/</value>
<value component="nemo" >$SRCROOT/components/nemo/</value>
<value component="blom" >$SRCROOT/components/blom/</value>
<value component="docn" comp_interface="mct" >$SRCROOT/components/cpl7/components/data_comps_$COMP_INTERFACE/docn</value>
<value component="docn" comp_interface="nuopc" >$SRCROOT/components/cdeps/docn</value>
<value component="socn" comp_interface="mct" >$SRCROOT/components/cpl7/components/stub_comps_$COMP_INTERFACE/socn</value>
<value component="socn" comp_interface="nuopc" >$CIMEROOT/CIME/non_py/src/components/stub_comps_$COMP_INTERFACE/socn</value>
<value component="xocn" comp_interface="mct" >$SRCROOT/components/cpl7/components/xcpl_comps_$COMP_INTERFACE/xocn</value>
<value component="xocn" comp_interface="nuopc" >$CIMEROOT/CIME/non_py/src/components/xcpl_comps_$COMP_INTERFACE/xocn</value>
<value component="docn" >$SRCROOT/components/cdeps/docn</value>
<value component="socn" >$CIMEROOT/CIME/non_py/src/components/stub_comps_$COMP_INTERFACE/socn</value>
<value component="xocn" >$CIMEROOT/CIME/non_py/src/components/xcpl_comps_$COMP_INTERFACE/xocn</value>
</values>
<group>case_comps</group>
<file>env_case.xml</file>
Expand All @@ -178,13 +170,10 @@
<type>char</type>
<default_value>unset</default_value>
<values>
<value component="ww3" >$SRCROOT/components/ww3/</value>
<value component="dwav" comp_interface="mct" >$SRCROOT/components/cpl7/components/data_comps_$COMP_INTERFACE/dwav</value>
<value component="dwav" comp_interface="nuopc" >$SRCROOT/components/cdeps/dwav</value>
<value component="swav" comp_interface="mct" >$SRCROOT/components/cpl7/components/stub_comps_$COMP_INTERFACE/swav</value>
<value component="swav" comp_interface="nuopc" >$CIMEROOT/CIME/non_py/src/components/stub_comps_$COMP_INTERFACE/swav</value>
<value component="xwav" comp_interface="mct" >$SRCROOT/components/cpl7/components/xcpl_comps_$COMP_INTERFACE/xwav</value>
<value component="xwav" comp_interface="nuopc" >$CIMEROOT/CIME/non_py/src/components/xcpl_comps_$COMP_INTERFACE/xwav</value>
<value component="ww3" >$SRCROOT/components/ww3/</value>
<value component="dwav" >$SRCROOT/components/cdeps/dwav</value>
<value component="swav" >$CIMEROOT/CIME/non_py/src/components/stub_comps_$COMP_INTERFACE/swav</value>
<value component="xwav" >$CIMEROOT/CIME/non_py/src/components/xcpl_comps_$COMP_INTERFACE/xwav</value>
</values>
<group>case_comps</group>
<file>env_case.xml</file>
Expand All @@ -197,12 +186,9 @@
<default_value>unset</default_value>
<values>
<value component="cism" >$SRCROOT/components/cism/</value>
<value component="dglc" comp_interface="mct" >$SRCROOT/components/cpl7/components/data_comps_$COMP_INTERFACE/dglc</value>
<value component="dglc" comp_interface="nuopc" >$SRCROOT/components/cdeps/dglc</value>
<value component="sglc" comp_interface="mct" >$SRCROOT/components/cpl7/components/stub_comps_$COMP_INTERFACE/sglc</value>
<value component="sglc" comp_interface="nuopc" >$CIMEROOT/CIME/non_py/src/components/stub_comps_$COMP_INTERFACE/sglc</value>
<value component="xglc" comp_interface="mct" >$SRCROOT/components/cpl7/components/xcpl_comps_$COMP_INTERFACE/xglc</value>
<value component="xglc" comp_interface="nuopc" >$CIMEROOT/CIME/non_py/src/components/xcpl_comps_$COMP_INTERFACE/xglc</value>
<value component="dglc" >$SRCROOT/components/cdeps/dglc</value>
<value component="sglc" >$CIMEROOT/CIME/non_py/src/components/stub_comps_$COMP_INTERFACE/sglc</value>
<value component="xglc" >$CIMEROOT/CIME/non_py/src/components/xcpl_comps_$COMP_INTERFACE/xglc</value>
</values>
<group>case_comps</group>
<file>env_case.xml</file>
Expand All @@ -216,12 +202,9 @@
<values>
<value component="cice5" >$SRCROOT/components/cice5/</value>
<value component="cice" >$SRCROOT/components/cice/</value>
<value component="dice" comp_interface="mct" >$SRCROOT/components/cpl7/components/data_comps_$COMP_INTERFACE/dice</value>
<value component="dice" comp_interface="nuopc" >$SRCROOT/components/cdeps/dice</value>
<value component="sice" comp_interface="mct" >$SRCROOT/components/cpl7/components/stub_comps_$COMP_INTERFACE/sice</value>
<value component="sice" comp_interface="nuopc" >$CIMEROOT/CIME/non_py/src/components/stub_comps_$COMP_INTERFACE/sice</value>
<value component="xice" comp_interface="mct" >$SRCROOT/components/cpl7/components/xcpl_comps_$COMP_INTERFACE/xice</value>
<value component="xice" comp_interface="nuopc" >$CIMEROOT/CIME/non_py/src/components/xcpl_comps_$COMP_INTERFACE/xice</value>
<value component="dice" >$SRCROOT/components/cdeps/dice</value>
<value component="sice" >$CIMEROOT/CIME/non_py/src/components/stub_comps_$COMP_INTERFACE/sice</value>
<value component="xice" >$CIMEROOT/CIME/non_py/src/components/xcpl_comps_$COMP_INTERFACE/xice</value>
</values>
<group>case_comps</group>
<file>env_case.xml</file>
Expand All @@ -236,12 +219,9 @@
<value component="rtm" >$SRCROOT/components/rtm/</value>
<value component="mosart" >$SRCROOT/components/mosart/</value>
<value component="mizuroute" >$SRCROOT/components/mizuRoute/</value>
<value component="drof" comp_interface="mct" >$SRCROOT/components/cpl7/components/data_comps_$COMP_INTERFACE/drof</value>
<value component="drof" comp_interface="nuopc" >$SRCROOT/components/cdeps/drof</value>
<value component="srof" comp_interface="mct" >$SRCROOT/components/cpl7/components/stub_comps_$COMP_INTERFACE/srof</value>
<value component="srof" comp_interface="nuopc" >$CIMEROOT/CIME/non_py/src/components/stub_comps_$COMP_INTERFACE/srof</value>
<value component="xrof" comp_interface="mct" >$SRCROOT/components/cpl7/components/xcpl_comps_$COMP_INTERFACE/xrof</value>
<value component="xrof" comp_interface="nuopc" >$CIMEROOT/CIME/non_py/src/components/xcpl_comps_$COMP_INTERFACE/xrof</value>
<value component="drof" >$SRCROOT/components/cdeps/drof</value>
<value component="srof" >$CIMEROOT/CIME/non_py/src/components/stub_comps_$COMP_INTERFACE/srof</value>
<value component="xrof" >$CIMEROOT/CIME/non_py/src/components/xcpl_comps_$COMP_INTERFACE/xrof</value>
</values>
<group>case_comps</group>
<file>env_case.xml</file>
Expand All @@ -255,12 +235,9 @@
<values>
<value component="clm" >$SRCROOT/components/clm/</value>
<value component="slim" >$SRCROOT/components/slim/</value>
<value component="dlnd" comp_interface="mct" >$SRCROOT/components/cpl7/components/data_comps_$COMP_INTERFACE/dlnd</value>
<value component="dlnd" comp_interface="nuopc" >$SRCROOT/components/cdeps/dlnd</value>
<value component="slnd" comp_interface="mct" >$SRCROOT/components/cpl7/components/stub_comps_$COMP_INTERFACE/slnd</value>
<value component="slnd" comp_interface="nuopc" >$CIMEROOT/CIME/non_py/src/components/stub_comps_$COMP_INTERFACE/slnd</value>
<value component="xlnd" comp_interface="mct" >$SRCROOT/components/cpl7/components/xcpl_comps_$COMP_INTERFACE/xlnd</value>
<value component="xlnd" comp_interface="nuopc" >$CIMEROOT/CIME/non_py/src/components/xcpl_comps_$COMP_INTERFACE/xlnd</value>
<value component="dlnd" >$SRCROOT/components/cdeps/dlnd</value>
<value component="slnd" >$CIMEROOT/CIME/non_py/src/components/stub_comps_$COMP_INTERFACE/slnd</value>
<value component="xlnd" >$CIMEROOT/CIME/non_py/src/components/xcpl_comps_$COMP_INTERFACE/xlnd</value>
</values>
<group>case_comps</group>
<file>env_case.xml</file>
Expand All @@ -272,10 +249,8 @@
<type>char</type>
<default_value>unset</default_value>
<values>
<value component="siac" comp_interface="mct" >$SRCROOT/components/cpl7/components/stub_comps_$COMP_INTERFACE/siac</value>
<value component="siac" comp_interface="nuopc" >$CIMEROOT/CIME/non_py/src/components/stub_comps_$COMP_INTERFACE/siac</value>
<value component="xiac" comp_interface="mct" >$SRCROOT/components/cpl7/components/xcpl_comps_$COMP_INTERFACE/xiac</value>
<value component="xiac" comp_interface="nuopc" >$CIMEROOT/CIME/non_py/src/components/xcpl_comps_$COMP_INTERFACE/xiac</value>
<value component="siac" >$CIMEROOT/CIME/non_py/src/components/stub_comps_$COMP_INTERFACE/siac</value>
<value component="xiac" >$CIMEROOT/CIME/non_py/src/components/xcpl_comps_$COMP_INTERFACE/xiac</value>
</values>
<group>case_comps</group>
<file>env_case.xml</file>
Expand All @@ -287,10 +262,8 @@
<type>char</type>
<default_value>unset</default_value>
<values>
<value component="desp" comp_interface="mct" >$SRCROOT/components/cpl7/components/data_comps_$COMP_INTERFACE/desp</value>
<value component="desp" comp_interface="nuopc" >$CIMEROOT/CIME/non_py/src/components/data_comps_$COMP_INTERFACE/desp</value>
<value component="sesp" comp_interface="mct" >$SRCROOT/components/cpl7/components/stub_comps_$COMP_INTERFACE/sesp</value>
<value component="sesp" comp_interface="nuopc" >$CIMEROOT/CIME/non_py/src/components/stub_comps_$COMP_INTERFACE/sesp</value>
<value component="desp" >$CIMEROOT/CIME/non_py/src/components/data_comps_$COMP_INTERFACE/desp</value>
<value component="sesp" >$CIMEROOT/CIME/non_py/src/components/stub_comps_$COMP_INTERFACE/sesp</value>
</values>
<group>case_comps</group>
<file>env_case.xml</file>
Expand Down Expand Up @@ -452,13 +425,13 @@
<value component="mom" >$COMP_ROOT_DIR_OCN/cime_config/testdefs/testmods_dirs</value>
<value component="nemo" >$COMP_ROOT_DIR_OCN/cime_config/testdefs/testmods_dirs</value>
<value component="blom" >$COMP_ROOT_DIR_OCN/cime_config/testdefs/testmods_dirs</value>
<value component="datm" comp_interface="nuopc" >$SRCROOT/components/cdeps/datm/cime_config/testdefs/testmods_dirs</value>
<value component="dice" comp_interface="nuopc" >$SRCROOT/components/cdeps/dice/cime_config/testdefs/testmods_dirs</value>
<value component="dlnd" comp_interface="nuopc" >$SRCROOT/components/cdeps/dlnd/cime_config/testdefs/testmods_dirs</value>
<value component="docn" comp_interface="nuopc" >$SRCROOT/components/cdeps/docn/cime_config/testdefs/testmods_dirs</value>
<value component="drof" comp_interface="nuopc" >$SRCROOT/components/cdeps/drof/cime_config/testdefs/testmods_dirs</value>
<value component="dglc" comp_interface="nuopc" >$SRCROOT/components/cdeps/dglc/cime_config/testdefs/testmods_dirs</value>
<value component="dwav" comp_interface="nuopc" >$SRCROOT/components/cdeps/dwav/cime_config/testdefs/testmods_dirs</value>
<value component="datm" >$SRCROOT/components/cdeps/datm/cime_config/testdefs/testmods_dirs</value>
<value component="dice" >$SRCROOT/components/cdeps/dice/cime_config/testdefs/testmods_dirs</value>
<value component="dlnd" >$SRCROOT/components/cdeps/dlnd/cime_config/testdefs/testmods_dirs</value>
<value component="docn" >$SRCROOT/components/cdeps/docn/cime_config/testdefs/testmods_dirs</value>
<value component="drof" >$SRCROOT/components/cdeps/drof/cime_config/testdefs/testmods_dirs</value>
<value component="dglc" >$SRCROOT/components/cdeps/dglc/cime_config/testdefs/testmods_dirs</value>
<value component="dwav" >$SRCROOT/components/cdeps/dwav/cime_config/testdefs/testmods_dirs</value>
</values>
<group>case_last</group>
<file>env_case.xml</file>
Expand Down Expand Up @@ -543,8 +516,7 @@
<entry id="CONFIG_CPL_FILE_MODEL_SPECIFIC">
<type>char</type>
<values>
<value comp_interface="nuopc">$SRCROOT/components/cmeps/cime_config/config_component_$MODEL.xml</value> -->
<value comp_interface="mct">$SRCROOT/components/cpl7/driver/cime_config/config_component_$MODEL.xml</value> -->
<value>$SRCROOT/components/cmeps/cime_config/config_component_$MODEL.xml</value> -->
</values>
<group>case_last</group>
<file>env_case.xml</file>
Expand Down
29 changes: 19 additions & 10 deletions CIME/locked_files.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import glob
from pathlib import Path

from CIME.utils import safe_copy
Expand Down Expand Up @@ -55,7 +54,7 @@ def is_locked(filename, caseroot):
return os.path.exists(os.path.join(caseroot, LOCKED_DIR, filename))


def check_lockedfiles(case, skip=None):
def check_lockedfiles(case, skip=None, quiet=False, caseroot=None, whitelist=None):
"""
Check that all lockedfiles match what's in case
Expand All @@ -66,28 +65,35 @@ def check_lockedfiles(case, skip=None):
elif isinstance(skip, str):
skip = [skip]

caseroot = case.get_value("CASEROOT")
if caseroot is None:
caseroot = case.get_value("CASEROOT")

locked_path = Path(caseroot, LOCKED_DIR)

lockedfiles = glob.glob(os.path.join(caseroot, LOCKED_DIR, "*.xml"))
lockedfiles = locked_path.glob("*.xml")

# filter based on whitelist
if whitelist is not None:
lockedfiles = [x for x in lockedfiles if x.stem in whitelist]

for file_path in lockedfiles:
filename = os.path.basename(file_path)
filename = file_path.name

# Skip files used for tests e.g. env_mach_pes.ERP1.xml or included in skip list
if filename.count(".") > 1 or any([filename.startswith(x) for x in skip]):
continue

check_lockedfile(case, filename, caseroot=caseroot)
check_lockedfile(case, f"{filename}", caseroot=caseroot, quiet=quiet)


def check_lockedfile(case, filebase, caseroot=None):
def check_lockedfile(case, filebase, caseroot=None, quiet=False):
if caseroot is None:
caseroot = case.get_value("CASEROOT")

env_name, diff = diff_lockedfile(case, caseroot, filebase)

if diff:
check_diff(case, filebase, env_name, diff)
check_diff(case, filebase, env_name, diff, quiet=quiet)


def diff_lockedfile(case, caseroot, filename):
Expand Down Expand Up @@ -138,7 +144,7 @@ def _get_case_env(case, caseroot, locked_file, env_name):
return l_env, r_env


def check_diff(case, filename, env_name, diff):
def check_diff(case, filename, env_name, diff, quiet=False):
logger.warning("Detected diff in locked file {!r}".format(filename))

# Remove BUILD_COMPLETE, invalid entry in diff
Expand Down Expand Up @@ -207,4 +213,7 @@ def check_diff(case, filename, env_name, diff):

message = f"{message}./case.build {clean_targets}\n./case.build"

expect(False, message)
if quiet:
logger.info(message)
else:
expect(False, message)
2 changes: 1 addition & 1 deletion CIME/tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def _create_test(
driver = utils.get_cime_default_driver()
if driver == "nuopc" and "cime_developer" in extra_args:
extra_args.append(
" ^SMS_Ln3.T42_T42.S ^PRE.f19_f19.ADESP_TEST ^PRE.f19_f19.ADESP ^DAE.ww3a.ADWAV"
" ^SMS_Ln3.T42_T42.S ^PRE.f19_f19.ADESP_TEST ^PRE.f19_f19.ADESP ^DAE.ww3a.ADWAV ^IRT_N2_Vmct_Ln9.f19_g16_rx1.A"
)

test_id = (
Expand Down
Loading

0 comments on commit f903115

Please sign in to comment.