From 00538eaf41158859a02732ef63d7ee005a8451ad Mon Sep 17 00:00:00 2001 From: Ahmad Nawab Date: Mon, 31 Jul 2023 12:23:19 +0200 Subject: [PATCH] Local loki now injected into bundle using environment variable --- transformations/tests/conftest.py | 15 ++++----------- transformations/tests/test_cloudsc.py | 18 ++++++++++-------- transformations/tests/test_ecwam.py | 18 +++++++++++------- 3 files changed, 25 insertions(+), 26 deletions(-) diff --git a/transformations/tests/conftest.py b/transformations/tests/conftest.py index 829a2a326..91a8def5e 100644 --- a/transformations/tests/conftest.py +++ b/transformations/tests/conftest.py @@ -13,7 +13,7 @@ from loki import as_tuple, Frontend import loki.frontend -__all__ = ['available_frontends', '_write_script', '_local_loki_bundle'] +__all__ = ['available_frontends', 'local_loki_setup', 'local_loki_cleanup'] def available_frontends(xfail=None, skip=None): """ @@ -89,12 +89,11 @@ def write_env_launch_script(here, binary, args): return script -def inject_local_loki_into_bundle(here): +def local_loki_setup(here): lokidir = Path(__file__).parent.parent.parent target = here/'source/loki' backup = here/'source/loki.bak' bundlefile = here/'bundle.yml' - local_loki_bundlefile = here/'__bundle_loki.yml' # Do not overwrite any existing Loki copy if target.exists(): @@ -106,17 +105,11 @@ def inject_local_loki_into_bundle(here): bundle = yaml.safe_load(bundlefile.read_text()) loki_index = [i for i, p in enumerate(bundle['projects']) if 'loki' in p] assert len(loki_index) == 1 - if 'git' in bundle['projects'][loki_index[0]]['loki']: - del bundle['projects'][loki_index[0]]['loki']['git'] - bundle['projects'][loki_index[0]]['loki']['dir'] = str(lokidir.resolve()) - local_loki_bundlefile.write_text(yaml.dump(bundle)) - return local_loki_bundlefile, target, backup + return str(lokidir.resolve()), target, backup -def restore_original_bundle(local_loki_bundlefile, target, backup): - if local_loki_bundlefile.exists(): - local_loki_bundlefile.unlink() +def local_loki_cleanup(target, backup): if target.is_symlink(): target.unlink() if not target.exists() and backup.exists(): diff --git a/transformations/tests/test_cloudsc.py b/transformations/tests/test_cloudsc.py index ddb645f0e..0f4cd6a57 100644 --- a/transformations/tests/test_cloudsc.py +++ b/transformations/tests/test_cloudsc.py @@ -14,7 +14,7 @@ import pytest from conftest import ( - available_frontends, write_env_launch_script, inject_local_loki_into_bundle, restore_original_bundle + available_frontends, write_env_launch_script, local_loki_setup, local_loki_cleanup ) from loki import execute, OMNI, HAVE_FP, HAVE_OMNI, warning @@ -28,19 +28,21 @@ def fixture_here(): @pytest.fixture(scope='module', name='local_loki_bundle') def fixture_local_loki_bundle(here): - """Inject ourselves into the CLOUDSC bundle""" - local_loki_bundlefile, target, backup = inject_local_loki_into_bundle(here) - yield local_loki_bundlefile - restore_original_bundle(local_loki_bundlefile, target, backup) + """Call setup utilities for injecting ourselves into the CLOUDSC bundle""" + lokidir, target, backup = local_loki_setup(here) + yield lokidir + local_loki_cleanup(target, backup) @pytest.fixture(scope='module', name='bundle_create') def fixture_bundle_create(here, local_loki_bundle): + """Inject ourselves into the CLOUDSC bundle""" + os.environ['CLOUDSC_BUNDLE_LOKI_DIR'] = local_loki_bundle + env = os.environ.copy() + # Run ecbundle to fetch dependencies execute( - ['./cloudsc-bundle', 'create', '--bundle', str(local_loki_bundle)], - cwd=here, - silent=False + ['./cloudsc-bundle', 'create'], cwd=here, silent=False, env=env ) diff --git a/transformations/tests/test_ecwam.py b/transformations/tests/test_ecwam.py index 52221bb9b..321137bb1 100644 --- a/transformations/tests/test_ecwam.py +++ b/transformations/tests/test_ecwam.py @@ -11,7 +11,7 @@ from pathlib import Path import pytest -from conftest import write_env_launch_script, inject_local_loki_into_bundle, restore_original_bundle +from conftest import write_env_launch_script, local_loki_setup, local_loki_cleanup from loki import execute, HAVE_FP, FP pytestmark = pytest.mark.skipif('ECWAM_DIR' not in os.environ, reason='ECWAM_DIR not set') @@ -23,19 +23,23 @@ def fixture_here(): @pytest.fixture(scope='module', name='local_loki_bundle') def fixture_local_loki_bundle(here): - """Inject ourselves into the ECWAM bundle""" - local_loki_bundlefile, target, backup = inject_local_loki_into_bundle(here) - yield local_loki_bundlefile - restore_original_bundle(local_loki_bundlefile, target, backup) + """Call setup utilities for injecting ourselves into the ECWAM bundle""" + lokidir, target, backup = local_loki_setup(here) + yield lokidir + local_loki_cleanup(target, backup) @pytest.fixture(scope='module', name='bundle_create') def fixture_bundle_create(here, local_loki_bundle): + """Inject ourselves into the ECWAM bundle""" + os.environ['ECWAM_CONCEPT_BUNDLE_LOKI_DIR'] = local_loki_bundle + env = os.environ.copy() + # Run ecbundle to fetch dependencies execute( - ['./ecwam-bundle', 'create', '--bundle', str(local_loki_bundle)], + ['./ecwam-bundle', 'create'], cwd=here, - silent=False + silent=False, env=env )