Skip to content

Commit

Permalink
Merge pull request #96 from xylar/add_spack_mirror
Browse files Browse the repository at this point in the history
Add support for a local spack mirror
  • Loading branch information
xylar authored Jan 16, 2023
2 parents 9e7ec13 + 2f8aca3 commit 6f6dba1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
17 changes: 13 additions & 4 deletions mache/spack/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
def make_spack_env(spack_path, env_name, spack_specs, compiler, mpi,
machine=None, include_e3sm_lapack=False,
include_e3sm_hdf5_netcdf=False, yaml_template=None,
tmpdir=None):
tmpdir=None, spack_mirror=None):
"""
Clone the ``spack_for_mache_{{version}}`` branch from
`E3SM's spack clone <https://github.com/E3SM-Project/spack>`_ and build
Expand Down Expand Up @@ -57,6 +57,10 @@ def make_spack_env(spack_path, env_name, spack_specs, compiler, mpi,
tmpdir : str, optional
A temporary directory for building spack packages
spack_mirror : str, optional
The absolute path to a local spack mirror (e.g. for files a given
machine isn't allowed to download)
"""

if machine is None:
Expand Down Expand Up @@ -114,9 +118,14 @@ def make_spack_env(spack_path, env_name, spack_specs, compiler, mpi,
modules = f'{modules}\n' \
f'export TMPDIR={tmpdir}'

build_file = template.render(modules=modules, version=__version__,
spack_path=spack_path, env_name=env_name,
yaml_filename=yaml_filename)
template_args = dict(modules=modules, version=__version__,
spack_path=spack_path, env_name=env_name,
yaml_filename=yaml_filename)

if spack_mirror is not None:
template_args['spack_mirror'] = spack_mirror

build_file = template.render(**template_args)
build_filename = f'build_{env_name}.bash'
with open(build_filename, 'w') as handle:
handle.write(build_file)
Expand Down
6 changes: 6 additions & 0 deletions mache/spack/build_spack_env.template
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ else
cd {{ spack_path }}
fi
source share/spack/setup-env.sh

{% if spack_mirror is defined %}
spack mirror remove spack_mirror >& /dev/null || true
spack mirror add spack_mirror file://{{ spack_mirror }}
{% endif %}

spack env remove -y {{ env_name }} && \
echo "recreating environment: {{ env_name }}" || \
echo "creating new environment: {{ env_name }}"
Expand Down

0 comments on commit 6f6dba1

Please sign in to comment.