Skip to content

Commit d6fdb3a

Browse files
committed
Clean up get_conda_base()
The deploy and bootstrap scripts are now getting totally different conda bases in totally different ways so a shared function doesn't make sense anymore. This merge splits the functionality back into these 2 scripts for better clarity and simplicity.
1 parent f5ffbad commit d6fdb3a

File tree

3 files changed

+23
-34
lines changed

3 files changed

+23
-34
lines changed

e3sm_supported_machines/bootstrap.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
from shared import (
1515
check_call,
1616
get_base,
17-
get_conda_base,
1817
get_rc_dev_labels,
1918
install_miniforge3,
2019
parse_args,
@@ -412,9 +411,8 @@ def main():
412411
else:
413412
is_test = not config.getboolean('e3sm_unified', 'release')
414413

415-
conda_base = get_conda_base(
416-
args.conda_base, config, version, shared=True, machine=machine
417-
)
414+
base_path = get_base(config, version)
415+
conda_base = os.path.join(base_path, machine, 'conda')
418416
conda_base = os.path.abspath(conda_base)
419417

420418
source_activation_scripts = \

e3sm_supported_machines/deploy_e3sm_unified.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44

55
import os
66
import sys
7+
import warnings
78

89
from configparser import ConfigParser
910

1011
from shared import (
1112
check_call,
12-
get_conda_base,
1313
install_miniforge3,
1414
parse_args,
1515
)
@@ -27,6 +27,25 @@ def get_config(config_file):
2727
return config
2828

2929

30+
def get_conda_base(conda_base):
31+
if conda_base is None:
32+
if 'CONDA_EXE' in os.environ:
33+
# if this is a test, assume we're the same base as the
34+
# environment currently active
35+
conda_exe = os.environ['CONDA_EXE']
36+
conda_base = os.path.abspath(
37+
os.path.join(conda_exe, '..', '..'))
38+
warnings.warn(
39+
f'--conda path not supplied. Using conda installed at '
40+
f'{conda_base}')
41+
else:
42+
raise ValueError('No conda base provided with --conda and '
43+
'none could be inferred.')
44+
# handle "~" in the path
45+
conda_base = os.path.abspath(os.path.expanduser(conda_base))
46+
return conda_base
47+
48+
3049
def bootstrap(activate_install_env, source_path, local_conda_build):
3150

3251
print('Creating the e3sm_unified conda environment')
@@ -84,9 +103,8 @@ def main():
84103
source_path = os.getcwd()
85104

86105
config = get_config(args.config_file)
87-
version = args.version
88106

89-
conda_base = get_conda_base(args.conda_base, config, version, shared=False)
107+
conda_base = get_conda_base(args.conda_base)
90108
conda_base = os.path.abspath(conda_base)
91109

92110
source_activation_scripts = \

e3sm_supported_machines/shared.py

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import subprocess
44
import os
55
import platform
6-
import warnings
76

87
try:
98
from urllib.request import urlopen, Request
@@ -138,32 +137,6 @@ def get_base(config, version):
138137
return base_path
139138

140139

141-
def get_conda_base(conda_base, config, version, shared, machine=None):
142-
if shared:
143-
base_path = get_base(config, version)
144-
if machine is None:
145-
raise ValueError(
146-
"Machine must be specified for shared conda base"
147-
)
148-
conda_base = os.path.join(base_path, machine, 'conda')
149-
elif conda_base is None:
150-
if 'CONDA_EXE' in os.environ:
151-
# if this is a test, assume we're the same base as the
152-
# environment currently active
153-
conda_exe = os.environ['CONDA_EXE']
154-
conda_base = os.path.abspath(
155-
os.path.join(conda_exe, '..', '..'))
156-
warnings.warn(
157-
f'--conda path not supplied. Using conda installed at '
158-
f'{conda_base}')
159-
else:
160-
raise ValueError('No conda base provided with --conda and '
161-
'none could be inferred.')
162-
# handle "~" in the path
163-
conda_base = os.path.abspath(os.path.expanduser(conda_base))
164-
return conda_base
165-
166-
167140
def get_rc_dev_labels(meta_yaml_path):
168141
"""Parse meta.yaml and return a list of dev labels for RC dependencies."""
169142

0 commit comments

Comments
 (0)