From a1dfac8d99ef7b11f312ed2e792df190f1651c49 Mon Sep 17 00:00:00 2001 From: Xylar Asay-Davis Date: Thu, 2 Feb 2023 23:04:48 -0700 Subject: [PATCH] Enable easier mache testing 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. --- conda/bootstrap.py | 23 ++++++++++++++++++----- conda/compass_env/spec-file.template | 2 ++ conda/configure_compass_env.py | 26 +++++++++++++++++++++++--- conda/shared.py | 8 ++++++++ 4 files changed, 51 insertions(+), 8 deletions(-) diff --git a/conda/bootstrap.py b/conda/bootstrap.py index 5f1b6eaa32..c029f66b41 100755 --- a/conda/bootstrap.py +++ b/conda/bootstrap.py @@ -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) @@ -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: @@ -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: @@ -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': diff --git a/conda/compass_env/spec-file.template b/conda/compass_env/spec-file.template index 6df2e8acd9..0421f2f2ed 100644 --- a/conda/compass_env/spec-file.template +++ b/conda/compass_env/spec-file.template @@ -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 diff --git a/conda/configure_compass_env.py b/conda/configure_compass_env.py index d12343f7ae..30a7a49b84 100755 --- a/conda/configure_compass_env.py +++ b/conda/configure_compass_env.py @@ -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 = '{}; ' \ @@ -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 {} git@github.com:{}.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']: diff --git a/conda/shared.py b/conda/shared.py index 0ec9498d79..9bbd8d3639 100644 --- a/conda/shared.py +++ b/conda/shared.py @@ -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 " @@ -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