diff --git a/conda/bootstrap.py b/conda/bootstrap.py index da68bd5f14..b6f41f47bf 100755 --- a/conda/bootstrap.py +++ b/conda/bootstrap.py @@ -544,7 +544,8 @@ def set_ld_library_path(spack_branch_base, spack_env, logger): def write_load_compass(template_path, activ_path, conda_base, env_type, activ_suffix, prefix, env_name, spack_script, machine, - env_vars, env_only, source_path, without_openmp): + env_vars, env_only, source_path, without_openmp, + compass_version): try: os.makedirs(activ_path) @@ -575,10 +576,6 @@ def write_load_compass(template_path, activ_path, conda_base, env_type, env_vars = f'{env_vars}\n' \ f'export COMPASS_MACHINE={machine}' - if env_type == 'dev': - env_vars = f'{env_vars}\n' \ - f'export COMPASS_BRANCH={source_path}' - filename = f'{template_path}/load_compass.template' with open(filename, 'r') as f: template = Template(f.read()) @@ -603,7 +600,10 @@ def write_load_compass(template_path, activ_path, conda_base, env_type, script = template.render(conda_base=conda_base, compass_env=env_name, env_vars=env_vars, spack=spack_script, - update_compass=update_compass) + update_compass=update_compass, + env_type=env_type, + compass_source_path=source_path, + compass_version=compass_version) # strip out redundant blank lines lines = list() @@ -1035,7 +1035,8 @@ def main(): # noqa: C901 script_filename = write_load_compass( conda_template_path, activ_path, conda_base, env_type, activ_suffix, prefix, conda_env_name, spack_script, machine, - env_vars, args.env_only, source_path, args.without_openmp) + env_vars, args.env_only, source_path, args.without_openmp, + compass_version) if args.check: check_env(script_filename, conda_env_name, logger) diff --git a/conda/compass_env/load_compass.template b/conda/compass_env/load_compass.template index 15513a6631..bbfb1f87b6 100644 --- a/conda/compass_env/load_compass.template +++ b/conda/compass_env/load_compass.template @@ -1,3 +1,24 @@ +{% if env_type == 'dev' -%} +export COMPASS_BRANCH="{{ compass_source_path }}" +export COMPASS_VERSION="{{ compass_version }}" + +version_file="${COMPASS_BRANCH}/compass/version.py" +code_version=$(cat $version_file) +if [[ "$code_version" != *"$COMPASS_VERSION"* ]]; then + +echo "This load script is for a different version of compass:" +echo "__version__ = '$COMPASS_VERSION'" +echo "" +echo "Your code is version:" +echo "$code_version" +echo "" +echo "You need to run ./conda/configure_compass_env.py to update your conda " +echo "environment and load script." + +else +# the right compass version +{%- endif %} + echo Loading conda environment source {{ conda_base }}/etc/profile.d/conda.sh source {{ conda_base }}/etc/profile.d/mamba.sh @@ -10,3 +31,8 @@ echo {{ spack }} {{ env_vars }} + +{% if env_type == 'dev' -%} +# the right compass version +fi +{%- endif %} diff --git a/docs/developers_guide/quick_start.rst b/docs/developers_guide/quick_start.rst index c7cded691e..8042eefb4d 100644 --- a/docs/developers_guide/quick_start.rst +++ b/docs/developers_guide/quick_start.rst @@ -265,7 +265,7 @@ the branch is. If you do not use the worktree approach, you will also need to check what branch you are currently on with ``git log``, ``git branch`` or a similar command. -If you wish to work with another compiler, simply rerun the script with a new +If you wish to work with another compiler, simply rerun the configure script with a new compiler name and an activation script will be produced. You can then source either activation script to get the same conda environment but with different compilers and related modules. Make sure you are careful to set up compass by @@ -324,6 +324,22 @@ you have worked with (or if you aren't sure), it is safest to not just reinstall the ``compass`` package but also to check the dependencies by re-running: ``./conda/configure_compass_env.py`` with the same arguments as above. This will also reinstall the ``compass`` package from the current directory. +The activation script includes a check to see if the version of compass used +to produce the load script is the same as the version of compass in the +current branch. If the two don't match, an error like the following results +and the environment is not activated: + +.. code-block:: + + $ source load_compass_test_morpheus_gnu_openmpi.sh + This load script is for a different version of compass: + __version__ = '1.2.0-alpha.6' + + Your code is version: + __version__ = '1.2.0-alpha.7' + + You need to run ./conda/configure_compass_env.py to update your conda + environment and load script. If you need more than one conda environment (e.g. because you are testing multiple branches at the same time), you can choose your own name @@ -360,10 +376,10 @@ switch branches. python -m pip install -e . The activation script will do this automatically when you source it in - the root directory of your compass branch. This is substantially faster - than rerunning ``./conda/configure_compass_env.py ...`` but risks - dependencies being out of date. Since dependencies change fairly rarely, - this will usually be safe. + the root directory of your compass branch. The activation script will also + check if the current compass version matches the one used to create the + activation script, thus catching situations where the dependencies are out + of date and the configure script needs to be rerun. Troubleshooting ~~~~~~~~~~~~~~~