Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 26 additions & 13 deletions lfric_macros/apply_macros.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ def __init__(
version: str,
apps: Path,
core: Path,
jules: Path | None = None,
testing: bool = False,
) -> None:
self.tag: str = tag
Expand All @@ -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)
Expand All @@ -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

Expand Down Expand Up @@ -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:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The repo argument would benefit from being added to the docstring

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

"""
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
Expand All @@ -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:
Expand All @@ -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.
Expand Down Expand Up @@ -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()
Expand All @@ -1232,14 +1242,15 @@ 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
"""

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")
Expand Down Expand Up @@ -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
)
38 changes: 18 additions & 20 deletions lfric_macros/release_lfric.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ 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: str) -> None:
"""
Change HEAD to vnX.Y in meta import statements in the newly created
vnX.Y/rose-meta.conf files
Expand All @@ -261,7 +261,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)
else:
line = line.replace("HEAD", version)
lines[i] = line

with open(meta_file, "w") as f:
Expand Down Expand Up @@ -384,6 +387,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",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could be easy to get a bit confused with apps and core being references to paths. So adding version here may help users of the script know what is expected in the argument.

Suggested change
"--jules",
"--jules_version",

required=True,
help="The newly released version of Jules for jules-lfric metadata imports "
"(format X.Y)",
)
parser.add_argument(
"-t",
"--ticket",
Expand Down Expand Up @@ -413,6 +423,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 = f"vn{args.jules}"

return args

Expand All @@ -430,29 +441,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)
Expand All @@ -471,9 +469,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)

upgrade_file_name = copy_versions_files(
meta_dirs, args.old_version, args.version, args.apps, args.core
Expand Down
4 changes: 3 additions & 1 deletion lfric_macros/tests/test_apply_macros.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ 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(
"vn0.0_t001", None, None, TEST_APPS_DIR, Path("/tmp"), Path("/tmp"), True

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reckon it would be good to differentiate between the parameters here as it makes it clearer what data is being operated on when the function is called.

Suggested change
"vn0.0_t001", None, None, TEST_APPS_DIR, Path("/tmp"), Path("/tmp"), True
"vn0.0_t001", None, None, apps=TEST_APPS_DIR, core=Path("/tmp"), jules=Path("/tmp"), testing=True

)


def test_read_versions_file():
Expand Down
Loading