Skip to content

Commit ba4f9e9

Browse files
committed
Merge branch 'development' into feature/pfunit-integration
2 parents a0ec7a8 + 03e12bd commit ba4f9e9

File tree

13 files changed

+105
-91
lines changed

13 files changed

+105
-91
lines changed

.gitmodules

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[submodule "ccpp-framework"]
22
path = ccpp_framework
33
url = https://github.com/NCAR/ccpp-framework
4-
fxtag = 2024-11-07-dev
4+
fxtag = 2025-01-06-dev
55
fxrequired = AlwaysRequired
66
fxDONOTUSEurl = https://github.com/NCAR/ccpp-framework
77
[submodule "history"]
@@ -20,7 +20,7 @@
2020
[submodule "ncar-physics"]
2121
path = src/physics/ncar_ccpp
2222
url = https://github.com/ESCOMP/atmospheric_physics
23-
fxtag = 491e56247815ef23bfd8dba65d1e3c3b78ba164a
23+
fxtag = 74e905b7a0ee5b2d2bfc3e3dd942eb9963398373
2424
fxrequired = AlwaysRequired
2525
fxDONOTUSEurl = https://github.com/ESCOMP/atmospheric_physics
2626
[submodule "ccs_config"]

.lib/git-fleximod/git_fleximod/cli.py

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,31 @@
22
import argparse
33
from git_fleximod import utils
44

5-
__version__ = "0.8.4"
5+
__version__ = "0.9.4"
66

77
def find_root_dir(filename=".gitmodules"):
88
""" finds the highest directory in tree
99
which contains a file called filename """
10-
d = Path.cwd()
11-
root = Path(d.root)
12-
dirlist = []
13-
dl = d
14-
while dl != root:
15-
dirlist.append(dl)
16-
dl = dl.parent
17-
dirlist.append(root)
18-
dirlist.reverse()
19-
20-
for dl in dirlist:
21-
attempt = dl / filename
22-
if attempt.is_file():
23-
return str(dl)
24-
return None
25-
10+
try:
11+
root = utils.execute_subprocess(["git","rev-parse", "--show-toplevel"],
12+
output_to_caller=True ).rstrip()
13+
except:
14+
d = Path.cwd()
15+
root = Path(d.root)
16+
dirlist = []
17+
dl = d
18+
while dl != root:
19+
dirlist.append(dl)
20+
dl = dl.parent
21+
dirlist.append(root)
22+
dirlist.reverse()
23+
24+
for dl in dirlist:
25+
attempt = dl / filename
26+
if attempt.is_file():
27+
return str(dl)
28+
return None
29+
return Path(root)
2630

