Skip to content

Commit 8f99428

Browse files
committed
Add flag to 'spack stack create env' to promote warnings to errors (--treat-warnings-as-errors)
1 parent 95878de commit 8f99428

3 files changed

Lines changed: 33 additions & 4 deletions

File tree

‎spack-ext/lib/jcsda-emc/spack-stack/stack/cmd/stack_cmds/create.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,11 @@ def setup_env_parser(subparser):
151151
help="Do not filter site/compilers.yaml (default is filter out different compiler versions of the same name)"
152152
)
153153

154+
subparser.add_argument(
155+
"--treat-warnings-as-errors",
156+
action='store_true',
157+
help="Promote warnings from 'spack stack create env' to errors"
158+
)
154159

155160
def setup_create_parser(subparser):
156161
sp = subparser.add_subparsers(metavar="SUBCOMMAND", dest="env_type")
@@ -187,6 +192,7 @@ def dict_from_args(args):
187192
dict["modifypkg"] = args.modify_pkg
188193
dict["compiler"] = args.compiler
189194
dict["keep_all_compilers"] = args.keep_all_compilers
195+
dict["treat_warnings_as_errors"] = args.treat_warnings_as_errors
190196

191197
return dict
192198

‎spack-ext/lib/jcsda-emc/spack-stack/stack/stack_env.py‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ def __init__(self, **kwargs):
111111
self.upstreams = kwargs.get("upstreams", None)
112112
self.modifypkg = kwargs.get("modifypkg", None)
113113
self.keepallcompilers = kwargs.get("keep_all_compilers", None)
114+
self.treatwarningsaserrors = kwargs.get("treat_warnings_as_errors", None)
114115

115116
if not self.name:
116117
# site = self.site if self.site else 'default'
@@ -187,7 +188,10 @@ def _copy_common_includes(self):
187188
(compiler_name, _) = compiler_name_and_version_from_string(self.compiler)
188189
packages_compiler_yaml_path = os.path.join(common_path, f"packages_{compiler_name}.yaml")
189190
if not os.path.exists(packages_compiler_yaml_path):
190-
logging.warning(f"\nWARNING: {packages_compiler_yaml_path} not found, please check if this is correct\n")
191+
if self.treatwarningsaserrors:
192+
raise Exception(f"\n{packages_compiler_yaml_path} not found, please check if this is correct\n")
193+
else:
194+
logging.warning(f"\nWARNING: {packages_compiler_yaml_path} not found, please check if this is correct\n")
191195
destination = os.path.join(env_common_dir, "packages.yaml")
192196
self._copy_or_merge_includes("packages", packages_yaml_path, packages_compiler_yaml_path, destination)
193197

@@ -222,7 +226,10 @@ def _copy_site_includes(self):
222226
packages_yaml_path = os.path.join(site_path, "packages.yaml")
223227
packages_compiler_yaml_path = os.path.join(site_path, f"packages_{self.compiler}.yaml")
224228
if not os.path.exists(packages_compiler_yaml_path):
225-
logging.warning(f"\nWARNING: {packages_compiler_yaml_path} not found, please check if this is correct\n")
229+
if self.treatwarningsaserrors:
230+
raise Exception(f"\n{packages_compiler_yaml_path} not found, please check if this is correct\n")
231+
else:
232+
logging.warning(f"\nWARNING: {packages_compiler_yaml_path} not found, please check if this is correct\n")
226233
destination = os.path.join(env_site_dir, "packages.yaml")
227234
self._copy_or_merge_includes("packages", packages_yaml_path, packages_compiler_yaml_path, destination)
228235

‎spack-ext/lib/jcsda-emc/spack-stack/tests/test_stack_create.py‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,24 @@ def test_modifypkg():
317317
netcdfc_spack_path = spack_cmd(
318318
"--env-dir", env_dir, "location", "--package-dir", "netcdf_c", output=str
319319
).strip()
320-
print("DH DEBUG 1:", os.path.join(spack.config.get("repos")['builtin'], "packages/netcdf_c"))
321-
print("DH DEBUG 2:", netcdfc_spack_path)
322320
assert (
323321
os.path.join(spack.config.get("repos")['builtin'].replace("${SPACK_STACK_DIR}", os.getenv("SPACK_STACK_DIR")), "packages/netcdf_c") == netcdfc_spack_path
324322
), "Incorrect netcdf-c location in modifypkg_test"
323+
324+
@pytest.mark.extension("stack")
325+
@pytest.mark.filterwarnings("ignore::UserWarning")
326+
def test_treatwarningsaserrors():
327+
with pytest.raises(Exception, match="packages_fj.yaml not found"):
328+
stack_create(
329+
"create",
330+
"env",
331+
"--site",
332+
"blueback",
333+
"--name",
334+
"treatwarningsaserrors_test",
335+
"--dir",
336+
test_dir,
337+
"--compiler",
338+
"fj",
339+
"--treat-warnings-as-errors"
340+
)

0 commit comments

Comments
 (0)