Skip to content

Commit b487ad0

Browse files
committed
Omit empty optional load-script exports
1 parent ffc3ab8 commit b487ad0

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

mache/deploy/templates/load.sh.j2

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,43 @@
44

55
export MACHE_DEPLOY_TARGET_SOFTWARE={{ software | tojson }}
66
export MACHE_DEPLOY_TARGET_VERSION={{ software_version | tojson }}
7+
{% if runtime_version_cmd_sh != "''" %}
78
export MACHE_DEPLOY_RUNTIME_VERSION_CMD={{ runtime_version_cmd_sh }}
9+
{% endif %}
10+
{% if toolchain_compiler %}
811
export MACHE_DEPLOY_TOOLCHAIN_COMPILER={{ toolchain_compiler | tojson }}
12+
{% endif %}
13+
{% if toolchain_mpi %}
914
export MACHE_DEPLOY_TOOLCHAIN_MPI={{ toolchain_mpi | tojson }}
15+
{% endif %}
16+
{% if spack_library_view %}
1017
export MACHE_DEPLOY_SPACK_LIBRARY_VIEW={{ spack_library_view | tojson }}
18+
{% endif %}
1119
export MACHE_DEPLOY_COMPUTE_PIXI_EXE={{ compute_pixi_exe | tojson }}
1220
export MACHE_DEPLOY_COMPUTE_PIXI_PREFIX={{ prefix | tojson }}
1321
export MACHE_DEPLOY_COMPUTE_PIXI_TOML={{ pixi_toml | tojson }}
1422
export MACHE_DEPLOY_COMPUTE_PIXI_MPI={{ compute_pixi_mpi | tojson }}
1523
export MACHE_DEPLOY_COMPUTE_TARGET_LOAD_SNIPPET={{ compute_target_load_snippet | tojson }}
24+
{% if login_pixi_toml %}
1625
export MACHE_DEPLOY_LOGIN_PIXI_EXE={{ login_pixi_exe | tojson }}
1726
export MACHE_DEPLOY_LOGIN_PIXI_PREFIX={{ login_prefix | tojson }}
1827
export MACHE_DEPLOY_LOGIN_PIXI_TOML={{ login_pixi_toml | tojson }}
1928
export MACHE_DEPLOY_LOGIN_PIXI_MPI={{ login_pixi_mpi | tojson }}
2029
export MACHE_DEPLOY_LOGIN_TARGET_LOAD_SNIPPET={{ login_target_load_snippet | tojson }}
30+
{% endif %}
31+
{% if machine %}
2132
export {{ software_upper }}_MACHINE={{ machine | tojson }}
33+
{% endif %}
2234
{% if branch_path %}
2335
export {{ software_upper }}_BRANCH={{ branch_path | tojson }}
2436
{% endif %}
2537
export {{ software_upper }}_VERSION={{ software_version | tojson }}
38+
{% if toolchain_compiler %}
2639
export {{ software_upper }}_COMPILER={{ toolchain_compiler | tojson }}
40+
{% endif %}
41+
{% if toolchain_mpi %}
2742
export {{ software_upper }}_MPI={{ toolchain_mpi | tojson }}
43+
{% endif %}
2844
export {{ software_upper }}_LOAD_SCRIPT={{ load_script | tojson }}
2945

3046
# Activate the pixi environment in the *current* shell.

tests/test_deploy_run.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,40 @@ def test_write_load_script_without_login_env_skips_compute_detection(
469469
assert 'MACHE_DEPLOY_ACTIVE_ENV_KIND="compute"' in script_text
470470

471471

472+
def test_write_load_script_omits_optional_exports_when_values_are_empty(
473+
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
474+
):
475+
monkeypatch.chdir(tmp_path)
476+
pixi_exe = _make_pixi_executable(tmp_path)
477+
478+
script_path = deploy_run._write_load_script(
479+
prefix=str(tmp_path / 'compute'),
480+
login_env=None,
481+
pixi_exe=pixi_exe,
482+
branch_path=None,
483+
load_script_pixi_exe=_path_load_script_pixi(),
484+
software='e3sm-unified',
485+
software_version='1.0.0',
486+
runtime_version_cmd=None,
487+
machine=None,
488+
compute_pixi_mpi='nompi',
489+
toolchain_compiler=None,
490+
toolchain_mpi=None,
491+
spack_library_view=None,
492+
spack_activation='',
493+
)
494+
495+
script_text = Path(script_path).read_text(encoding='utf-8')
496+
assert 'MACHE_DEPLOY_RUNTIME_VERSION_CMD' not in script_text
497+
assert 'MACHE_DEPLOY_LOGIN_PIXI_TOML' not in script_text
498+
assert 'MACHE_DEPLOY_TOOLCHAIN_COMPILER' not in script_text
499+
assert 'MACHE_DEPLOY_SPACK_LIBRARY_VIEW' not in script_text
500+
assert 'E3SM_UNIFIED_MACHINE' not in script_text
501+
assert 'E3SM_UNIFIED_COMPILER' not in script_text
502+
assert 'E3SM_UNIFIED_MPI' not in script_text
503+
assert 'E3SM_UNIFIED_LOAD_SCRIPT' in script_text
504+
505+
472506
def test_copy_mache_pixi_toml_writes_slim_bootstrap_manifest(tmp_path: Path):
473507
source_repo = tmp_path / 'source'
474508
source_repo.mkdir()

0 commit comments

Comments
 (0)