diff --git a/lfric_macros/apply_macros.py b/lfric_macros/apply_macros.py index d8852fff..bdec22e7 100755 --- a/lfric_macros/apply_macros.py +++ b/lfric_macros/apply_macros.py @@ -248,9 +248,10 @@ def __init__( self, tag: str, cname: str | None, - version: str, + version: str | None, apps: Path, core: Path, + jules: Path | None = None, testing: bool = False, ) -> None: self.tag: str = tag @@ -266,7 +267,8 @@ def __init__( self.root_path: Path = apps else: self.root_path: Path = get_root_path(apps) - self.core_source: Path = self.get_dependency_paths(core) + self.core_source: Path = self.get_dependency_paths(core, "lfric_core") + self.jules_source: Path = self.get_dependency_paths(jules, "jules") self.set_rose_meta_path() if version is None: self.version: str = re.search(r".*vn(\d+\.\d+)(_.*)?", tag).group(1) @@ -285,13 +287,15 @@ def __init__( def set_rose_meta_path(self) -> None: """ - Set up the ROSE_META_PATH environment variable in order to use the Core - metadata. We also add the clone root path as this should allow the script to be - run from anywhere. + Set up the ROSE_META_PATH environment variable in order to use the Core and + Jules metadata. We also add the clone root path as this should allow the script + to be run from anywhere. Edit 02/2026 - remove backwards compatibility support for pre central-metadata """ rose_meta_path: str = ( - f"{self.root_path / 'rose-meta'}:{self.core_source / 'rose-meta'}" + f"{self.root_path / 'rose-meta'}:" + f"{self.core_source / 'rose-meta'}:" + f"{self.jules_source / 'rose-meta'}" ) os.environ["ROSE_META_PATH"] = rose_meta_path @@ -320,7 +324,7 @@ def parse_application_section(self, meta_dir: Path) -> Path: # Get Working Copy Functions ############################################################################ - def get_dependency_paths(self, source: str | None) -> Path: + def get_dependency_paths(self, source: str | None, repo: str) -> Path: """ Parse the core command line arguments to get the path to a git clone. If the source isn't defined, first populate the source by reading the @@ -333,11 +337,9 @@ def get_dependency_paths(self, source: str | None) -> Path: - The path to the source working copy to use """ - repo = "lfric_core" - # If source is None then read the dependencies.yaml file for the source if source is None: - source, ref = self.read_dependencies() + source, ref = self.read_dependencies(repo) if ":" in str(source): source_path = Path(source.split(":")[1]).expanduser() else: @@ -360,7 +362,7 @@ def get_dependency_paths(self, source: str | None) -> Path: source = self.git_clone_temp(source, ref, repo) return source - def read_dependencies(self, repo: str = "lfric_core") -> tuple[str, str]: + def read_dependencies(self, repo: str) -> tuple[str, str]: """ Read through the dependencies.yaml file for the source of the repo defined by repo. Uses self.root_path to locate the dependencies.yaml file. @@ -1220,7 +1222,15 @@ def parse_args() -> argparse.Namespace: "--core", default=None, help="The LFRic Core source being used." - "Either a path to a working copy or a git source." + "Either a path to a local clone or a github source." + "If not set, will be read from the dependencies.yaml", + ) + parser.add_argument( + "-j", + "--jules", + default=None, + help="The Jules source being used." + "Either a path to a local clone or a github source." "If not set, will be read from the dependencies.yaml", ) return parser.parse_args() @@ -1232,6 +1242,7 @@ def apply_macros_main( version: str | None = None, apps: Path = Path(".").absolute(), core: str | None = None, + jules: str | None = None, ) -> None: """ Main function for this program @@ -1239,7 +1250,7 @@ def apply_macros_main( check_environment() - macro_object: ApplyMacros = ApplyMacros(tag, cname, version, apps, core) + macro_object: ApplyMacros = ApplyMacros(tag, cname, version, apps, core, jules) # Pre-process macros banner_print("Pre-Processing Macros") @@ -1268,4 +1279,6 @@ def apply_macros_main( if __name__ == "__main__": args = parse_args() - apply_macros_main(args.tag, args.cname, args.version, args.apps, args.core) + apply_macros_main( + args.tag, args.cname, args.version, args.apps, args.core, args.jules + ) diff --git a/lfric_macros/release_lfric.py b/lfric_macros/release_lfric.py index 567dd96a..33547c38 100755 --- a/lfric_macros/release_lfric.py +++ b/lfric_macros/release_lfric.py @@ -241,7 +241,9 @@ def copy_head_meta(meta_dirs: list[Path], apps: Path, core: Path, version: str) _ = run_command(command) -def update_meta_import_path(meta_dirs: list[Path], version: str) -> None: +def update_meta_import_path( + meta_dirs: list[Path], version: str, jules_version: str +) -> None: """ Change HEAD to vnX.Y in meta import statements in the newly created vnX.Y/rose-meta.conf files @@ -261,7 +263,10 @@ def update_meta_import_path(meta_dirs: list[Path], version: str) -> None: elif in_imports and not line.strip().startswith("="): break if in_imports: - line = line.replace("HEAD", version) + if "jules-lfric" in line: + line = line.replace("HEAD", jules_version) + else: + line = line.replace("HEAD", version) lines[i] = line with open(meta_file, "w") as f: @@ -384,6 +389,13 @@ def parse_args() -> argparse.Namespace: type=version_number, help="The new version number we are updating to (format X.Y)", ) + parser.add_argument( + "-j", + "--jules_version", + required=True, + help="The newly released version of Jules for jules-lfric metadata imports " + "(format X.Y)", + ) parser.add_argument( "-t", "--ticket", @@ -413,6 +425,7 @@ def parse_args() -> argparse.Namespace: args.core = args.core.expanduser().absolute() args.version = f"vn{args.version}" args.old_version = f"vn{args.old_version}" + args.jules_version = f"vn{args.jules_version}" return args @@ -430,29 +443,16 @@ def main() -> None: set_dependency_path(args.apps, args.core) - # Find all metadata directories, excluing jules shared and lfric inputs as these - # have metadata but no macros. + # Find all metadata directories, excluing lfric-inputs as this has metadata but no + # macros. exclude_dirs = ( - ".svn", + ".git", "rose-stem", "integration-test", - "lfric-jules-shared", "lfricinputs", ) meta_dirs = find_meta_dirs([args.apps, args.core], exclude_dirs) - # Find JULES shared metadata directories and combine with all other metadirs for - # where they are handled differently - jules_meta_path = ( - args.apps - / "interfaces" - / "jules_interface" - / "rose-meta" - / "lfric-jules-shared" - ) - jules_shared_meta_dirs = find_meta_dirs([jules_meta_path]) - meta_dirs_plus_jules = meta_dirs.union(jules_shared_meta_dirs) - update_version_number(args.apps, args.version) update_variables_files(args.apps) @@ -471,9 +471,9 @@ def main() -> None: ) print("\n[INFO] Successfully upgraded apps") - copy_head_meta(meta_dirs_plus_jules, args.apps, args.core, args.version) + copy_head_meta(meta_dirs, args.apps, args.core, args.version) - update_meta_import_path(meta_dirs, args.version) + update_meta_import_path(meta_dirs, args.version, args.jules_version) upgrade_file_name = copy_versions_files( meta_dirs, args.old_version, args.version, args.apps, args.core diff --git a/lfric_macros/tests/test_apply_macros.py b/lfric_macros/tests/test_apply_macros.py index c4e3f78c..138fd2c2 100644 --- a/lfric_macros/tests/test_apply_macros.py +++ b/lfric_macros/tests/test_apply_macros.py @@ -70,7 +70,15 @@ def __repr__(self): # Create an instance of the apply_macros class # Use /tmp for Core and Jules as these are not required for testing -applymacros = ApplyMacros("vn0.0_t001", None, None, TEST_APPS_DIR, Path("/tmp"), True) +applymacros = ApplyMacros( + tag="vn0.0_t001", + cname=None, + version=None, + apps=TEST_APPS_DIR, + core=Path("/tmp"), + jules=Path("/tmp"), + testing=True, +) def test_read_versions_file():