Skip to content

Instantly share code, notes, and snippets.

@matthewrmshin
Last active May 4, 2020 11:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthewrmshin/74a7b78adecd297b40e64f6c867b316b to your computer and use it in GitHub Desktop.
Save matthewrmshin/74a7b78adecd297b40e64f6c867b316b to your computer and use it in GitHub Desktop.
A set of Python applications run by a Cylc suite using a shared environment in tasks. This script installs the environment in the suite.
#!/bin/bash
#------------------------------------------------------------------------------
# This script is used by a Python project that is also a Cylc suite.
# An initial task in the suite runs this script to build and install the Python
# project and its environment in a self-contained Conda environment under
# `~/cylc-run/SUITE/share/condaenv/`.
# Subsequent tasks activates this environnment using:
# set +u
# . "${USER_CONDA_PROFILE}"
# conda activate "${SUITE_CONDA_ENV}"
# set -u
# ------------------------------------------------------------------------------
# Note: "conda" does not work with "set -u"
set -eo pipefail
SUITE_CONDA_ENV="${1:-${CYLC_SUITE_SHARE_DIR}/condaenv}"
# Gain access to the "conda" command.
. "${USER_CONDA_PROFILE:-${HOME}/miniconda3/etc/profile.d/conda.sh}"
# Create or update Conda environment. Activate it.
if conda activate "${SUITE_CONDA_ENV}"; then
conda env update \
--prune \
-p "${SUITE_CONDA_ENV}" \
-f "${CYLC_SUITE_RUN_DIR}/environment.yml"
pip uninstall -y 'stf' || true
else
conda env create \
--force \
-p "${SUITE_CONDA_ENV}" \
-f "${CYLC_SUITE_RUN_DIR}/environment.yml"
conda activate "${SUITE_CONDA_ENV}"
fi
# Install project to Conda environment
set -u
pushd "${CYLC_SUITE_RUN_DIR}"
python3 "./setup.py" 'install'
popd
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment