Skip to content

Instantly share code, notes, and snippets.

@rmyers
Last active October 5, 2015 16:48
Show Gist options
  • Save rmyers/2839803 to your computer and use it in GitHub Desktop.
Save rmyers/2839803 to your computer and use it in GitHub Desktop.
Create a Virtual ENV for appengine and python2.7
#!/bin/bash
#
# Build a virtual environment suitable for running appengine.
# This uses virtualenvwrapper to make the virtual environment.
# Which you can activate with 'workon appengine'
#
# Everyone loves one-liners!
# Mac one-liner:
# $ curl -s https://raw.github.com/gist/2839803 | bash
#
# Ubuntu one-liner:
# $ sudo apt-get install curl && curl -s https://raw.github.com/gist/1012769 | bash
#
#
# Install steps:
# 1) Checks for virtualenvwrapper and install if needed.
# 2) Activates virtualenvwrapper and creates $WORKON_HOME
# 3) Makes 'appengine' virtual environment
# 4) Downloads and extracts google appengine source
# 5) pip installs a few extra packages
#
# Ubuntu Install Help
# 1) sudo apt-get install curl python-setuptools
#
# CHANGELOG
# 11-18-12 - Fixed url for the appengine version check.
# 05-16-12 - Fixing typos in if statements.
# 11-01-11 - Adding support for Macosx Lion.
# 11-01-11 - Fixing bug in platform check which was always true.
# 10-03-11 - Adding support for Ubunutu.
PLATFORM=`uname -s`
VERSION=`uname -r`
if [[ $PLATFORM == "Linux" ]]
then
# check for individual packages in case they already had python2.5
# just in case
if [[ ! -e /usr/bin/curl ]]
then
sudo apt-get install curl
fi
if [[ ! -e /usr/bin/easy_install ]]
then
sudo apt-get install python-setuptools
fi
# check for ssl
if [[ ! -e /usr/include/openssl/ssl.h ]]
then
sudo apt-get install libssl-dev
fi
# check for libbluetooth-dev
if [[ ! -e /usr/include/bluetooth/bluetooth.h ]]
then
sudo apt-get install libbluetooth-dev
fi
fi
LATEST_VERSION=`curl -s https://appengine.google.com/api/updatecheck | awk '$1 ~/release/ {print $2};' | sed s/\"//g`
# Modify me as new versions are released.
APPENGINE_VERSION=google_appengine_$LATEST_VERSION.zip
which virtualenvwrapper.sh
VWNOTFOUND=$?
if [[ $VWNOTFOUND == 1 ]]
then
echo 'Installing virtualenvwrapper...'
sudo easy_install virtualenvwrapper
fi
if [[ ! $WORKON_HOME ]]
then
export WORKON_HOME=$HOME/envs
fi
# make sure we are not dealing with a customize path
unset PYTHONPATH
mkdir -p $WORKON_HOME
source `which virtualenvwrapper.sh`
cd $WORKON_HOME
if [[ -e appengine ]]
then
echo "Using existing appengine ENV"
workon appengine
else
mkvirtualenv --no-site-packages --distribute --python=python2.7 appengine
fi
if [[ ! $VIRTUAL_ENV ]]
then
echo "Problem running mkvirtualenv!"
exit 1
fi
# Don't download the file over again.
if [[ ! -e $APPENGINE_VERSION ]]
then
curl -O http://googleappengine.googlecode.com/files/$APPENGINE_VERSION
fi
echo "Extracting Google App Engine source..."
unzip -uq $APPENGINE_VERSION -d $VIRTUAL_ENV
if [[ ! $? == 0 ]]
then
echo "Problem unzipping file $APPENGINE_VERISON"
echo "Please delete it and try again!"
exit $?
fi
# Create a pth file for App Engine source
echo "$VIRTUAL_ENV/google_appengine" > $VIRTUAL_ENV/lib/python2.7/site-packages/gae.pth
# Link scripts
cd $VIRTUAL_ENV/bin
ln -s $VIRTUAL_ENV/google_appengine/*.py .
# On mac's add some compiler flags.
if [[ $PLATFORM == "Darwin" ]]
then
ARCHFLAGS="-arch i386 -arch x86_64"
fi
for package in webtest PIL fabric coverage ipython==0.10.2
do
echo "Installing $package ..."
pip install -qU $package
done
# uninstall webob as it conflicts with the bundled one in app engine.
echo "Uninstalling webob ..."
pip uninstall -q -y webob
echo "You are ready to roll. Edit .bashrc as needed and run 'workon appengine'"
if [[ $VWNOTFOUND == 1 ]]
then
echo "Virtualenvwrapper has been installed."
echo "Please add the following to your .bashrc file:"
echo ' export WORKON_HOME=$HOME/envs'
echo ' source `which virtualenvwrapper.sh`'
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment