Improve error message for missing "command" entry in containerize (#37590)
fixes #21242
This commit is contained in:
parent
1b6621a14b
commit
297329f4b5
@ -10,10 +10,12 @@
|
||||
from typing import Optional
|
||||
|
||||
import spack.environment as ev
|
||||
import spack.error
|
||||
import spack.schema.env
|
||||
import spack.tengine as tengine
|
||||
import spack.util.spack_yaml as syaml
|
||||
from spack.container.images import (
|
||||
|
||||
from ..images import (
|
||||
bootstrap_template_for,
|
||||
build_info,
|
||||
checkout_command,
|
||||
@ -205,12 +207,20 @@ def manifest(self):
|
||||
@tengine.context_property
|
||||
def os_packages_final(self):
|
||||
"""Additional system packages that are needed at run-time."""
|
||||
return self._os_packages_for_stage("final")
|
||||
try:
|
||||
return self._os_packages_for_stage("final")
|
||||
except Exception as e:
|
||||
msg = f"an error occurred while rendering the 'final' stage of the image: {e}"
|
||||
raise spack.error.SpackError(msg) from e
|
||||
|
||||
@tengine.context_property
|
||||
def os_packages_build(self):
|
||||
"""Additional system packages that are needed at build-time."""
|
||||
return self._os_packages_for_stage("build")
|
||||
try:
|
||||
return self._os_packages_for_stage("build")
|
||||
except Exception as e:
|
||||
msg = f"an error occurred while rendering the 'build' stage of the image: {e}"
|
||||
raise spack.error.SpackError(msg) from e
|
||||
|
||||
@tengine.context_property
|
||||
def os_package_update(self):
|
||||
@ -243,13 +253,24 @@ def _package_info_from(self, package_list):
|
||||
if image is None:
|
||||
os_pkg_manager = os_package_manager_for(image_config["os"])
|
||||
else:
|
||||
os_pkg_manager = self.container_config["os_packages"]["command"]
|
||||
os_pkg_manager = self._os_pkg_manager()
|
||||
|
||||
update, install, clean = commands_for(os_pkg_manager)
|
||||
|
||||
Packages = collections.namedtuple("Packages", ["update", "install", "list", "clean"])
|
||||
return Packages(update=update, install=install, list=package_list, clean=clean)
|
||||
|
||||
def _os_pkg_manager(self):
|
||||
try:
|
||||
os_pkg_manager = self.container_config["os_packages"]["command"]
|
||||
except KeyError:
|
||||
msg = (
|
||||
"cannot determine the OS package manager to use.\n\n\tPlease add an "
|
||||
"appropriate 'os_packages:command' entry to the spack.yaml manifest file\n"
|
||||
)
|
||||
raise spack.error.SpackError(msg)
|
||||
return os_pkg_manager
|
||||
|
||||
@tengine.context_property
|
||||
def extra_instructions(self):
|
||||
Extras = collections.namedtuple("Extra", ["build", "final"])
|
||||
|
Loading…
Reference in New Issue
Block a user