Last active
May 4, 2020 11:04
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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