Skip to content

Instantly share code, notes, and snippets.

@alloydwhitlock
Created January 3, 2019 22:22
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 alloydwhitlock/6656ac8d7e7a4b8edd378503cf281b1b to your computer and use it in GitHub Desktop.
Save alloydwhitlock/6656ac8d7e7a4b8edd378503cf281b1b to your computer and use it in GitHub Desktop.
Create a virtual environment for developers to use Airflow
#!/bin/bash
# Purpose: Setup local Airflow Python development environment
# Author: Adam Whitlock (adam@adamwhitlock.com)
# Version: 0.0.1
# Specify major version of Python used for Airflow
PYTHON_VERSION="2"
AIRFLOW_VERSION="1.10.1"
# Export this value to prevent issues with GPL code use
export SLUGIFY_USES_TEXT_UNIDECODE=yes
# If the virtualenv is present, give the option to remove
if [[ -d ./venv ]]; then
printf "Virtual environment already exists. Remove? (Y/N): "
read remove_virtenv
while true; do
case $remove_virtenv in
Y|y) rm -rf ./venv; echo "Removed!"; break ;;
N|n) echo "Skipped!"; VIRTEXIST=true break ;;
*) echo "Skipped!"; break ;;
esac
done
fi
printf "Setting up virtual environment for Airflow development:\n\n"
if [[ $PYTHON_VERSION -eq "2" ]]; then
PIP="pip"
elif [[ $PYTHON_VERSION -eq "3" ]]; then
PIP="pip3"
fi
# Check if Python version in PATH
if [[ `command -v python${PYTHON_VERSION} > /dev/null 2>&1` -ne 0 ]]; then
echo "Unable to find specified version of Python in PATH: python${PYTHON_VERSION}"
exit 1
fi
echo "python PATH validated..."
# Check if pip in PATH
if [[ `command -v ${PIP} > /dev/null 2>&1` -ne 0 ]]; then
echo "Unable to find specified version of Pip in PATH: ${PIP}"
exit 1
fi
echo "pip PATH validated..."
# Check if virtualenv in PATH
if [[ `command -v virtualenv > /dev/null 2>&1` -ne 0 ]]; then
echo "Unable to find specified virtualenv in PATH"
exit 1
fi
echo "virtualenv PATH validated..."
printf "\n\n"
# Create virtualenv
virtualenv -p `which python${PYTHON_VERSION}` venv
printf "\n\n\nTo use your Airflow virtual environment, source the virtualenv
file using \"source venv/bin/activate\" and to leave the environment, use
the \"deactivate\" command.\n\n!"
printf "Would you like to install Airflow in your environment (Y/N): "
read install_airflow
while true; do
case $install_airflow in
Y|y) source venv/bin/activate && ${PIP} install apache-airflow==${AIRFLOW_VERSION}; break ;;
N|n) echo "Thank you!"; break ;;
*) echo "Not activating at this time. You will have to activate manually."; break ;;
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment