Skip to content

Commit

Permalink
Merge pull request #739 from xylar/check-version-in-load-script
Browse files Browse the repository at this point in the history
Add a version check to load script
  • Loading branch information
xylar authored Nov 30, 2023
2 parents 9e8cbd1 + 70de75e commit a461f10
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 12 deletions.
15 changes: 8 additions & 7 deletions conda/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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())
Expand All @@ -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()
Expand Down Expand Up @@ -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)
Expand Down
26 changes: 26 additions & 0 deletions conda/compass_env/load_compass.template
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -10,3 +31,8 @@ echo
{{ spack }}

{{ env_vars }}

{% if env_type == 'dev' -%}
# the right compass version
fi
{%- endif %}
26 changes: 21 additions & 5 deletions docs/developers_guide/quick_start.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
~~~~~~~~~~~~~~~
Expand Down

0 comments on commit a461f10

Please sign in to comment.