Skip to content

Instantly share code, notes, and snippets.

@madebyjazz
Forked from rmyers/mkappenginevenv.sh
Created June 22, 2011 16:38
Show Gist options
  • Save madebyjazz/1040496 to your computer and use it in GitHub Desktop.
Save madebyjazz/1040496 to your computer and use it in GitHub Desktop.
Setup virtual env for appengine
#!/bin/bash
#
# Build a virtual environment suitable for running appengine.
# This uses virtualenvwrapper to make the virtual environment
# and modifies the postactivate/postdeactivate scripts to make
# the appengine code happy.
#
# Usage:
# $ 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) Modifies postactivate scripts
# 5) Downloads and extracts google appengine source
# 6) pip installs a few extra packages
#
#
# Modify me as new versions are released.
APPENGINE_VERSION=google_appengine_1.5.0.zip
PLATFORM=`uname -s`
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 "Deleting existing appengine ENV"
rm -rf appengine
fi
mkvirtualenv --no-site-packages --distribute --python=python2.5 appengine
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 -q $APPENGINE_VERSION -d $VIRTUAL_ENV
# Create a pth file for App Engine source
echo "$VIRTUAL_ENV/google_appengine" > $VIRTUAL_ENV/lib/python2.5/site-packages/gae.pth
# Link scripts
cd $VIRTUAL_ENV/bin
ln -s $VIRTUAL_ENV/google_appengine/*.py .
# link os.pyc to make appengine happy
REALPREFIX=`python2.5 -c "import sys;print sys.real_prefix"`
cd $VIRTUAL_ENV/lib/python2.5
echo "Linking os.pyc to $REALPREFIX/lib/python2.5/os.pyc"
rm -rf os.pyc
ln -s $REALPREFIX/lib/python2.5/os.pyc
# On mac's add some compiler flags.
if [[ $PLATFORM -eq "Darwin" ]]
then
ARCHFLAGS="-arch i386 -arch x86_64"
fi
for package in webtest PIL fabric coverage django==1.1
do
echo "Installing $package ..."
pip install -q $package
done
# SSL needs to be installed with sudo!! lame!
echo "Installing ssl with sudo:"
sudo pip install -q ssl
echo "Fixing perms"
sudo chown -R `whoami` $VIRTUAL_ENV
# 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