2731
def get_parser():
2832
description = """

.lib/git-fleximod/git_fleximod/git_fleximod.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ def submodule_sparse_checkout(root_dir, name, url, path, sparsefile, tag="master
124124
# set the repository remote
125125

126126
logger.info("Setting remote origin in {}/{}".format(root_dir, path))
127-
status = sprepo_git.git_operation("remote", "-v")
128-
if url not in status:
127+
_, remotelist = sprepo_git.git_operation("remote", "-v")
128+
if url not in remotelist:
129129
sprepo_git.git_operation("remote", "add", "origin", url)
130130

131131
topgit = os.path.join(gitroot, ".git")
@@ -181,6 +181,8 @@ def init_submodule_from_gitmodules(gitmodules, name, root_dir, logger):
181181
url = gitmodules.get(name, "url")
182182
assert path and url, f"Malformed .gitmodules file {path} {url}"
183183
tag = gitmodules.get(name, "fxtag")
184+
if not tag:
185+
tag = gitmodules.get(name, "hash")
184186
fxurl = gitmodules.get(name, "fxDONOTUSEurl")
185187
fxsparse = gitmodules.get(name, "fxsparse")
186188
fxrequired = gitmodules.get(name, "fxrequired")
@@ -213,7 +215,7 @@ def submodules_status(gitmodules, root_dir, toplevel=False, depth=0):
213215

214216
def git_toplevelroot(root_dir, logger):
215217
rgit = GitInterface(root_dir, logger)
216-
superroot = rgit.git_operation("rev-parse", "--show-superproject-working-tree")
218+
_, superroot = rgit.git_operation("rev-parse", "--show-superproject-working-tree")
217219
return superroot
218220

219221
def submodules_update(gitmodules, root_dir, requiredlist, force):
@@ -250,7 +252,6 @@ def submodules_update(gitmodules, root_dir, requiredlist, force):
250252
newrequiredlist = ["AlwaysRequired"]
251253
if optional:
252254
newrequiredlist.append("AlwaysOptional")
253-
254255
submodules_update(gitsubmodules, repodir, newrequiredlist, force=force)
255256

256257
def local_mods_output():
@@ -342,7 +343,7 @@ def main():
342343
excludelist=excludelist,
343344
)
344345
if not gitmodules.sections():
345-
sys.exit("No submodule components found")
346+
sys.exit(f"No submodule components found, root_dir={root_dir}")
346347
retval = 0
347348
if action == "update":
348349
submodules_update(gitmodules, root_dir, fxrequired, force)

.lib/git-fleximod/git_fleximod/gitinterface.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,12 @@ def git_operation(self, operation, *args, **kwargs):
5959
command = self._git_command(operation, *newargs)
6060
if isinstance(command, list):
6161
try:
62-
return utils.execute_subprocess(command, output_to_caller=True)
62+
status, output = utils.execute_subprocess(command, status_to_caller=True, output_to_caller=True)
63+
return status, output.rstrip()
6364
except Exception as e:
6465
sys.exit(e)
6566
else:
66-
return command
67+
return 0, command
6768

6869
def config_get_value(self, section, name):
6970
if self._use_module:
@@ -81,6 +82,8 @@ def config_get_value(self, section, name):
8182
def config_set_value(self, section, name, value):
8283
if self._use_module:
8384
with self.repo.config_writer() as writer:
85+
if "." in section:
86+
section = section.replace("."," \"")+'"'
8487
writer.set_value(section, name, value)
8588
writer.release() # Ensure changes are saved
8689
else:

.lib/git-fleximod/git_fleximod/submodule.py

Lines changed: 57 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,9 @@ def status(self):
6060
if not os.path.exists(os.path.join(smpath, ".git")):
6161
rootgit = GitInterface(self.root_dir, self.logger)
6262
# submodule commands use path, not name
63-
tags = rootgit.git_operation("ls-remote", "--tags", self.url)
64-
result = rootgit.git_operation("submodule","status",smpath).split()
63+
status, tags = rootgit.git_operation("ls-remote", "--tags", self.url)
64+
status, result = rootgit.git_operation("submodule","status",smpath)
65+
result = result.split()
6566

6667
if result:
6768
ahash = result[0][1:]
@@ -80,9 +81,9 @@ def status(self):
8081
result = f"e {self.name:>20} not checked out, aligned at tag {self.fxtag}{optional}"
8182
needsupdate = True
8283
elif self.fxtag:
83-
ahash = rootgit.git_operation(
84+
status, ahash = rootgit.git_operation(
8485
"submodule", "status", "{}".format(self.path)
85-
).rstrip()
86+
)
8687
ahash = ahash[1 : len(self.fxtag) + 1]
8788
if self.fxtag == ahash:
8889
result = f"e {self.name:>20} not checked out, aligned at hash {ahash}{optional}"
@@ -96,14 +97,15 @@ def status(self):
9697
else:
9798
with utils.pushd(smpath):
9899
git = GitInterface(smpath, self.logger)
99-
remote = git.git_operation("remote").rstrip()
100+
status, remote = git.git_operation("remote")
100101
if remote == '':
101102
result = f"e {self.name:>20} has no associated remote"
102103
testfails = True
103104
needsupdate = True
104105
return result, needsupdate, localmods, testfails
105-
rurl = git.git_operation("ls-remote","--get-url").rstrip()
106-
line = git.git_operation("log", "--pretty=format:\"%h %d\"").partition('\n')[0]
106+
status, rurl = git.git_operation("ls-remote","--get-url")
107+
status, lines = git.git_operation("log", "--pretty=format:\"%h %d\"")
108+
line = lines.partition('\n')[0]
107109
parts = line.split()
108110
ahash = parts[0][1:]
109111
atag = None
@@ -120,7 +122,7 @@ def status(self):
120122

121123

122124
#print(f"line is {line} ahash is {ahash} atag is {atag} {parts}")
123-
# atag = git.git_operation("describe", "--tags", "--always").rstrip()
125+
# atag = git.git_operation("describe", "--tags", "--always")
124126
# ahash = git.git_operation("rev-list", "HEAD").partition("\n")[0]
125127

126128
recurse = False
@@ -149,10 +151,10 @@ def status(self):
149151
result = f"e {self.name:>20} has no fxtag defined in .gitmodules, module at {ahash}"
150152
testfails = False
151153

152-
status = git.git_operation("status", "--ignore-submodules", "-uno")
153-
if "nothing to commit" not in status:
154+
status, output = git.git_operation("status", "--ignore-submodules", "-uno")
155+
if "nothing to commit" not in output:
154156
localmods = True
155-
result = "M" + textwrap.indent(status, " ")
157+
result = "M" + textwrap.indent(output, " ")
156158
# print(f"result {result} needsupdate {needsupdate} localmods {localmods} testfails {testfails}")
157159
return result, needsupdate, localmods, testfails
158160

@@ -171,10 +173,11 @@ def _add_remote(self, git):
171173
Returns:
172174
str: The name of the new remote if added, or the name of the existing remote that matches the submodule's URL.
173175
"""
174-
remotes = git.git_operation("remote", "-v").splitlines()
176+
status, remotes = git.git_operation("remote", "-v")
177+
remotes = remotes.splitlines()
175178
upstream = None
176179
if remotes:
177-
upstream = git.git_operation("ls-remote", "--get-url").rstrip()
180+
status, upstream = git.git_operation("ls-remote", "--get-url")
178181
newremote = "newremote.00"
179182
tmpurl = self.url.replace("git@github.com:", "https://github.com/")
180183
line = next((s for s in remotes if self.url in s or tmpurl in s), None)
@@ -183,7 +186,7 @@ def _add_remote(self, git):
183186
return newremote
184187
else:
185188
i = 0
186-
while "newremote" in remotes:
189+
while newremote in remotes:
187190
i = i + 1
188191
newremote = f"newremote.{i:02d}"
189192
else:
@@ -214,12 +217,19 @@ def sparse_checkout(self):
214217
"""
215218
self.logger.info("Called sparse_checkout for {}".format(self.name))
216219
rgit = GitInterface(self.root_dir, self.logger)
217-
superroot = rgit.git_operation("rev-parse", "--show-superproject-working-tree")
220+
status, superroot = rgit.git_operation("rev-parse", "--show-superproject-working-tree")
218221
if superroot:
219222
gitroot = superroot.strip()
220223
else:
221-
gitroot = self.root_dir.strip()
222-
assert os.path.isdir(os.path.join(gitroot, ".git"))
224+
gitroot = self.root_dir
225+
# Now need to move the .git dir to the submodule location
226+
rootdotgit = os.path.join(self.root_dir, ".git")
227+
while os.path.isfile(rootdotgit):
228+
with open(rootdotgit) as f:
229+
line = f.readline().rstrip()
230+
if line.startswith("gitdir: "):
231+
rootdotgit = os.path.abspath(os.path.join(self.root_dir,line[8:]))
232+
assert os.path.isdir(rootdotgit)
223233
# first create the module directory
224234
if not os.path.isdir(os.path.join(self.root_dir, self.path)):
225235
os.makedirs(os.path.join(self.root_dir, self.path))
@@ -244,8 +254,8 @@ def sparse_checkout(self):
244254
# set the repository remote
245255

246256
self.logger.info("Setting remote origin in {}/{}".format(self.root_dir, self.path))
247-
status = sprepo_git.git_operation("remote", "-v")
248-
if self.url not in status:
257+
status, remotes = sprepo_git.git_operation("remote", "-v")
258+
if self.url not in remotes:
249259
sprepo_git.git_operation("remote", "add", "origin", self.url)
250260

251261
topgit = os.path.join(gitroot, ".git")
@@ -256,46 +266,46 @@ def sparse_checkout(self):
256266
os.path.join(self.root_dir, f.read().split()[1]),
257267
start=os.path.join(self.root_dir, self.path),
258268
)
259-
topgit = os.path.join(gitpath, "modules")
269+
rootdotgit = os.path.join(gitpath, "modules", self.name)
260270
else:
261-
topgit = os.path.relpath(
262-
os.path.join(self.root_dir, ".git", "modules"),
271+
rootdotgit = os.path.relpath(
272+
os.path.join(self.root_dir, ".git", "modules", self.name),
263273
start=os.path.join(self.root_dir, self.path),
264274
)
265275

266-
with utils.pushd(sprep_repo):
267-
if not os.path.isdir(topgit):
268-
os.makedirs(topgit)
269-
topgit += os.sep + self.name
270-
271276
if os.path.isdir(os.path.join(self.root_dir, self.path, ".git")):
272277
with utils.pushd(sprep_repo):
273-
if os.path.isdir(os.path.join(topgit,".git")):
274-
shutil.rmtree(os.path.join(topgit,".git"))
275-
shutil.move(".git", topgit)
278+
if os.path.isdir(os.path.join(rootdotgit,".git")):
279+
shutil.rmtree(os.path.join(rootdotgit,".git"))
280+
shutil.move(".git", rootdotgit)
276281
with open(".git", "w") as f:
277-
f.write("gitdir: " + os.path.relpath(topgit))
278-
# assert(os.path.isdir(os.path.relpath(topgit, start=sprep_repo)))
279-
gitsparse = os.path.abspath(os.path.join(topgit, "info", "sparse-checkout"))
282+
f.write("gitdir: " + os.path.relpath(rootdotgit))
283+
infodir = os.path.join(rootdotgit, "info")
284+
if not os.path.isdir(infodir):
285+
os.makedirs(infodir)
286+
gitsparse = os.path.abspath(os.path.join(infodir, "sparse-checkout"))
280287
if os.path.isfile(gitsparse):
281288
self.logger.warning(
282-
"submodule {} is already initialized {}".format(self.name, topgit)
289+
"submodule {} is already initialized {}".format(self.name, rootdotgit)
283290
)
284291
return
285292

286293
with utils.pushd(sprep_repo):
287294
if os.path.isfile(self.fxsparse):
295+
288296
shutil.copy(self.fxsparse, gitsparse)
289297

290298

291299
# Finally checkout the repo
292300
sprepo_git.git_operation("fetch", "origin", "--tags")
293-
sprepo_git.git_operation("checkout", self.fxtag)
294-
295-
print(f"Successfully checked out {self.name:>20} at {self.fxtag}")
296-
rgit.config_set_value(f'submodule "{self.name}"', "active", "true")
297-
rgit.config_set_value(f'submodule "{self.name}"', "url", self.url)
298-
rgit.config_set_value(f'submodule "{self.name}"', "path", self.path)
301+
status,_ = sprepo_git.git_operation("checkout", self.fxtag)
302+
if status:
303+
print(f"Error checking out {self.name:>20} at {self.fxtag}")
304+
else:
305+
print(f"Successfully checked out {self.name:>20} at {self.fxtag}")
306+
rgit.config_set_value('submodule.' + self.name, "active", "true")
307+
rgit.config_set_value('submodule.' + self.name, "url", self.url)
308+
rgit.config_set_value('submodule.' + self.name, "path", self.path)
299309

300310
def update(self):
301311
"""
@@ -342,15 +352,15 @@ def update(self):
342352
git.git_operation("clone", self.url, self.path)
343353
smgit = GitInterface(repodir, self.logger)
344354
if not tag:
345-
tag = smgit.git_operation("describe", "--tags", "--always").rstrip()
355+
status, tag = smgit.git_operation("describe", "--tags", "--always")
346356
smgit.git_operation("checkout", tag)
347357
# Now need to move the .git dir to the submodule location
348358
rootdotgit = os.path.join(self.root_dir, ".git")
349359
if os.path.isfile(rootdotgit):
350360
with open(rootdotgit) as f:
351361
line = f.readline()
352362
if line.startswith("gitdir: "):
353-
rootdotgit = line[8:].rstrip()
363+
rootdotgit = line[8:]
354364

