Skip to content

Instantly share code, notes, and snippets.

@drewbanin
Last active July 11, 2017 15:54
Show Gist options
  • Save drewbanin/1dd9da1c838ebe3dd02641f02fc4b301 to your computer and use it in GitHub Desktop.
Save drewbanin/1dd9da1c838ebe3dd02641f02fc4b301 to your computer and use it in GitHub Desktop.
#!/bin/bash
INSANE_PYTHON='/usr/bin/python' # not sane?
VENV_PATH="$HOME/.dbt/dbt-dev-env"
DBT_REPO_REMOTE="https://github.com/fishtown-analytics/dbt.git"
DBT_LOCAL_PATH="${TMPDIR}dbt-development"
DBT_ALIAS="use-dbt-dev"
function install_python() {
echo 'Installing python'
brew install python3
brew link python3
}
function create_venv() {
echo "Creating virtualenv at ${VENV_PATH}"
mkdir -p "$VENV_PATH"
python3 -m venv "${VENV_PATH}"
}
# Install sane python if needed
installed_python="$(which python)"
if [ $installed_python = $INSANE_PYTHON ] ; then
install_python
else
echo "Python ${installed_python} is sane"
fi
# Create a new virtualenv if needed
if [ ! -d $VENV_PATH ] ; then
create_venv
fi
# Always pull latest dbt
echo "Getting latest dbt development"
if [ -d $DBT_LOCAL_PATH ] ; then
echo "Already downloaded -- pulling development"
pushd .
cd $DBT_LOCAL_PATH
git pull origin master
popd
else
echo "Cloning dbt"
git clone "$DBT_REPO_REMOTE" "$DBT_LOCAL_PATH"
fi
# Install dbt into venv
source "${VENV_PATH}/bin/activate"
pip install --upgrade pip
pip install --upgrade setuptools
echo "Installing latest dbt development"
pip install $DBT_LOCAL_PATH
alias $DBT_ALIAS 2>/dev/null >/dev/null
is_installed=$?
echo
echo
echo "============================================================================"
if [ 1 -eq $is_installed ] ; then
echo "Run the following lines of code to complete installation:"
echo
echo "echo 'alias $DBT_ALIAS=\"source ${VENV_PATH}/bin/activate\"' >> ~/.profile"
echo "source ~/.profile"
echo
echo "----------------------------------------------------------------------------"
echo
fi
echo "To use a development version of dbt, run:"
echo
echo " $DBT_ALIAS"
echo
echo "To later revert to a production build, run:"
echo
echo " deactivate"
echo
echo "============================================================================"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment