diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index bd5669bd97eadd66de13a991da728ff12e7599b7..2b497048d572c8df8798ae2d62fc8e13589add33 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -6,7 +6,6 @@ variables: BUILD_ENV_DOCKER_IMAGE: docker-registry.ebrains.eu/esd/tmp:latest - build-wheel: stage: build tags: @@ -40,6 +39,5 @@ testing-pytest: paths: - test-results.xml - .dedal.log - - .generate_cache.log expire_in: 1 week diff --git a/esd/configuration/GpgConfig.py b/dedal/configuration/GpgConfig.py similarity index 100% rename from esd/configuration/GpgConfig.py rename to dedal/configuration/GpgConfig.py diff --git a/esd/configuration/SpackConfig.py b/dedal/configuration/SpackConfig.py similarity index 92% rename from esd/configuration/SpackConfig.py rename to dedal/configuration/SpackConfig.py index b6178760ae724b8ecc5fd8c7ad576343c0624922..0d4706796ec13d6bf733c3d68459e455a6da53b7 100644 --- a/esd/configuration/SpackConfig.py +++ b/dedal/configuration/SpackConfig.py @@ -1,8 +1,8 @@ import os from pathlib import Path -from esd.configuration.GpgConfig import GpgConfig -from esd.model import SpackDescriptor +from dedal.configuration.GpgConfig import GpgConfig +from dedal.model import SpackDescriptor class SpackConfig: diff --git a/esd/configuration/__init__.py b/dedal/configuration/__init__.py similarity index 100% rename from esd/configuration/__init__.py rename to dedal/configuration/__init__.py diff --git a/esd/error_handling/__init__.py b/dedal/error_handling/__init__.py similarity index 100% rename from esd/error_handling/__init__.py rename to dedal/error_handling/__init__.py diff --git a/esd/error_handling/exceptions.py b/dedal/error_handling/exceptions.py similarity index 100% rename from esd/error_handling/exceptions.py rename to dedal/error_handling/exceptions.py diff --git a/esd/model/SpackDescriptor.py b/dedal/model/SpackDescriptor.py similarity index 100% rename from esd/model/SpackDescriptor.py rename to dedal/model/SpackDescriptor.py diff --git a/esd/model/__init__.py b/dedal/model/__init__.py similarity index 100% rename from esd/model/__init__.py rename to dedal/model/__init__.py diff --git a/esd/spack_factory/SpackOperation.py b/dedal/spack_factory/SpackOperation.py similarity index 97% rename from esd/spack_factory/SpackOperation.py rename to dedal/spack_factory/SpackOperation.py index a0b21a1c8934ac604388be139b5e9b9ec2f0b5b4..ecfbb8e5084fc1e49b32894aecd47190df36fd98 100644 --- a/esd/spack_factory/SpackOperation.py +++ b/dedal/spack_factory/SpackOperation.py @@ -2,13 +2,13 @@ import os import re import subprocess from pathlib import Path -from esd.error_handling.exceptions import BashCommandException, NoSpackEnvironmentException, \ +from dedal.error_handling.exceptions import BashCommandException, NoSpackEnvironmentException, \ SpackInstallPackagesException, SpackConcertizeException, SpackMirrorException, SpackGpgException -from esd.logger.logger_builder import get_logger -from esd.configuration.SpackConfig import SpackConfig -from esd.tests.testing_variables import SPACK_VERSION -from esd.wrapper.spack_wrapper import check_spack_env -from esd.utils.utils import run_command, git_clone_repo, log_command, set_bashrc_variable +from dedal.logger.logger_builder import get_logger +from dedal.configuration.SpackConfig import SpackConfig +from dedal.tests.testing_variables import SPACK_VERSION +from dedal.wrapper.spack_wrapper import check_spack_env +from dedal.utils.utils import run_command, git_clone_repo, log_command, set_bashrc_variable class SpackOperation: diff --git a/esd/spack_factory/SpackOperationCreator.py b/dedal/spack_factory/SpackOperationCreator.py similarity index 67% rename from esd/spack_factory/SpackOperationCreator.py rename to dedal/spack_factory/SpackOperationCreator.py index 8369c5ca0efb2865e706f1968882fc53a4e4d3d9..54517a845bad14629c6019416f0e19581472991e 100644 --- a/esd/spack_factory/SpackOperationCreator.py +++ b/dedal/spack_factory/SpackOperationCreator.py @@ -1,6 +1,6 @@ -from esd.configuration.SpackConfig import SpackConfig -from esd.spack_factory.SpackOperation import SpackOperation -from esd.spack_factory.SpackOperationUseCache import SpackOperationUseCache +from dedal.configuration.SpackConfig import SpackConfig +from dedal.spack_factory.SpackOperation import SpackOperation +from dedal.spack_factory.SpackOperationUseCache import SpackOperationUseCache class SpackOperationCreator: diff --git a/esd/spack_factory/SpackOperationUseCache.py b/dedal/spack_factory/SpackOperationUseCache.py similarity index 86% rename from esd/spack_factory/SpackOperationUseCache.py rename to dedal/spack_factory/SpackOperationUseCache.py index 313522d235515955124ba44536976d995e17ff77..efb9af763af58a0f9e44ab79cab13af56947502e 100644 --- a/esd/spack_factory/SpackOperationUseCache.py +++ b/dedal/spack_factory/SpackOperationUseCache.py @@ -1,8 +1,8 @@ import os -from esd.build_cache.BuildCacheManager import BuildCacheManager -from esd.logger.logger_builder import get_logger -from esd.spack_factory.SpackOperation import SpackOperation -from esd.configuration.SpackConfig import SpackConfig +from dedal.build_cache.BuildCacheManager import BuildCacheManager +from dedal.logger.logger_builder import get_logger +from dedal.spack_factory.SpackOperation import SpackOperation +from dedal.configuration.SpackConfig import SpackConfig class SpackOperationUseCache(SpackOperation): diff --git a/esd/spack_factory/__init__.py b/dedal/spack_factory/__init__.py similarity index 100% rename from esd/spack_factory/__init__.py rename to dedal/spack_factory/__init__.py diff --git a/dedal/tests/spack_from_scratch_test.py b/dedal/tests/spack_from_scratch_test.py index cdc405e744fb70389ce474fa04a59c973da8e58d..2fec80f743d72190d0b175191660250981f98255 100644 --- a/dedal/tests/spack_from_scratch_test.py +++ b/dedal/tests/spack_from_scratch_test.py @@ -1,11 +1,11 @@ from pathlib import Path import pytest -from esd.configuration.SpackConfig import SpackConfig -from esd.error_handling.exceptions import BashCommandException, NoSpackEnvironmentException -from esd.spack_factory.SpackOperationCreator import SpackOperationCreator -from esd.model.SpackDescriptor import SpackDescriptor -from esd.tests.testing_variables import test_spack_env_git, ebrains_spack_builds_git -from esd.utils.utils import file_exists_and_not_empty +from dedal.configuration.SpackConfig import SpackConfig +from dedal.error_handling.exceptions import BashCommandException, NoSpackEnvironmentException +from dedal.spack_factory.SpackOperationCreator import SpackOperationCreator +from dedal.model.SpackDescriptor import SpackDescriptor +from dedal.tests.testing_variables import test_spack_env_git, ebrains_spack_builds_git +from dedal.utils.utils import file_exists_and_not_empty def test_spack_repo_exists_1(): diff --git a/dedal/tests/spack_install_test.py b/dedal/tests/spack_install_test.py index 28f8268e668ee2036930b9724ea72cd0320e82d4..564d5c6aa2138e815cd7d092215a4f2eee8816f6 100644 --- a/dedal/tests/spack_install_test.py +++ b/dedal/tests/spack_install_test.py @@ -1,6 +1,6 @@ import pytest -from esd.spack_factory.SpackOperation import SpackOperation -from esd.tests.testing_variables import SPACK_VERSION +from dedal.spack_factory.SpackOperation import SpackOperation +from dedal.tests.testing_variables import SPACK_VERSION # run this test first so that spack is installed only once for all the tests diff --git a/dedal/tests/utils_test.py b/dedal/tests/utils_test.py index 256b82184ab25f5ee1d1a0c2551974c1f4cf1b0a..c7bcde88492433a9c4aa23e65f65563b43e1f5f9 100644 --- a/dedal/tests/utils_test.py +++ b/dedal/tests/utils_test.py @@ -1,7 +1,9 @@ +import logging + import pytest from pathlib import Path - -from dedal.utils.utils import clean_up +from unittest.mock import mock_open, patch, MagicMock +from dedal.utils.utils import clean_up, file_exists_and_not_empty, set_bashrc_variable, log_command @pytest.fixture @@ -79,3 +81,20 @@ def test_file_exists_and_not_empty(tmp_path: Path): non_empty_file = tmp_path / "non_empty.txt" non_empty_file.write_text("Some content") assert file_exists_and_not_empty(non_empty_file) + + +def test_log_command(): + results = MagicMock() + results.stdout = "Test output" + results.stderr = "Test error" + mock_file = mock_open() + + with patch("builtins.open", mock_file): + log_command(results, "logfile.log") + + mock_file.assert_called_once_with("logfile.log", "w") + handle = mock_file() + handle.write.assert_any_call("Test output") + handle.write.assert_any_call("\n--- STDERR ---\n") + handle.write.assert_any_call("Test error") + diff --git a/dedal/utils/utils.py b/dedal/utils/utils.py index 033cbc54bbcd33a5f6c59399227d71b620e7544f..6c28a9d962553e36e34c1478b795f8fbafb7bf2a 100644 --- a/dedal/utils/utils.py +++ b/dedal/utils/utils.py @@ -4,7 +4,7 @@ import shutil import subprocess from pathlib import Path -from esd.error_handling.exceptions import BashCommandException +from dedal.error_handling.exceptions import BashCommandException import re @@ -38,6 +38,8 @@ def run_command(*args, logger=logging.getLogger(__name__), info_msg: str = '', e raise exception(f'{exception_msg} : {e}') else: return None + except exception as e: + logger.error(f"Run command exception: {e}") def git_clone_repo(repo_name: str, dir: Path, git_path: str, logger: logging = logging.getLogger(__name__)): diff --git a/esd/wrapper/__init__.py b/dedal/wrapper/__init__.py similarity index 100% rename from esd/wrapper/__init__.py rename to dedal/wrapper/__init__.py diff --git a/esd/wrapper/spack_wrapper.py b/dedal/wrapper/spack_wrapper.py similarity index 85% rename from esd/wrapper/spack_wrapper.py rename to dedal/wrapper/spack_wrapper.py index c2f9c116abb782eae1c22ebad4b8dae073c5acac..018cad482083beda9ee0a278f4bbb2d107476849 100644 --- a/esd/wrapper/spack_wrapper.py +++ b/dedal/wrapper/spack_wrapper.py @@ -1,6 +1,6 @@ import functools -from esd.error_handling.exceptions import NoSpackEnvironmentException +from dedal.error_handling.exceptions import NoSpackEnvironmentException def check_spack_env(method):