Skip to content

Commit

Permalink
Enable easier mache testing
Browse files Browse the repository at this point in the history
The `configure_compass_env.py` script now takes two flags,
`--mache_fork` and `--mache_branch` that are used to clone the
fork and branch locally, then install mache from it.  This
saves the trouble of developers cloning it themselves and building
the mache conda package.
  • Loading branch information
xylar committed Feb 3, 2023
1 parent 8486a07 commit a1dfac8
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 8 deletions.
23 changes: 18 additions & 5 deletions conda/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,10 @@ def get_env_setup(args, config, machine, compiler, mpi, env_type, source_path,
activ_path, env_path, env_name, activate_env, spack_env


def build_conda_env(env_type, recreate, machine, mpi, conda_mpi, version,
def build_conda_env(env_type, recreate, mpi, conda_mpi, version,
python, source_path, conda_template_path, conda_base,
env_name, env_path, activate_base, use_local,
local_conda_build, logger):
local_conda_build, logger, local_mache):

if env_type != 'dev':
install_miniconda(conda_base, activate_base, logger)
Expand Down Expand Up @@ -276,7 +276,8 @@ def build_conda_env(env_type, recreate, machine, mpi, conda_mpi, version,
conda_openmp = ''
spec_file = template.render(supports_otps=supports_otps,
mpi=conda_mpi, openmp=conda_openmp,
mpi_prefix=mpi_prefix)
mpi_prefix=mpi_prefix,
include_mache=not local_mache)

spec_filename = f'spec-file-{conda_mpi}.txt'
with open(spec_filename, 'w') as handle:
Expand Down Expand Up @@ -777,6 +778,8 @@ def main():

compass_version = get_version()

local_mache = args.mache_fork is not None and args.mache_branch is not None

machine = None
if not args.env_only:
if args.machine is None:
Expand Down Expand Up @@ -864,10 +867,20 @@ def main():

if previous_conda_env != conda_env_name:
build_conda_env(
env_type, recreate, machine, mpi, conda_mpi, compass_version,
env_type, recreate, mpi, conda_mpi, compass_version,
python, source_path, conda_template_path, conda_base,
conda_env_name, conda_env_path, activate_base, args.use_local,
args.local_conda_build, logger)
args.local_conda_build, logger, local_mache)

if local_mache:
print('Install local mache\n')
commands = f'source {conda_base}/etc/profile.d/conda.sh; ' \
f'source {conda_base}/etc/profile.d/mamba.sh; ' \
f'conda activate {conda_env_name}; ' \
'cd ../build_mache/mache; ' \
'python -m pip install .'
check_call(commands, logger=logger)

previous_conda_env = conda_env_name

if env_type != 'dev':
Expand Down
2 changes: 2 additions & 0 deletions conda/compass_env/spec-file.template
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ jigsaw=0.9.14
jigsawpy=0.3.3
jupyter
lxml
{% if include_mache %}
mache=1.12.0rc1
{% endif %}
matplotlib-base
metis
mpas_tools=0.17.0
Expand Down
26 changes: 23 additions & 3 deletions conda/configure_compass_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ def bootstrap(activate_install_env, source_path, local_conda_build):


def setup_install_env(env_name, activate_base, use_local, logger, recreate,
conda_base):
conda_base, mache):
env_path = os.path.join(conda_base, 'envs', env_name)
if use_local:
channels = '--use-local'
else:
channels = ''
packages = 'progressbar2 jinja2 "mache=1.12.0rc1"'
packages = 'progressbar2 jinja2 {}'.format(mache)
if recreate or not os.path.exists(env_path):
print('Setting up a conda environment for installing compass\n')
commands = '{}; ' \
Expand Down Expand Up @@ -101,8 +101,28 @@ def main():
# install miniconda if needed
install_miniconda(conda_base, activate_base, logger)

local_mache = args.mache_fork is not None and args.mache_branch is not None
if local_mache:
mache = ''
else:
mache = '"mache=1.12.0rc1"'

setup_install_env(env_name, activate_base, args.use_local, logger,
args.recreate, conda_base)
args.recreate, conda_base, mache)

if local_mache:
print('Clone and install local mache\n')
commands = '{}; ' \
'rm -rf conda/build_mache; ' \
'mkdir -p conda/build_mache; ' \
'cd conda/build_mache; ' \
'git clone -b {} [email protected]:{}.git mache; ' \
'cd mache; ' \
'python -m pip install .'.format(activate_install_env,
args.mache_branch,
args.mache_fork)

check_call(commands, logger=logger)

env_type = config.get('deploy', 'env_type')
if env_type not in ['dev', 'test_release', 'release']:
Expand Down
8 changes: 8 additions & 0 deletions conda/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ def parse_args(bootstrap):
"packages")
parser.add_argument("--use_local", dest="use_local", action='store_true',
help="Use locally built conda packages (for testing).")
parser.add_argument("--mache_fork", dest="mache_fork",
help="Point to a mache fork (and branch) for testing")
parser.add_argument("--mache_branch", dest="mache_branch",
help="Point to a mache branch (and fork) for testing")
parser.add_argument("--update_spack", dest="update_spack",
action='store_true',
help="If the shared spack environment should be "
Expand Down Expand Up @@ -78,6 +82,10 @@ def parse_args(bootstrap):

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

if (args.mache_fork is None) != (args.mache_branch is None):
raise ValueError('You must supply both or neither of '
'--mache_fork and --mache_branch')

return args


Expand Down

0 comments on commit a1dfac8

Please sign in to comment.