@@ -130,7 +130,6 @@ def split_macros(parsed_versions):
130130 macros = []
131131 macro = ""
132132 in_macro = False
133- in_comment = False
134133 for line in parsed_versions :
135134 if line .startswith ("class vn" ) and not line .startswith (
136135 "class vnXX_txxx"
@@ -234,6 +233,7 @@ def __init__(self, tag, cname, version, apps, core, jules):
234233 # copy in LFRic, rather than using the Jules version. The LFRic build
235234 # system needs modifying to enable this
236235 # self.jules_source = self.get_dependency_paths(jules, "jules")
236+ self .central_rose_meta = False
237237 self .set_rose_meta_path ()
238238 if version is None :
239239 self .version = re .search (r".*vn(\d+\.\d+)(_.*)?" , tag ).group (1 )
@@ -255,7 +255,15 @@ def set_rose_meta_path(self):
255255 When Jules Shared from Jules is enabled, self.jules_source will need
256256 adding here
257257 """
258- rose_meta_path = f"{ self .root_path } :{ self .core_source } "
258+ if os .path .isdir (os .path .join (self .root_path , "rose-meta" )):
259+ # For backwards compatibility with central rose-meta imports
260+ rose_meta_path = (
261+ f"{ os .path .join (self .root_path , 'rose-meta' )} :"
262+ f"{ os .path .join (self .core_source , 'rose-meta' )} "
263+ )
264+ self .central_rose_meta = True
265+ else :
266+ rose_meta_path = f"{ self .root_path } :{ self .core_source } "
259267 os .environ ["ROSE_META_PATH" ] = rose_meta_path
260268
261269 def parse_application_section (self , meta_dir ):
@@ -396,7 +404,7 @@ def find_meta_dirs(self, path):
396404 - str, stdout of find command looking for versions.py files
397405 """
398406
399- for dirpath , dirnames , filenames in os .walk (path ):
407+ for dirpath , dirnames , filenames in os .walk (path , followlinks = True ):
400408 dirnames [:] = [d for d in dirnames if d not in [".svn" ]]
401409 if "versions.py" in filenames :
402410 self .meta_dirs .add (dirpath )
@@ -570,23 +578,23 @@ def get_full_import_path(self, imp):
570578 not found
571579 """
572580
573- core_imp = os .path .join (self .core_source , imp )
574- if os .path .exists (core_imp ) or os .path .exists (
575- os .path .dirname (core_imp )
576- ):
577- return core_imp
581+ # TODO: Reinstate Jules checks when using Jules Metadata from Jules
578582
579- # Reinstate when using Jules Shared from Jules
580- # jules_imp = os.path.join(self.jules_source, imp)
581- # if os.path.exists(jules_imp) or os.path.exists(
582- # os.path.dirname(jules_imp)
583- # ):
584- # return jules_imp
585-
586- apps_imp = os .path .join (self .root_path , imp )
587- if os .path .exists (apps_imp ) or os .path .exists (
588- os .path .dirname (apps_imp )
589- ):
583+ # For backwards compatibility with central rose-meta imports
584+ if self .central_rose_meta :
585+ core_imp = os .path .join (self .core_source , "rose-meta" , imp )
586+ apps_imp = os .path .join (self .root_path , "rose-meta" , imp )
587+ else :
588+ core_imp = os .path .join (self .core_source , imp )
589+ apps_imp = os .path .join (self .root_path , imp )
590+
591+ if os .path .exists (core_imp ):
592+ return core_imp
593+ if os .path .exists (apps_imp ):
594+ return apps_imp
595+ if os .path .exists (os .path .dirname (core_imp )):
596+ return core_imp
597+ if os .path .exists (os .path .dirname (apps_imp )):
590598 return apps_imp
591599
592600 raise Exception (
@@ -684,7 +692,14 @@ def determine_import_order(self, app):
684692 - A list of meta imports in the correct order
685693 """
686694
687- import_list = [app ]
695+ # If using central metadata, use the basename, otherwise the full path
696+ if self .central_rose_meta :
697+ app_name = os .path .basename (app )
698+ else :
699+ app_name = app
700+
701+ import_list = [app_name ]
702+
688703 try :
689704 imports = self .parsed_macros [app ]["imports" ]
690705 except KeyError :
@@ -709,6 +724,7 @@ def combine_macros(self, import_order):
709724
710725 full_command = ""
711726 for meta_import in import_order :
727+ meta_import = self .get_full_import_path (meta_import )
712728 if (
713729 meta_import in self .parsed_macros
714730 and self .parsed_macros [meta_import ]["commands" ]
@@ -758,7 +774,7 @@ def write_new_macro(self, meta_dir, full_command):
758774
759775 def preprocess_macros (self ):
760776 """
761- Overraching function to pre-process added macros
777+ Overarching function to pre-process added macros
762778 Run before running any rose macro upgrade commands"
763779 Search through versions.py files for macros with the correct after-tag
764780 Save info and then delete the macro when found
@@ -768,8 +784,13 @@ def preprocess_macros(self):
768784 """
769785
770786 # Get list of versions files to check - in both core and apps
771- self .find_meta_dirs (self .root_path )
772- self .find_meta_dirs (self .core_source )
787+ # Duplicated for backwards compatibility with central rose-meta imports
788+ if self .central_rose_meta :
789+ self .find_meta_dirs (os .path .join (self .root_path , "rose-meta" ))
790+ self .find_meta_dirs (os .path .join (self .core_source , "rose-meta" ))
791+ else :
792+ self .find_meta_dirs (self .root_path )
793+ self .find_meta_dirs (self .core_source )
773794
774795 for meta_dir in self .meta_dirs :
775796 print (
0 commit comments