Skip to content

Commit 17565e1

Browse files
change apply_macros to print macros to all files, including science (#48)
* change apply_macros to print macros to all files, including science * add fix for 2nd macro in chain * comment fix and change to black filename
1 parent 46b487e commit 17565e1

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

lfric_macros/apply_macros.py

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -561,16 +561,22 @@ def get_full_import_path(self, imp):
561561
"""
562562

563563
core_imp = os.path.join(self.core_source, imp)
564-
if os.path.exists(core_imp):
564+
if os.path.exists(core_imp) or os.path.exists(
565+
os.path.dirname(core_imp)
566+
):
565567
return core_imp
566568

567569
# Reinstate when using Jules Shared from Jules
568570
# jules_imp = os.path.join(self.jules_source, imp)
569-
# if os.path.exists(jules_imp):
571+
# if os.path.exists(jules_imp) or os.path.exists(
572+
# os.path.dirname(jules_imp)
573+
# ):
570574
# return jules_imp
571575

572576
apps_imp = os.path.join(self.root_path, imp)
573-
if os.path.exists(apps_imp):
577+
if os.path.exists(apps_imp) or os.path.exists(
578+
os.path.dirname(apps_imp)
579+
):
574580
return apps_imp
575581

576582
raise Exception(
@@ -609,7 +615,7 @@ def read_meta_imports(self, meta_dir, flag="import"):
609615
# Split the import line by '=' then take the rhs
610616
# Then remove the trailing '/HEAD'
611617
# Then prepend the path to the working copy
612-
imp = line.split("=", 1)[1].strip("/HEAD")
618+
imp = line.split("=", 1)[1].removesuffix("/HEAD")
613619
imp = self.get_full_import_path(imp)
614620
imports.append(imp)
615621
else:
@@ -736,7 +742,7 @@ def write_new_macro(self, meta_dir, full_command):
736742
" return config, self.reports\n"
737743
)
738744

739-
run_black(filepath)
745+
run_black(temppath)
740746

741747
os.rename(temppath, filepath)
742748

@@ -795,17 +801,7 @@ def preprocess_macros(self):
795801

796802
# Now reconstruct the macro for all applications which have the newly
797803
# added macro or import metadata with the new macro
798-
# Note, this is only done for applications, not for science sections
799804
for meta_dir in self.meta_dirs:
800-
if not (
801-
meta_dir.startswith(
802-
os.path.join(self.root_path, "applications")
803-
)
804-
or meta_dir.startswith(
805-
os.path.join(self.core_source, "applications")
806-
)
807-
):
808-
continue
809805
import_order = self.determine_import_order(meta_dir)
810806
full_command = self.combine_macros(import_order)
811807
# If there are commands to write out, do so and record this

0 commit comments

Comments
 (0)