Skip to content

Commit

Permalink
Local loki now injected into bundle using environment variable
Browse files Browse the repository at this point in the history
  • Loading branch information
awnawab committed Jul 31, 2023
1 parent 3904aac commit 00538ea
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 26 deletions.
15 changes: 4 additions & 11 deletions transformations/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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():
Expand All @@ -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():
Expand Down
18 changes: 10 additions & 8 deletions transformations/tests/test_cloudsc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
)


Expand Down
18 changes: 11 additions & 7 deletions transformations/tests/test_ecwam.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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
)


Expand Down

0 comments on commit 00538ea

Please sign in to comment.