diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 7af0dd3085bf3c2dfb732d0b13df332a9c8e5717..d1b09e6a6cacf186df7143c64de2f75277a61d05 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -39,5 +39,6 @@ testing-pytest: paths: - test-results.xml - .esd.log + - .generate_cache.log expire_in: 1 week diff --git a/esd/spack_manager/SpackManager.py b/esd/spack_manager/SpackManager.py index a7f46c2778eeb874a138a01e2c99ed85f7f12e3d..d534b30a085ce41ed27a19908b71f47f9097b699 100644 --- a/esd/spack_manager/SpackManager.py +++ b/esd/spack_manager/SpackManager.py @@ -2,12 +2,13 @@ import os import re from abc import ABC, abstractmethod from pathlib import Path +from tabnanny import check from esd.error_handling.exceptions import BashCommandException, NoSpackEnvironmentException, \ SpackInstallPackagesException from esd.logger.logger_builder import get_logger from esd.model.SpackModel import SpackModel -from esd.spack_manager.wrapper.spack_wrapper import no_spack_env +from esd.spack_manager.wrapper.spack_wrapper import check_spack_env from esd.utils.utils import run_command, git_clone_repo @@ -53,7 +54,6 @@ class SpackManager(ABC): pass def create_fetch_spack_environment(self): - if self.env.git_path: git_clone_repo(self.env.env_name, self.env.path / self.env.env_name, self.env.git_path, logger=self.logger) else: @@ -127,7 +127,7 @@ class SpackManager(ABC): return False return True - @no_spack_env + @check_spack_env def add_spack_repo(self, repo_path: Path, repo_name: str): """Add the Spack repository if it does not exist.""" run_command("bash", "-c", @@ -137,7 +137,7 @@ class SpackManager(ABC): exception_msg=f"Failed to add {repo_name} to spack environment {self.env.env_name}", exception=BashCommandException) - @no_spack_env + @check_spack_env def get_compiler_version(self): result = run_command("bash", "-c", f'source {self.spack_setup_script} && spack env activate -p {self.env_path} && spack compiler list', @@ -167,8 +167,21 @@ class SpackManager(ABC): return spack_version.stdout.strip().split()[0] return None - - def install_spack(self, spack_version="v0.21.1", spack_repo='https://github.com/spack/spack'): + @check_spack_env + def install_packages(self, jobs: int, signed=True, fresh=False): + signed = '' if signed else '--no-check-signature' + fresh = '--fresh' if fresh else '' + with open(str(Path(os.getcwd()).resolve() / ".generate_cache.log"), "w") as log_file: + run_command("bash", "-c", + f'source {self.spack_setup_script} && spack install --env {self.env.env_name} -v {signed} --j {jobs} {fresh}', + stdout=log_file, + capture_output=True, text=True, check=True, + logger=self.logger, + debug_msg=f"Installing spack packages for {self.env.env_name}", + exception_msg=f"Error installing spack packages for {self.env.env_name}", + exception=SpackInstallPackagesException) + + def install_spack(self, spack_version="v0.22.0", spack_repo='https://github.com/spack/spack'): try: user = os.getlogin() except OSError: diff --git a/esd/spack_manager/wrapper/spack_wrapper.py b/esd/spack_manager/wrapper/spack_wrapper.py index d075a317289669d00aa07b086ed78a41922f26fd..c2f9c116abb782eae1c22ebad4b8dae073c5acac 100644 --- a/esd/spack_manager/wrapper/spack_wrapper.py +++ b/esd/spack_manager/wrapper/spack_wrapper.py @@ -3,7 +3,7 @@ import functools from esd.error_handling.exceptions import NoSpackEnvironmentException -def no_spack_env(method): +def check_spack_env(method): @functools.wraps(method) def wrapper(self, *args, **kwargs): if self.spack_env_exists():