Skip to content

Commit d673e10

Browse files
committed
Add support for mache from fork/branch
1 parent 8bd20e7 commit d673e10

File tree

3 files changed

+85
-31
lines changed

3 files changed

+85
-31
lines changed

e3sm_supported_machines/bootstrap.py

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@
1111
from mache.spack import make_spack_env, get_spack_script, \
1212
get_modules_env_vars_and_mpi_compilers
1313
from mache.permissions import update_permissions
14-
from shared import parse_args, check_call, install_miniconda, get_conda_base
14+
from shared import (
15+
check_call,
16+
get_conda_base,
17+
install_miniforge3,
18+
parse_args,
19+
)
1520

1621

1722
def get_config(config_file, machine):
@@ -147,16 +152,15 @@ def build_env(is_test, recreate, compiler, mpi, conda_mpi, version,
147152
packages = f'python={python} pip'
148153

149154
source_activation_scripts = \
150-
f'source {conda_base}/etc/profile.d/conda.sh && ' \
151-
f'source {conda_base}/etc/profile.d/mamba.sh'
155+
f'source {conda_base}/etc/profile.d/conda.sh'
152156

153157
activate_env = f'{source_activation_scripts} && conda activate {env_name}'
154158

155159
if not os.path.exists(env_path) or recreate:
156160
print(f'creating {env_name}')
157161
packages = f'{packages} "e3sm-unified={version}={mpi_prefix}_*"'
158162
commands = f'{activate_base} && ' \
159-
f'mamba create -y -n {env_name} {channels} {packages}'
163+
f'conda create -y -n {env_name} {channels} {packages}'
160164
check_call(commands)
161165

162166
if conda_mpi == 'hpc':
@@ -174,6 +178,15 @@ def build_env(is_test, recreate, compiler, mpi, conda_mpi, version,
174178
return env_path, env_name, activate_env, channels, spack_env
175179

176180

181+
def install_mache_from_branch(activate_env, fork, branch):
182+
print('Clone and install local mache\n')
183+
commands = f'{activate_env} && ' \
184+
f'cd build_mache/mache && ' \
185+
f'python -m pip install --no-deps .'
186+
187+
check_call(commands)
188+
189+
177190
def build_sys_ilamb_esmpy(config, machine, compiler, mpi, template_path,
178191
activate_env, channels, spack_base, spack_env):
179192

@@ -378,6 +391,8 @@ def main():
378391

379392
config = get_config(args.config_file, machine)
380393

394+
local_mache = args.mache_fork is not None and args.mache_branch is not None
395+
381396
if args.release:
382397
is_test = False
383398
else:
@@ -387,13 +402,12 @@ def main():
387402
conda_base = os.path.abspath(conda_base)
388403

389404
source_activation_scripts = \
390-
f'source {conda_base}/etc/profile.d/conda.sh && ' \
391-
f'source {conda_base}/etc/profile.d/mamba.sh'
405+
f'source {conda_base}/etc/profile.d/conda.sh'
392406

393407
activate_base = f'{source_activation_scripts} && conda activate'
394408

395409
# install miniconda if needed
396-
install_miniconda(conda_base, activate_base)
410+
install_miniforge3(conda_base, activate_base)
397411

398412
python, recreate, compiler, mpi, conda_mpi, activ_suffix, env_suffix, \
399413
activ_path = get_env_setup(args, config, machine)
@@ -405,11 +419,16 @@ def main():
405419
nompi_suffix = '_login'
406420
# first, make environment for login nodes. We're using mpich from
407421
# conda-forge for now because we haven't had any luck with esmf>8.2.0 nompi
408-
env_path, env_nompi, _, _, _ = build_env(
422+
env_path, env_nompi, activate_env, _, _ = build_env(
409423
is_test, recreate, nompi_compiler, mpi, 'mpich', version,
410424
python, conda_base, nompi_suffix, nompi_suffix, activate_base,
411425
args.local_conda_build, config)
412426

427+
if local_mache:
428+
install_mache_from_branch(activate_env=activate_env,
429+
fork=args.mache_fork,
430+
branch=args.mache_branch)
431+
413432
if not is_test:
414433
# make a symlink to the environment
415434
link = os.path.join(conda_base, 'envs', 'e3sm_unified_latest')

e3sm_supported_machines/deploy_e3sm_unified.py

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@
77

88
from configparser import ConfigParser
99

10-
from shared import parse_args, check_call, install_miniconda, get_conda_base
10+
from shared import (
11+
check_call,
12+
get_conda_base,
13+
install_miniforge3,
14+
parse_args,
15+
)
1116

1217

1318
def get_config(config_file):
@@ -35,18 +40,17 @@ def bootstrap(activate_install_env, source_path, local_conda_build):
3540
sys.exit(0)
3641

3742

38-
def setup_install_env(activate_base, config, use_local):
43+
def setup_install_env(activate_base, use_local, mache):
3944
print('Setting up a conda environment for installing E3SM-Unified')
40-
mache_version = config.get('e3sm_unified', 'mache')
4145
channels = []
4246
if use_local:
4347
channels.append('--use-local')
44-
if 'rc' in mache_version:
48+
if 'rc' in mache:
4549
channels.append('-c conda-forge/label/mache_dev')
4650
channels = ' '.join(channels)
4751
commands = f'{activate_base} && ' \
48-
f'mamba create -y -n temp_e3sm_unified_install ' \
49-
f'{channels} progressbar2 jinja2 mache={mache_version}'
52+
f'conda create -y -n temp_e3sm_unified_install ' \
53+
f'{channels} progressbar2 jinja2 {mache}'
5054

5155
check_call(commands)
5256

@@ -60,6 +64,21 @@ def remove_install_env(activate_base):
6064
check_call(commands)
6165

6266

67+
def install_mache_from_branch(activate_install_env, fork, branch):
68+
print('Clone and install local mache\n')
69+
commands = f'{activate_install_env} && ' \
70+
f'rm -rf build_mache && ' \
71+
f'mkdir -p build_mache && ' \
72+
f'cd build_mache && ' \
73+
f'git clone -b {branch} ' \
74+
f'[email protected]:{fork}.git mache && ' \
75+
f'cd mache && ' \
76+
f'conda install -y --file spec-file.txt && ' \
77+
f'python -m pip install --no-deps .'
78+
79+
check_call(commands)
80+
81+
6382
def main():
6483
args = parse_args(bootstrap=False)
6584
source_path = os.getcwd()
@@ -70,8 +89,14 @@ def main():
7089
conda_base = os.path.abspath(conda_base)
7190

7291
source_activation_scripts = \
73-
f'source {conda_base}/etc/profile.d/conda.sh && ' \
74-
f'source {conda_base}/etc/profile.d/mamba.sh'
92+
f'source {conda_base}/etc/profile.d/conda.sh'
93+
94+
local_mache = args.mache_fork is not None and args.mache_branch is not None
95+
if local_mache:
96+
mache = ''
97+
else:
98+
mache_version = config.get('e3sm_unified', 'mache')
99+
mache = f'"mache={mache_version}"'
75100

76101
activate_base = f'{source_activation_scripts} && conda activate'
77102

@@ -80,9 +105,14 @@ def main():
80105
f'conda activate temp_e3sm_unified_install'
81106

82107
# install miniconda if needed
83-
install_miniconda(conda_base, activate_base)
108+
install_miniforge3(conda_base, activate_base)
109+
110+
setup_install_env(activate_base, args.use_local, mache)
84111

85-
setup_install_env(activate_base, config, args.use_local)
112+
if local_mache:
113+
install_mache_from_branch(activate_install_env=activate_install_env,
114+
fork=args.mache_fork,
115+
branch=args.mache_branch)
86116

87117
if args.release:
88118
is_test = False

e3sm_supported_machines/shared.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,17 @@ def parse_args(bootstrap):
4545
parser.add_argument("--local_conda_build", dest="local_conda_build",
4646
type=str,
4747
help="A path for conda packages (for testing).")
48+
parser.add_argument("--mache_fork", dest="mache_fork",
49+
help="Point to a mache fork (and branch) for testing")
50+
parser.add_argument("--mache_branch", dest="mache_branch",
51+
help="Point to a mache branch (and fork) for testing")
4852

4953
args = parser.parse_args(sys.argv[1:])
5054

55+
if (args.mache_fork is None) != (args.mache_branch is None):
56+
raise ValueError('You must supply both or neither of '
57+
'--mache_fork and --mache_branch')
58+
5159
return args
5260

5361

@@ -61,38 +69,35 @@ def check_call(commands, env=None):
6169
raise subprocess.CalledProcessError(proc.returncode, commands)
6270

6371

64-
def install_miniconda(conda_base, activate_base):
72+
def install_miniforge3(conda_base, activate_base):
6573
if not os.path.exists(conda_base):
66-
print('Installing Miniconda3')
74+
print('Installing Miniforge3')
6775
if platform.system() == 'Linux':
6876
system = 'Linux'
6977
elif platform.system() == 'Darwin':
7078
system = 'MacOSX'
7179
else:
7280
system = 'Linux'
73-
74-
miniconda = f'Mambaforge-{system}-x86_64.sh'
75-
url = f'https://github.com/conda-forge/miniforge/releases/latest/download/{miniconda}'
81+
miniforge = f'Miniforge3-{system}-x86_64.sh'
82+
url = f'https://github.com/conda-forge/miniforge/releases/latest/download/{miniforge}' # noqa: E501
7683
print(url)
7784
req = Request(url, headers={'User-Agent': 'Mozilla/5.0'})
7885
f = urlopen(req)
7986
html = f.read()
80-
with open(miniconda, 'wb') as outfile:
87+
with open(miniforge, 'wb') as outfile:
8188
outfile.write(html)
8289
f.close()
8390

84-
command = f'/bin/bash {miniconda} -b -p {conda_base}'
91+
command = f'/bin/bash {miniforge} -b -p {conda_base}'
8592
check_call(command)
86-
os.remove(miniconda)
93+
os.remove(miniforge)
8794

88-
print('Doing initial setup')
95+
print('Doing initial setup\n')
8996
commands = f'{activate_base} && ' \
9097
f'conda config --add channels conda-forge && ' \
9198
f'conda config --set channel_priority strict && ' \
92-
f'mamba update -y --all && ' \
93-
f'cp ~/.bashrc ~/.bashrc.conda_bak && ' \
94-
f'mamba init && ' \
95-
f'mv ~/.bashrc.conda_bak ~/.bashrc'
99+
f'conda update -y --all && ' \
100+
f'conda init --no-user'
96101

97102
check_call(commands)
98103

0 commit comments

Comments
 (0)