Skip to content

Commit c487b2c

Browse files
authored
Merge pull request #357 from xylar/fix-mache-deploy
A few fixes to `mache.deploy`
2 parents a67e751 + 295675b commit c487b2c

File tree

6 files changed

+75
-9
lines changed

6 files changed

+75
-9
lines changed

docs/design/mache_deploy.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,12 @@ After deployment, users need a simple way to load the environment.
159159

160160
`mache.deploy` generates load scripts, for example:
161161

162-
`load_<software>.sh`
162+
- `load_<software>.sh` (no toolchain-specific Spack environment)
163+
- `load_<software>_<machine>_<compiler>_<mpi>.sh` (toolchain-specific)
164+
165+
Including `<machine>` avoids filename collisions on shared filesystems where
166+
multiple machines (or machine partitions exposed as distinct machine names)
167+
share compiler and MPI naming.
163168

164169
These scripts encapsulate:
165170

docs/developers_guide/deploy.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,9 @@ That file is target-owned and is not generated from a package template.
111111

112112
`load.sh.j2`
113113
: Package-owned template used by `run.py` to create final
114-
`load_<software>*.sh` scripts in the target repo.
114+
`load_<software>*.sh` scripts in the target repo
115+
(toolchain-specific form:
116+
`load_<software>_<machine>_<compiler>_<mpi>.sh`).
115117

116118
`spack_install.bash.j2`
117119
: Package-owned template used by `spack.py` to create a temporary Spack build

docs/users_guide/deploy.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,11 @@ created.
343343
10. Optionally installs the target software in editable mode.
344344
11. Writes one or more `load_<software>*.sh` scripts.
345345

346+
When a toolchain pair is selected, script names include machine, compiler,
347+
and MPI tags, for example:
348+
349+
`load_<software>_<machine>_<compiler>_<mpi>.sh`
350+
346351
Those load scripts are the main artifact a downstream user consumes after the
347352
deployment completes.
348353

mache/deploy/run.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -772,14 +772,20 @@ def _write_load_script(
772772
)
773773
pixi_toml = os.path.join(prefix_abs, 'pixi.toml')
774774

775-
# Keep the script name stable and discoverable.
776-
safe_software = software.strip() or 'software'
777775
if toolchain_compiler and toolchain_mpi:
776+
if machine is None:
777+
raise ValueError(
778+
'Cannot include toolchain in load script name without machine.'
779+
' Set a machine in deploy/config.yaml.j2 or pass --machine.'
780+
)
781+
machine_tag = _sanitize_script_tag(machine)
778782
compiler_tag = _sanitize_script_tag(toolchain_compiler)
779783
mpi_tag = _sanitize_script_tag(toolchain_mpi)
780-
script_path = f'load_{safe_software}_{compiler_tag}_{mpi_tag}.sh'
784+
script_path = (
785+
f'load_{software}_{machine_tag}_{compiler_tag}_{mpi_tag}.sh'
786+
)
781787
else:
782-
script_path = f'load_{safe_software}.sh'
788+
script_path = f'load_{software}.sh'
783789

784790
template_text = (
785791
resources.files(__package__)
@@ -788,7 +794,7 @@ def _write_load_script(
788794
)
789795
tmpl = Template(template_text, keep_trailing_newline=True)
790796

791-
software_upper = safe_software.upper().replace('-', '_')
797+
software_upper = software.upper().replace('-', '_')
792798
source_path = os.path.abspath(os.getcwd())
793799
target_load_snippet = os.path.join(source_path, 'deploy', 'load.sh')
794800

mache/deploy/templates/load.sh.j2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,11 @@ if [[ -n "${MACHE_DEPLOY_RUNTIME_VERSION_CMD:-}" ]]; then
5050
return 1
5151
fi
5252

53+
# Use a non-login shell so pixi-provided PATH/env are not reset by site profiles.
5354
probe_output="$(
5455
env -u PIXI_PROJECT_MANIFEST -u PIXI_PROJECT_ROOT \
5556
"${PIXI}" run -m "${PIXI_TOML}" -- \
56-
bash -lc "${MACHE_DEPLOY_RUNTIME_VERSION_CMD}" 2>&1
57+
bash -c "${MACHE_DEPLOY_RUNTIME_VERSION_CMD}" 2>&1
5758
)"
5859
status=$?
5960

@@ -103,7 +104,6 @@ echo " spack env activated."
103104
if [[ -n "${MACHE_DEPLOY_TARGET_LOAD_SNIPPET:-}" \
104105
&& -f "${MACHE_DEPLOY_TARGET_LOAD_SNIPPET}" ]]; then
105106
echo "loading ${MACHE_DEPLOY_TARGET_SOFTWARE} environment variables..."
106-
echo " ${MACHE_DEPLOY_TARGET_LOAD_SNIPPET}"
107107
# shellcheck source=/dev/null
108108
source "${MACHE_DEPLOY_TARGET_LOAD_SNIPPET}"
109109
echo " ${MACHE_DEPLOY_TARGET_SOFTWARE} environment variables loaded."

tests/test_deploy_run.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
from pathlib import Path
2+
3+
from mache.deploy import run as deploy_run
4+
5+
6+
def test_write_load_script_includes_machine_for_toolchain(
7+
tmp_path, monkeypatch
8+
):
9+
monkeypatch.chdir(tmp_path)
10+
11+
script_path = deploy_run._write_load_script(
12+
prefix=str(tmp_path / 'prefix'),
13+
pixi_exe='/usr/bin/pixi',
14+
software='polaris',
15+
software_version='1.0.0',
16+
runtime_version_cmd=None,
17+
machine='pm-gpu',
18+
toolchain_compiler='oneapi/2024.2',
19+
toolchain_mpi='mpich@4.2',
20+
spack_library_view=None,
21+
spack_activation='',
22+
)
23+
24+
assert script_path == 'load_polaris_pm-gpu_oneapi_2024.2_mpich_4.2.sh'
25+
assert Path(script_path).is_file()
26+
27+
28+
def test_write_load_script_without_toolchain_keeps_default_name(
29+
tmp_path,
30+
monkeypatch,
31+
):
32+
monkeypatch.chdir(tmp_path)
33+
34+
script_path = deploy_run._write_load_script(
35+
prefix=str(tmp_path / 'prefix'),
36+
pixi_exe='/usr/bin/pixi',
37+
software='polaris',
38+
software_version='1.0.0',
39+
runtime_version_cmd=None,
40+
machine='chrysalis',
41+
toolchain_compiler=None,
42+
toolchain_mpi=None,
43+
spack_library_view=None,
44+
spack_activation='',
45+
)
46+
47+
assert script_path == 'load_polaris.sh'
48+
assert Path(script_path).is_file()

0 commit comments

Comments
 (0)