Created
March 21, 2017 18:53
-
-
Save r35krag0th/8bfd06989857b5bbc3f3632cf244a73b to your computer and use it in GitHub Desktop.
PyEnv Wrapper (Docker)
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 | |
shopt -s expand_aliases | |
wrapper_log() { | |
echo -e "\033[1;32m[py27-wrapper]\033[0m $*\033[0m" | |
} | |
export PATH="$HOME/.pyenv/bin:$PATH" | |
export PATH="/app/.pyenv/bin:$PATH" | |
YOUR_COMMAND=$* | |
WHICH_PYENV=$(which pyenv) | |
eval "$(pyenv init -)" | |
eval "$(pyenv virtualenv-init -)" | |
VIRTUALENV_WRAPPER_ENABLED="no" | |
VIRTUALENV_WRAPPER_BIN=$(pyenv which virtualenvwrapper.sh 2>/dev/null) | |
if [ -f "${VIRTUALENV_WRAPPER_BIN}" ]; then | |
wrapper_log "VirtualEnv Wrapper was found!" | |
VIRTUALENV_WRAPPER_ENABLED="yes" | |
source ${VIRTUALENV_WRAPPER_BIN} | |
if [ ! "${ACTIVATE_ENV}" == "" ]; then | |
wrapper_log "Auto-Activating VirtualEnv $ACTIVATE_ENV" | |
workon ${ACTIVATE_ENV} | |
fi | |
fi | |
PYTHON_BIN=$(which python) | |
PYENV_PYTHON_VERSION=$(python --version 2>&1 | cut -f2 -d' ') | |
wrapper_log "" | |
wrapper_log "PyEnv Location: ${WHICH_PYENV}" | |
wrapper_log " PyEnv Prefix: $(pyenv prefix)" | |
wrapper_log " Python Binary: ${PYTHON_BIN}" | |
wrapper_log "Python Version: ${PYENV_PYTHON_VERSION}" | |
wrapper_log "VirtualEnvWrap: ${VIRTUALENV_WRAPPER_ENABLED}" | |
wrapper_log " Virtual Env: ${ACTIVATE_ENV}" | |
wrapper_log "" | |
wrapper_log "Running ==> ${YOUR_COMMAND}" | |
wrapper_log "" | |
declare -f -F $1 2>&1 >/dev/null | |
RC=$? | |
if [ $RC -eq 0 ]; then | |
$YOUR_COMMAND | |
else | |
exec $YOUR_COMMAND | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment