Skip to content

Commit 22eed88

Browse files
authored
Merge pull request #4660 from ESMCI/add_case_git
Add case git
2 parents bc55af9 + c4d8638 commit 22eed88

24 files changed

+464
-144
lines changed

CIME/SystemTests/funit.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
from CIME.XML.standard_module_setup import *
66
from CIME.SystemTests.system_tests_common import SystemTestsCommon
77
from CIME.build import post_build
8-
from CIME.utils import append_testlog, get_cime_root
8+
from CIME.status import append_testlog
9+
from CIME.utils import get_cime_root
910
from CIME.test_status import *
1011

1112
logger = logging.getLogger(__name__)

CIME/SystemTests/hommebaseclass.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
from CIME.XML.standard_module_setup import *
55
from CIME.SystemTests.system_tests_common import SystemTestsCommon
66
from CIME.build import post_build
7-
from CIME.utils import append_testlog, SharedArea
7+
from CIME.status import append_testlog
8+
from CIME.utils import SharedArea
89
from CIME.test_status import *
910

1011
import shutil
11-
from distutils import dir_util
1212

1313
logger = logging.getLogger(__name__)
1414

@@ -97,10 +97,9 @@ def run_phase(self):
9797
shutil.rmtree(full_baseline_dir)
9898

9999
with SharedArea():
100-
dir_util.copy_tree(
100+
shutil.copytree(
101101
os.path.join(exeroot, "tests", "baseline"),
102102
full_baseline_dir,
103-
preserve_mode=False,
104103
)
105104

106105
elif compare:

CIME/SystemTests/mvk.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010
import json
1111
import logging
1212

13-
from distutils import dir_util
13+
from shutils import copytree
1414

1515
import CIME.test_status
1616
import CIME.utils
17+
from CIME.status import append_testlog
1718
from CIME.SystemTests.system_tests_common import SystemTestsCommon
1819
from CIME.case.case_setup import case_setup
1920
from CIME.XML.machines import Machines
@@ -173,10 +174,9 @@ def _compare_baseline(self):
173174
urlroot = CIME.utils.get_urlroot(mach_obj)
174175
if htmlroot is not None:
175176
with CIME.utils.SharedArea():
176-
dir_util.copy_tree(
177+
copytree(
177178
evv_out_dir,
178179
os.path.join(htmlroot, "evv", case_name),
179-
preserve_mode=False,
180180
)
181181
if urlroot is None:
182182
urlroot = "[{}_URL]".format(mach_name.capitalize())
@@ -203,4 +203,4 @@ def _compare_baseline(self):
203203
)
204204
)
205205

206-
CIME.utils.append_testlog(comments, self._orig_caseroot)
206+
append_testlog(comments, self._orig_caseroot)

CIME/SystemTests/pgn.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@
1616
import logging
1717

1818
from collections import OrderedDict
19-
from distutils import dir_util
19+
from shutils import copytree
2020

2121
import pandas as pd
2222
import numpy as np
2323

2424

2525
import CIME.test_status
2626
import CIME.utils
27+
from CIME.status import append_testlog
2728
from CIME.SystemTests.system_tests_common import SystemTestsCommon
2829
from CIME.case.case_setup import case_setup
2930
from CIME.XML.machines import Machines
@@ -80,7 +81,7 @@ def build_phase(self, sharedlib_only=False, model_only=False):
8081
if not model_only:
8182
# Lay all of the components out concurrently
8283
logger.debug(
83-
"PGN_INFO: Updating NINST for multi-instance in " "env_mach_pes.xml"
84+
"PGN_INFO: Updating NINST for multi-instance in env_mach_pes.xml"
8485
)
8586
for comp in ["ATM", "OCN", "WAV", "GLC", "ICE", "ROF", "LND"]:
8687
ntasks = self._case.get_value("NTASKS_{}".format(comp))
@@ -224,10 +225,9 @@ def _compare_baseline(self):
224225
urlroot = CIME.utils.get_urlroot(mach_obj)
225226
if htmlroot is not None:
226227
with CIME.utils.SharedArea():
227-
dir_util.copy_tree(
228+
copytree(
228229
evv_out_dir,
229230
os.path.join(htmlroot, "evv", case_name),
230-
preserve_mode=False,
231231
)
232232
if urlroot is None:
233233
urlroot = "[{}_URL]".format(mach_name.capitalize())
@@ -253,7 +253,7 @@ def _compare_baseline(self):
253253
)
254254
)
255255

256-
CIME.utils.append_testlog(comments, self._orig_caseroot)
256+
append_testlog(comments, self._orig_caseroot)
257257

258258
def run_phase(self):
259259
logger.debug("PGN_INFO: RUN PHASE")

CIME/SystemTests/system_tests_common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
from CIME.XML.standard_module_setup import *
55
from CIME.XML.env_run import EnvRun
66
from CIME.XML.env_test import EnvTest
7+
from CIME.status import append_testlog
78
from CIME.utils import (
8-
append_testlog,
99
get_model,
1010
safe_copy,
1111
get_timestamp,

CIME/SystemTests/tsc.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@
1111
import json
1212
import logging
1313

14-
from distutils import dir_util
14+
from shutil import copytree
1515

1616
import CIME.test_status
1717
import CIME.utils
18+
from CIME.status import append_testlog
1819
from CIME.SystemTests.system_tests_common import SystemTestsCommon
1920
from CIME.case.case_setup import case_setup
2021
from CIME.hist_utils import rename_all_hist_files
@@ -213,10 +214,9 @@ def _compare_baseline(self):
213214
urlroot = CIME.utils.get_urlroot(mach_obj)
214215
if htmlroot is not None:
215216
with CIME.utils.SharedArea():
216-
dir_util.copy_tree(
217+
copytree(
217218
evv_out_dir,
218219
os.path.join(htmlroot, "evv", case_name),
219-
preserve_mode=False,
220220
)
221221
if urlroot is None:
222222
urlroot = "[{}_URL]".format(mach_name.capitalize())
@@ -243,7 +243,7 @@ def _compare_baseline(self):
243243
)
244244
)
245245

246-
CIME.utils.append_testlog(comments, self._orig_caseroot)
246+
append_testlog(comments, self._orig_caseroot)
247247

248248
def _generate_baseline(self):
249249
super(TSC, self)._generate_baseline()

CIME/Tools/xmlchange

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,10 @@ from standard_script_setup import *
5555
from CIME.utils import (
5656
expect,
5757
convert_to_type,
58-
append_case_status,
5958
get_batch_script_for_job,
59+
Timeout,
6060
)
61+
from CIME.status import append_case_status
6162
from CIME.case import Case
6263
from CIME.locked_files import check_lockedfiles
6364

@@ -246,6 +247,40 @@ def xmlchange_single_value(
246247
if xmlid == "JOB_QUEUE":
247248
case.set_value("USER_REQUESTED_QUEUE", xmlval, subgroup)
248249

250+
# if CASE_GIT_REPOSITORY is updated set the remote to the new repo
251+
# note that if origin exists and is different than CASE_GIT_REPOSITORY it
252+
# will be deleted and replaced
253+
if xmlid == "CASE_GIT_REPOSITORY":
254+
if not case._gitinterface:
255+
logger.warning(
256+
"You must run case.setup before you can set CASE_GIT_REPOSITORY"
257+
)
258+
return
259+
remote = case._gitinterface.git_operation("remote")
260+
if remote:
261+
if remote == xmlval:
262+
return
263+
else:
264+
case._gitinterface.git_operation("remote", "rm", remote)
265+
branch = case._gitinterface.git_operation("branch").split()[1]
266+
remote_branches = ""
267+
with Timeout(30):
268+
remote_branches = case._gitinterface.git_operation(
269+
"ls-remote", "--heads", xmlval
270+
)
271+
chk = remote_branches.find("refs/heads/" + branch)
272+
273+
if chk >= 0:
274+
expect(
275+
False,
276+
" Could not set {} to {}, remote branch {} already exists, Rename case and try again.".format(
277+
xmlid, xmlval, branch
278+
),
279+
)
280+
with Timeout(30):
281+
case._gitinterface.git_operation("remote", "add", "origin", xmlval)
282+
case._gitinterface.git_operation("push", "--set-upstream", "origin", branch)
283+
249284

250285
def xmlchange(
251286
caseroot,
@@ -321,7 +356,13 @@ def xmlchange(
321356
for arg in sys.argv:
322357
argstr += "%s " % arg
323358
msg = "<command> %s </command>" % (argstr)
324-
append_case_status("xmlchange", "success", msg=msg, caseroot=caseroot)
359+
append_case_status(
360+
"xmlchange",
361+
"success",
362+
msg=msg,
363+
caseroot=caseroot,
364+
gitinterface=case._gitinterface,
365+
)
325366

326367

327368
def _main_func(description):

CIME/XML/env_batch.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -919,7 +919,6 @@ def _submit_single_job(
919919
resubmit_immediate=False,
920920
workflow=True,
921921
):
922-
923922
if not dry_run:
924923
logger.warning("Submit job {}".format(job))
925924
batch_system = self.get_value("BATCH_SYSTEM", subgroup=None)
@@ -1080,19 +1079,19 @@ def _submit_single_job(
10801079
submitargs,
10811080
run_args,
10821081
batchredirect,
1083-
get_batch_script_for_job(job),
1082+
os.path.join(self._caseroot, get_batch_script_for_job(job)),
10841083
)
10851084
else:
10861085
sequence = (
10871086
batchsubmit,
10881087
submitargs,
10891088
batchredirect,
1090-
get_batch_script_for_job(job),
1089+
os.path.join(self._caseroot, get_batch_script_for_job(job)),
10911090
run_args,
10921091
)
10931092

10941093
submitcmd = " ".join(s.strip() for s in sequence if s is not None)
1095-
if submitcmd.startswith("ssh"):
1094+
if submitcmd.startswith("ssh") and "$CASEROOT" in submitcmd:
10961095
# add ` before cd $CASEROOT and at end of command
10971096
submitcmd = submitcmd.replace("cd $CASEROOT", "'cd $CASEROOT") + "'"
10981097

@@ -1385,7 +1384,6 @@ def make_all_batch_files(self, case):
13851384
template = case.get_resolved_value(
13861385
env_workflow.get_value("template", subgroup=job)
13871386
)
1388-
13891387
if os.path.isabs(template):
13901388
input_batch_script = template
13911389
else:

CIME/build.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
import glob, shutil, time, threading, subprocess
55
from pathlib import Path
66
from CIME.XML.standard_module_setup import *
7+
from CIME.status import run_and_log_case_status
78
from CIME.utils import (
89
get_model,
910
analyze_build_log,
1011
stringify_bool,
11-
run_and_log_case_status,
1212
get_timestamp,
1313
run_sub_or_cmd,
1414
run_cmd,
@@ -1318,13 +1318,18 @@ def case_build(
13181318
cb = cb + " (SHAREDLIB_BUILD)"
13191319
if model_only == True:
13201320
cb = cb + " (MODEL_BUILD)"
1321-
return run_and_log_case_status(functor, cb, caseroot=caseroot)
1321+
return run_and_log_case_status(
1322+
functor, cb, caseroot=caseroot, gitinterface=case._gitinterface
1323+
)
13221324

13231325

13241326
###############################################################################
13251327
def clean(case, cleanlist=None, clean_all=False, clean_depends=None):
13261328
###############################################################################
13271329
functor = lambda: _clean_impl(case, cleanlist, clean_all, clean_depends)
13281330
return run_and_log_case_status(
1329-
functor, "build.clean", caseroot=case.get_value("CASEROOT")
1331+
functor,
1332+
"build.clean",
1333+
caseroot=case.get_value("CASEROOT"),
1334+
gitinterface=case._gitinterface,
13301335
)

CIME/case/case.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@
1313
# pylint: disable=import-error,redefined-builtin
1414
from CIME import utils
1515
from CIME.config import Config
16-
from CIME.utils import expect, get_cime_root, append_status
16+
from CIME.status import append_status
17+
from CIME.utils import expect, get_cime_root
1718
from CIME.utils import convert_to_type, get_model, set_model
1819
from CIME.utils import get_project, get_charge_account, check_name
1920
from CIME.utils import get_current_commit, safe_copy, get_cime_default_driver
21+
from CIME.gitinterface import GitInterface
2022
from CIME.locked_files import LOCKED_DIR, lock_file
2123
from CIME.XML.machines import Machines
2224
from CIME.XML.pes import Pes
@@ -77,7 +79,7 @@ class Case(object):
7779
7880
"""
7981

80-
from CIME.case.case_setup import case_setup
82+
from CIME.case.case_setup import case_setup, _create_case_repo
8183
from CIME.case.case_clone import create_clone, _copy_user_modified_to_clone
8284
from CIME.case.case_test import case_test
8385
from CIME.case.case_submit import check_DA_settings, check_case, submit
@@ -98,7 +100,6 @@ class Case(object):
98100
)
99101

100102
def __init__(self, case_root=None, read_only=True, record=False, non_local=False):
101-
102103
if case_root is None:
103104
case_root = os.getcwd()
104105
expect(
@@ -164,7 +165,7 @@ def __init__(self, case_root=None, read_only=True, record=False, non_local=False
164165
self._component_description = {}
165166
self._is_env_loaded = False
166167
self._loaded_envs = None
167-
168+
self._gitinterface = None
168169
# these are user_mods as defined in the compset
169170
# Command Line user_mods are handled seperately
170171

@@ -199,6 +200,10 @@ def __init__(self, case_root=None, read_only=True, record=False, non_local=False
199200
mach == probed_machine,
200201
f"Current machine {probed_machine} does not match case machine {mach}.",
201202
)
203+
if os.path.exists(os.path.join(self.get_value("CASEROOT"), ".git")):
204+
self._gitinterface = GitInterface(
205+
self.get_value("CASEROOT"), logger
206+
)
202207

203208
self.initialize_derived_attributes()
204209

@@ -682,7 +687,6 @@ def _set_compset(self, compset_name, files):
682687
# Loop through all of the files listed in COMPSETS_SPEC_FILE and find the file
683688
# that has a match for either the alias or the longname in that order
684689
for component in components:
685-
686690
# Determine the compsets file for this component
687691
compsets_filename = files.get_value(
688692
"COMPSETS_SPEC_FILE", {"component": component}
@@ -1284,7 +1288,6 @@ def configure(
12841288
gpu_type=None,
12851289
gpu_offload=None,
12861290
):
1287-
12881291
expect(
12891292
check_name(compset_name, additional_chars="."),
12901293
"Invalid compset name {}".format(compset_name),

0 commit comments

Comments
 (0)