Skip to content

Commit 25af255

Browse files
Add checking for unused compilers to software-definitions
This commit adds a check to the software-definitions command to ensure compilers are used within the applications they are defined in.
1 parent 91fa393 commit 25af255

File tree

1 file changed

+50
-17
lines changed

1 file changed

+50
-17
lines changed

lib/ramble/ramble/cmd/software_definitions.py

Lines changed: 50 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
section = "developer"
1919
level = "long"
2020

21+
unused_compilers = {}
2122
definitions = {}
2223
conflicts = {}
2324
used_by = {}
@@ -56,7 +57,12 @@ def collect_definitions():
5657
"""
5758
top_level_attrs = ["compilers", "software_specs"]
5859

59-
types_to_print = [ramble.repository.ObjectTypes.applications]
60+
types_to_print = [
61+
ramble.repository.ObjectTypes.applications,
62+
ramble.repository.ObjectTypes.modifiers,
63+
ramble.repository.ObjectTypes.workflow_managers,
64+
ramble.repository.ObjectTypes.package_managers,
65+
]
6066

6167
for object_type in types_to_print:
6268
obj_path = ramble.repository.paths[object_type]
@@ -65,6 +71,20 @@ def collect_definitions():
6571

6672
obj_namespace = f"{obj_repo.full_namespace}.{obj_inst.name}"
6773

74+
for compiler_name in obj_inst.compilers:
75+
used = False
76+
for pkg_defs in obj_inst.software_specs.values():
77+
for pkg_def in pkg_defs:
78+
if (
79+
getattr(pkg_def, "compiler", "__rmb_no_compiler_attr__")
80+
== compiler_name
81+
):
82+
used = True
83+
if not used:
84+
if compiler_name not in unused_compilers:
85+
unused_compilers[compiler_name] = []
86+
unused_compilers[compiler_name].append(obj_namespace)
87+
6888
for top_level_attr in top_level_attrs:
6989
if hasattr(obj_inst, top_level_attr):
7090
for pkg_name, pkg_defs in getattr(obj_inst, top_level_attr).items():
@@ -110,26 +130,36 @@ def count_conflicts():
110130
num_conflicts = 0
111131
for pkg_name in conflicts:
112132
num_conflicts += len(conflicts[pkg_name])
133+
for object_names in unused_compilers.values():
134+
num_conflicts += len(object_names)
113135
return num_conflicts
114136

115137

116138
def print_conflicts():
117139
"""Print conflict information, if any exist"""
118-
if len(conflicts) > 0:
119-
color.cprint(section_title("Software Definition Conflicts:"))
120-
for pkg_name in conflicts:
121-
122-
color.cprint(f'{nested_1("Package")}: {pkg_name}:')
123-
color.cprint("\tDefined as:")
124-
for attr in ["pkg_spec", "compiler_spec", "compiler"]:
125-
if hasattr(definitions[pkg_name], attr):
126-
attr_def = getattr(definitions[pkg_name], attr)
127-
if attr_def:
128-
color.cprint(f'\t\t{attr} = {attr_def.replace("@", "@@")}')
129-
color.cprint("\tIn objects:")
130-
colify(used_by[pkg_name], indent=24, output=sys.stdout)
131-
color.cprint("\tConflicts with objects:")
132-
colify(conflicts[pkg_name], indent=24, output=sys.stdout)
140+
if len(conflicts) > 0 or len(unused_compilers) > 0:
141+
if len(conflicts) > 0:
142+
color.cprint(section_title("Software Definition Conflicts:"))
143+
for pkg_name in conflicts:
144+
145+
color.cprint(f'{nested_1("Package")}: {pkg_name}:')
146+
color.cprint("\tDefined as:")
147+
for attr in ["pkg_spec", "compiler_spec", "compiler"]:
148+
if hasattr(definitions[pkg_name], attr):
149+
attr_def = getattr(definitions[pkg_name], attr)
150+
if attr_def:
151+
color.cprint(f'\t\t{attr} = {attr_def.replace("@", "@@")}')
152+
color.cprint("\tIn objects:")
153+
colify(used_by[pkg_name], indent=24, output=sys.stdout)
154+
color.cprint("\tConflicts with objects:")
155+
colify(conflicts[pkg_name], indent=24, output=sys.stdout)
156+
157+
if len(unused_compilers) > 0:
158+
color.cprint(section_title("Unused Compilers:"))
159+
for compiler_name, object_names in unused_compilers.items():
160+
color.cprint(nested_1(f" Compiler {compiler_name} is not used in packages:"))
161+
colify(object_names, indent=8, output=sys.stdout)
162+
color.cprint("\n")
133163
else:
134164
color.cprint(section_title("No Conflicts Detected"))
135165

@@ -164,5 +194,8 @@ def software_definitions(parser, args, unknown_args):
164194

165195
if args.error_on_conflict:
166196
num_conflicts = count_conflicts()
167-
color.cprint(f"{num_conflicts} conflicts detected.")
197+
if num_conflicts == 1:
198+
color.cprint(f"{num_conflicts} conflict detected.")
199+
else:
200+
color.cprint(f"{num_conflicts} conflicts detected.")
168201
sys.exit(num_conflicts)

0 commit comments

Comments
 (0)