355365
newpath = os.path.abspath(os.path.join(self.root_dir, rootdotgit, "modules", self.name))
356366
if os.path.exists(newpath):
@@ -393,15 +403,16 @@ def update(self):
393403
git = GitInterface(submoddir, self.logger)
394404
# first make sure the url is correct
395405
newremote = self._add_remote(git)
396-
tags = git.git_operation("tag", "-l")
406+
status, tags = git.git_operation("tag", "-l")
397407
fxtag = self.fxtag
398408
if fxtag and fxtag not in tags:
399409
git.git_operation("fetch", newremote, "--tags")
400-
atag = git.git_operation("describe", "--tags", "--always").rstrip()
410+
status, atag = git.git_operation("describe", "--tags", "--always")
401411
if fxtag and fxtag != atag:
402412
try:
403-
git.git_operation("checkout", fxtag)
404-
print(f"{self.name:>20} updated to {fxtag}")
413+
status, _ = git.git_operation("checkout", fxtag)
414+
if not status:
415+
print(f"{self.name:>20} updated to {fxtag}")
405416
except Exception as error:
406417
print(error)
407418

.lib/git-fleximod/git_fleximod/utils.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -307,12 +307,12 @@ def execute_subprocess(commands, status_to_caller=False, output_to_caller=False)
307307
# simple status check. If returning, it is the callers
308308
# responsibility determine if an error occurred and handle it
309309
# appropriately.
310+
msg_context = (
311+
"Process did not run successfully; "
312+
"returned status {0}".format(error.returncode)
313+
)
314+
msg = failed_command_msg(msg_context, commands, output=error.output)
310315
if not return_to_caller:
311-
msg_context = (
312-
"Process did not run successfully; "
313-
"returned status {0}".format(error.returncode)
314-
)
315-
msg = failed_command_msg(msg_context, commands, output=error.output)
316316
logging.error(error)
317317
logging.error(msg)
318318
log_process_output(error.output)

0 commit comments

Comments
 (0)