Skip to content

Commit 8b02be5

Browse files
Merge branch 'main' into core_only_macros
2 parents 3db6afe + 3e2998b commit 8b02be5

5 files changed

Lines changed: 86 additions & 8 deletions

File tree

github_scripts/get_git_sources.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,13 @@
55
# -----------------------------------------------------------------------------
66
"""
77
Helper functions for cloning git sources in command line builds
8+
9+
Reads CONFLICT_IGNORES environment variable to get a list of comma-separated
10+
files/directories to ignore merge conflicts in. These should be relative to the
11+
top-level of the repo. If not set, then a default list is defined below.
812
"""
913

14+
import os
1015
import re
1116
import subprocess
1217
from datetime import datetime
@@ -231,17 +236,24 @@ def handle_merge_conflicts(source: str, ref: str, loc: Path, dependency: str) ->
231236
If merge conflicts are in `rose-stem/` or `dependencies.yaml` then accept the
232237
current changes and mark as resolved.
233238
If others remain then raise an error
239+
If CONFLICT_IGNORES environment variable is set, use that as a comma-separated list
240+
of files/directories to ignore. If not set, use a default list below.
234241
"""
235242

236243
# For suites, merge conflicts in these files/directories are unimportant so accept
237244
# the current changes
238-
for filepath in ("dependencies.yaml", "rose-stem"):
245+
ignores = os.environ.get(
246+
"CONFLICT_IGNORES", "dependencies.yaml,rose-stem,CONTRIBUTORS.md"
247+
).split(",")
248+
need_commit = False
249+
for filepath in ignores:
239250
full_path = loc / filepath
240251
if not full_path.exists():
241252
continue
242253
logger.warning(f"Ignoring merge conflicts in {filepath}")
243254
run_command(f"git -C {loc} checkout --ours -- {filepath}")
244-
run_command(f"git -C {loc} add {filepath}")
255+
run_command(f"git -C {loc} add -f {filepath}")
256+
need_commit = True
245257

246258
# Check if there are any remaining merge conflicts
247259
unmerged = get_unmerged(loc)
@@ -254,6 +266,10 @@ def handle_merge_conflicts(source: str, ref: str, loc: Path, dependency: str) ->
254266
"\n\nThese will need changing in the source branches to be useable together"
255267
)
256268

269+
# Need to commit the ignored conflict fixes
270+
if need_commit:
271+
run_command(f"git -C {loc} commit -m 'fix conflict'")
272+
257273

258274
def get_unmerged(loc: Path) -> list[str]:
259275
"""

lfric_macros/apply_macros.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,13 +339,14 @@ def parse_application_section(self, meta_dir: Path) -> Path:
339339

340340
def get_dependency_paths(self, source: str | None, repo: str) -> Path:
341341
"""
342-
Parse the core command line arguments to get the path to a git clone.
342+
Parse the core/jules command line arguments to get the path to a git clone.
343343
If the source isn't defined, first populate the source by reading the
344344
dependencies.yaml file.
345345
If the source is a remote GitHub source clone it to a temporary location
346346
Inputs:
347347
- source, The command line argument for the source. If not set this will be
348348
None
349+
- repo, The name of the repository to clone
349350
Outputs:
350351
- The path to the source working copy to use
351352
"""

lfric_macros/check_macro_chains.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,11 @@ def main() -> None:
135135

136136
source_apps = Path(os.environ["SOURCE_ROOT"]) / "lfric_apps"
137137
source_core = Path(os.environ["SOURCE_ROOT"]) / "lfric_core"
138+
source_jules = Path(os.environ["SOURCE_ROOT"]) / "jules"
138139

139-
macro_object = ApplyMacros("vn0.0_t0", None, "vn0.0", source_apps, source_core)
140+
macro_object = ApplyMacros(
141+
"vn0.0_t0", None, "vn0.0", source_apps, source_core, source_jules
142+
)
140143
apps_meta_dirs = macro_object.find_meta_dirs(macro_object.root_path / "rose-meta")
141144

