Skip to content

Commit

Permalink
Add force_overwrite_tools flag
Browse files Browse the repository at this point in the history
  • Loading branch information
minghangli-uni committed Oct 7, 2024
1 parent 5a4a82e commit b14bedb
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
30 changes: 19 additions & 11 deletions expts_manager/Expts_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class Expts_manager(object):

def __init__(
self,
force_overwrite_tools: bool = False,
MOM_prefix: str = "MOM_list",
CONFIG_prefix: str = "config_list",
runconfig_suffix1: str = "_attributes",
Expand All @@ -93,6 +94,7 @@ def __init__(
):

self.dir_manager = self.DIR_MANAGER
self.force_overwrite_tools = force_overwrite_tools
self.MOM_prefix = MOM_prefix
self.CONFIG_prefix = CONFIG_prefix
self.runconfig_suffix1 = runconfig_suffix1
Expand Down Expand Up @@ -127,6 +129,7 @@ def load_variables(self, yamlfile):
self.indata = self._read_ryaml(yamlfile)

self.model = self.indata["model"]
self.force_overwrite_tools = self.indata.get("force_overwrite_tools", False)
self.utils_url = self.indata.get("utils_url", None)
self.utils_dir_name = self.indata.get("utils_dir_name", None)
self.utils_branch_name = self.indata.get("utils_branch_name", None)
Expand Down Expand Up @@ -183,18 +186,23 @@ def load_tools(self):
"""
Loads external tools required for the experiments.
"""

# currently import from a fork: https://github.com/minghangli-uni/om3-utils
# will update the tool when it is merged to COSIMA/om3-utils
def _clone_repo(branch_name, url, path, tool_name):
if not os.path.isdir(path):
command = (
f"git clone --branch {branch_name} {url} {path} --single-branch"
)
subprocess.run(command, shell=True, check=True)
print(f"Cloning {tool_name} for use!")
def _clone_repo(branch_name, url, path, tool_name, force_overwrite_tools):
if os.path.exists(path) and os.path.isdir(path):
if force_overwrite_tools:
print(f"-- Force_overwrite_tools is activated, hence removing existing {tool_name}: {path}")
shutil.rmtree(path)
print(f"Cloning {tool_name} for use!")
command = (f"git clone --branch {branch_name} {url} {path} --single-branch")
subprocess.run(command, shell=True, check=True)
else:
print(f"{tool_name} already exists, hence skips cloning!")
else:
print(f"{path} already exists!")
print(f"Cloning {tool_name} for use!")
command = (f"git clone --branch {branch_name} {url} {path} --single-branch")
subprocess.run(command, shell=True, check=True)
print(f"Finished cloning {tool_name}!")

# om3-utils is a must for om3 but not required for access-om2.
utils_path = (
Expand All @@ -214,7 +222,7 @@ def _clone_repo(branch_name, url, path, tool_name):

if self.model == "access-om3":
_clone_repo(
self.utils_branch_name, self.utils_url, utils_path, self.utils_dir_name
self.utils_branch_name, self.utils_url, utils_path, self.utils_dir_name, self.force_overwrite_tools
)

# make_diag_table is [optional]
Expand All @@ -226,7 +234,7 @@ def _clone_repo(branch_name, url, path, tool_name):

if self.diag_path is not None:
_clone_repo(
self.diag_branch_name, self.diag_url, self.diag_path, self.diag_dir_name
self.diag_branch_name, self.diag_url, self.diag_path, self.diag_dir_name, self.force_overwrite_tools
)
sys.path.extend([utils_path, self.diag_path])
else:
Expand Down
1 change: 1 addition & 0 deletions expts_manager/Expts_manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ model: access-om3 # Specify the model to be used. Options: 'access-om2', 'acces
# 1. Parse parameters and comments from `MOM_input` in MOM6.
# 2. Read and write the `nuopc.runconfig` file.

force_overwrite_tools: False
utils_url: git@github.com:minghangli-uni/om3-utils.git # Git URL for the utility tool repository
utils_branch_name: main # The branch for which the utility tool will be checked out
utils_dir_name: om3-utils # Directory name for the utility tool (user-defined)
Expand Down
4 changes: 4 additions & 0 deletions expts_manager/write_Expts_manager_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ def write_value(key, value, file, comment=None, indent=0):
# 2. Read and write the `nuopc.runconfig` file.
"""
config_util = [
{
"key": "force_overwrite_tools",
"value": "False",
},
{
"key": "utils_url",
"value": "git@github.com:minghangli-uni/om3-utils.git",
Expand Down

0 comments on commit b14bedb

Please sign in to comment.