Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Central meta changes #57

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
64 changes: 43 additions & 21 deletions lfric_macros/apply_macros.py
yaswant marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ def __init__(self, tag, cname, version, apps, core, jules):
# copy in LFRic, rather than using the Jules version. The LFRic build
# system needs modifying to enable this
# self.jules_source = self.get_dependency_paths(jules, "jules")
self.central_rose_meta = False
self.set_rose_meta_path()
if version is None:
self.version = re.search(r".*vn(\d+\.\d+)(_.*)?", tag).group(1)
Expand All @@ -255,7 +256,15 @@ def set_rose_meta_path(self):
When Jules Shared from Jules is enabled, self.jules_source will need
adding here
"""
rose_meta_path = f"{self.root_path}:{self.core_source}"
if os.path.isdir(os.path.join(self.root_path, "rose-meta")):
# For backwards compatibility with central rose-meta imports
rose_meta_path = (
f"{os.path.join(self.root_path, 'rose-meta')}:"
yaswant marked this conversation as resolved.
Show resolved Hide resolved
f"{os.path.join(self.core_source, 'rose-meta')}"
)
self.central_rose_meta = True
else:
rose_meta_path = f"{self.root_path}:{self.core_source}"
yaswant marked this conversation as resolved.
Show resolved Hide resolved
os.environ["ROSE_META_PATH"] = rose_meta_path

def parse_application_section(self, meta_dir):
Expand Down Expand Up @@ -396,7 +405,7 @@ def find_meta_dirs(self, path):
- str, stdout of find command looking for versions.py files
"""

for dirpath, dirnames, filenames in os.walk(path):
for dirpath, dirnames, filenames in os.walk(path, followlinks=True):
dirnames[:] = [d for d in dirnames if d not in [".svn"]]
if "versions.py" in filenames:
self.meta_dirs.add(dirpath)
Expand Down Expand Up @@ -570,23 +579,23 @@ def get_full_import_path(self, imp):
not found
"""

core_imp = os.path.join(self.core_source, imp)
if os.path.exists(core_imp) or os.path.exists(
os.path.dirname(core_imp)
):
return core_imp
# TODO: Reinstate Jules checks when using Jules Metadata from Jules

# Reinstate when using Jules Shared from Jules
# jules_imp = os.path.join(self.jules_source, imp)
# if os.path.exists(jules_imp) or os.path.exists(
# os.path.dirname(jules_imp)
# ):
# return jules_imp

apps_imp = os.path.join(self.root_path, imp)
if os.path.exists(apps_imp) or os.path.exists(
os.path.dirname(apps_imp)
):
# For backwards compatibility with central rose-meta imports
if self.central_rose_meta:
core_imp = os.path.join(self.core_source, "rose-meta", imp)
apps_imp = os.path.join(self.root_path, "rose-meta", imp)
else:
core_imp = os.path.join(self.core_source, imp)
apps_imp = os.path.join(self.root_path, imp)

if os.path.exists(core_imp):
return core_imp
if os.path.exists(apps_imp):
return apps_imp
if os.path.exists(os.path.dirname(core_imp)):
return core_imp
if os.path.exists(os.path.dirname(apps_imp)):
return apps_imp

raise Exception(
Expand Down Expand Up @@ -684,7 +693,14 @@ def determine_import_order(self, app):
- A list of meta imports in the correct order
"""

import_list = [app]
# If using central metadata, use the basename, otherwise the full path
if self.central_rose_meta:
app_name = os.path.basename(app)
else:
app_name = app

import_list = [app_name]

try:
imports = self.parsed_macros[app]["imports"]
except KeyError:
Expand All @@ -709,6 +725,7 @@ def combine_macros(self, import_order):

full_command = ""
for meta_import in import_order:
meta_import = self.get_full_import_path(meta_import)
if (
meta_import in self.parsed_macros
and self.parsed_macros[meta_import]["commands"]
Expand Down Expand Up @@ -768,8 +785,13 @@ def preprocess_macros(self):
"""

# Get list of versions files to check - in both core and apps
self.find_meta_dirs(self.root_path)
self.find_meta_dirs(self.core_source)
# Duplicated for backwards compatibility with central rose-meta imports
if self.central_rose_meta:
self.find_meta_dirs(os.path.join(self.root_path, "rose-meta"))
self.find_meta_dirs(os.path.join(self.core_source, "rose-meta"))
else:
self.find_meta_dirs(self.root_path)
self.find_meta_dirs(self.core_source)

for meta_dir in self.meta_dirs:
print(
Expand Down