diff --git a/bin/compile b/bin/compile index baf25e5..476fe6f 100755 --- a/bin/compile +++ b/bin/compile @@ -2,7 +2,7 @@ # Usage: # -# $ bin/compile +# $ bin/compile # Fail fast and fail hard. @@ -16,6 +16,7 @@ BIN_DIR=$(cd $(dirname $0); pwd) # absolute path ROOT_DIR=$(dirname $BIN_DIR) BUILD_DIR=$1 CACHE_DIR=$2 +ENV_DIR=$3 CACHED_DIRS=".heroku" @@ -31,6 +32,7 @@ export BUILD_DIR CACHE_DIR BIN_DIR PROFILE_PATH # Syntax sugar. source $BIN_DIR/utils + # Directory Hacks for path consistiency. APP_DIR='/app' TMP_APP_DIR=$CACHE_DIR/tmp_app_dir @@ -73,7 +75,11 @@ set -e # Make profile.d directory. mkdir -p $(dirname $PROFILE_PATH) -# Actuall do the conda steps. +# Add environment variables +export_env_dir $ENV_DIR + + +# Actually do the conda steps. source $BIN_DIR/steps/conda_compile # ### Finalize diff --git a/bin/steps/conda_compile b/bin/steps/conda_compile index 5ef775d..bbc90b9 100755 --- a/bin/steps/conda_compile +++ b/bin/steps/conda_compile @@ -9,18 +9,32 @@ fi echo "nomkl" > $HOME/.heroku/miniconda/conda-meta/pinned echo "added pinned file in $HOME/.heroku/miniconda/conda-meta/pinned" -conda install nomkl +if [ -n "${CONDA_CHANNELS}" ]; then + for channel in ${CONDA_CHANNELS}; do + puts-step "Add conda channel $channel" + conda config --add channels $channel + done +fi + +conda install nomkl -if [ -f conda-requirements.txt ]; then - puts-step "Installing dependencies using Conda" - conda install --file conda-requirements.txt --yes | indent +puts-step "Looking for conda deps in ${CONDA_REQ_FILE:-conda-requirements.txt}" +if [ -f ${CONDA_REQ_FILE:-conda-requirements.txt} ]; then + puts-step "Installing dependencies using Conda form ${CONDA_REQ_FILE}" + conda install --file ${CONDA_REQ_FILE:-conda-requirements.txt} --yes | indent fi +puts-step "Looking for deps in requirements.txt" if [ -f requirements.txt ]; then - puts-step "Installing dependencies using Pip" + puts-step "Installing dependencies using Pip from requirements.txt" pip install -r requirements.txt --exists-action=w --allow-all-external | indent fi +if [ -f setup.py ]; then + puts-step "Installing setup.py using pip install -e ." + pip install --exists-action=w --allow-all-external -e . | indent +fi + # Clean up the installation environment . conda clean -pt --yes > /dev/null diff --git a/bin/utils b/bin/utils index d849e0c..e9d06d7 100755 --- a/bin/utils +++ b/bin/utils @@ -52,3 +52,16 @@ function deep-mv (){ rm -fr $1/!(tmp) find -H $1 -maxdepth 1 -name '.*' -a \( -type d -o -type f -o -type l \) -exec rm -fr '{}' \; } + +export_env_dir() { + env_dir=$1 + whitelist_regex=${2:-''} + blacklist_regex=${3:-'^(PATH|GIT_DIR|CPATH|CPPATH|LD_PRELOAD|LIBRARY_PATH|JAVA_OPTS)$'} + if [ -d "$env_dir" ]; then + for e in $(ls $env_dir); do + echo "$e" | grep -E "$whitelist_regex" | grep -qvE "$blacklist_regex" && + export "$e=$(cat $env_dir/$e)" + : + done + fi +}