From 80cd09ff860554470acf6f80741759943db97420 Mon Sep 17 00:00:00 2001 From: adrianciu <adrian.ciu@codemart.ro> Date: Tue, 18 Feb 2025 13:45:13 +0200 Subject: [PATCH] esd-spack-installation: package renaming to dedal --- .gitlab-ci.yml | 2 -- {esd => dedal}/configuration/GpgConfig.py | 0 {esd => dedal}/configuration/SpackConfig.py | 4 ++-- {esd => dedal}/configuration/__init__.py | 0 {esd => dedal}/error_handling/__init__.py | 0 {esd => dedal}/error_handling/exceptions.py | 0 {esd => dedal}/model/SpackDescriptor.py | 0 {esd => dedal}/model/__init__.py | 0 .../spack_factory/SpackOperation.py | 12 +++++----- .../spack_factory/SpackOperationCreator.py | 6 ++--- .../spack_factory/SpackOperationUseCache.py | 8 +++---- {esd => dedal}/spack_factory/__init__.py | 0 dedal/tests/spack_from_scratch_test.py | 12 +++++----- dedal/tests/spack_install_test.py | 4 ++-- dedal/tests/utils_test.py | 23 +++++++++++++++++-- dedal/utils/utils.py | 4 +++- {esd => dedal}/wrapper/__init__.py | 0 {esd => dedal}/wrapper/spack_wrapper.py | 2 +- 18 files changed, 48 insertions(+), 29 deletions(-) rename {esd => dedal}/configuration/GpgConfig.py (100%) rename {esd => dedal}/configuration/SpackConfig.py (92%) rename {esd => dedal}/configuration/__init__.py (100%) rename {esd => dedal}/error_handling/__init__.py (100%) rename {esd => dedal}/error_handling/exceptions.py (100%) rename {esd => dedal}/model/SpackDescriptor.py (100%) rename {esd => dedal}/model/__init__.py (100%) rename {esd => dedal}/spack_factory/SpackOperation.py (97%) rename {esd => dedal}/spack_factory/SpackOperationCreator.py (67%) rename {esd => dedal}/spack_factory/SpackOperationUseCache.py (86%) rename {esd => dedal}/spack_factory/__init__.py (100%) rename {esd => dedal}/wrapper/__init__.py (100%) rename {esd => dedal}/wrapper/spack_wrapper.py (85%) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index bd5669bd..2b497048 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 b6178760..0d470679 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 a0b21a1c..ecfbb8e5 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 8369c5ca..54517a84 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 313522d2..efb9af76 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 cdc405e7..2fec80f7 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 28f8268e..564d5c6a 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 256b8218..c7bcde88 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 033cbc54..6c28a9d9 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 c2f9c116..018cad48 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): -- GitLab