142145
rose_apps = find_upgradeable_apps(

lfric_macros/release_lfric.py

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,34 @@ def update_versions_file(meta_dirs: list[Path], upgrade_name: str) -> None:
357357
add_new_import(versions_file, upgrade_name)
358358

359359

360+
def update_versions_mod(repo: str, filepath: Path, version: str) -> None:
361+
"""
362+
Update the versions numbers in lfric versions mod files
363+
"""
364+
365+
print(f"[INFO] Updating lfric_{repo}_versions_mod.F90")
366+
367+
version = version.removeprefix("vn").split(".")
368+
updates = {
369+
"major": version[0],
370+
"minor": version[1],
371+
"patch": "0",
372+
"release": ".true.",
373+
}
374+
375+
lines = filepath.read_text().split("\n")
376+
for i, line in enumerate(lines):
377+
if len(updates) == 0:
378+
break
379+
for item, val in updates.items():
380+
if re.match(rf".*::\s*lfric_{repo}_{item}_version\s*=", line):
381+
lines[i] = f"{line.split('=')[0]} = {val}"
382+
del updates[item]
383+
break
384+
385+
filepath.write_text("\n".join(lines))
386+
387+
360388
def ticket_number(opt: str) -> str:
361389
"""
362390
Check that the command line supplied ticket number is of a suitable format
@@ -408,9 +436,8 @@ def parse_args() -> argparse.Namespace:
408436
"--apps",
409437
default=Path(".").absolute(),
410438
type=Path,
411-
help="The path to the LFRic Apps working copy being used. Defaults to "
412-
"the location the script is being run from - this assumes you are in a "
413-
"working copy.",
439+
help="The path to the LFRic Apps working copy being used. Defaults to the "
440+
"location the script is being run from - this assumes you are in an Apps clone",
414441
)
415442
parser.add_argument(
416443
"-c",
@@ -481,6 +508,26 @@ def main() -> None:
481508

482509
update_versions_file(meta_dirs, upgrade_file_name)
483510

511+
update_versions_mod(
512+
"apps",
513+
args.apps
514+
/ "science"
515+
/ "shared"
516+
/ "source"
517+
/ "utilities"
518+
/ "lfric_apps_version_mod.f90",
519+
args.version,
520+
)
521+
update_versions_mod(
522+
"core",
523+
args.core
524+
/ "infrastructure"
525+
/ "source"
526+
/ "utilities"
527+
/ "lfric_core_version_mod.f90",
528+
args.version,
529+
)
530+
484531

485532
if __name__ == "__main__":
486533
main()

lfric_macros/validate_rose_meta.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
INVALID_METADATA = [
2121
"jules-lfric",
2222
"jules-lsm",
23-
"lfric-jules-shared",
2423
"socrates-radiation",
2524
"um-aerosol",
2625
"um-boundary_layer",
@@ -191,6 +190,13 @@ def parse_args() -> argparse.Namespace:
191190
"required. If both are provided then it will be assumed that Apps is the "
192191
"repository to check.",
193192
)
193+
parser.add_argument(
194+
"-j",
195+
"--jules",
196+
default=None,
197+
help="The path to the JULES source required for jules-lfric & jules-shared "
198+
"metadata.",
199+
)
194200

195201
args = parser.parse_args()
196202

@@ -204,6 +210,8 @@ def parse_args() -> argparse.Namespace:
204210
args.apps = Path(args.apps).absolute().expanduser()
205211
if args.core:
206212
args.core = Path(args.core).absolute().expanduser()
213+
if args.jules:
214+
args.jules = Path(args.jules).absolute().expanduser()
207215

208216
return args
209217

@@ -229,6 +237,9 @@ def main() -> None:
229237
# Apps hasn't been set
230238
source_path = args.core
231239
rose_meta_path = f"{args.core / 'rose-meta'}"
240+
if args.jules:
241+
meta_paths += f"-M {args.jules / 'rose-meta'} "
242+
rose_meta_path += f":{args.jules / 'rose-meta'}"
232243

233244
if check_rose_metadata(rose_meta_path, source_path) or check_rose_stem_apps(
234245
meta_paths, source_path

0 commit comments

Comments
 (0)