Skip to content

Instantly share code, notes, and snippets.

Created January 8, 2014 06:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/8312638 to your computer and use it in GitHub Desktop.
Save anonymous/8312638 to your computer and use it in GitHub Desktop.
Snippet for a python script intended to provision a Mac OSX machine with virtualenv & virtualenvwrapper, then install bundled requirements to a default virtualenv.
#!/bin/bash
#
# Python
#
# This will install the latest python 2.x branch via
# Homebrew, install virtualenv and virtualenvwrapper packages
# globally via pip, then create a base virtual environment under
# the branch and install the packages in requirements.txt
#
# alternate version that does not depend on virtualenvwrapper is
# available here:
# https://gist.github.com/michaelxor/8136225
run_python() {
if type_exists "brew"; then
# install latest python 2.x branches, if necessary
if ! formula_exists "python"; then
e_header "Installing Python 2.x..."
brew install python
# make sure we're using brew's python
brew link --overwrite python
fi
# make sure we're not in a virtualenv already
if [[ ! -z "$VIRTUAL_ENV" ]]; then
deactivate
fi
# make sure these are available globally
pip install virtualenv virtualenvwrapper
# new envs
INITIAL_ENV="pymordial"
# the first time we run this we'll need to source the
# included bash startup file
source config.bash
# copy some default virtualenvwrapper hooks into the global hook dir
seek_confirmation "Warning: This step may overwrite your virtualenvwrapper hooks."
if is_confirmed; then
ln -fs ${HOME}/.dotfiles/python/virtualenvwrapper/* "${WORKON_HOME}/"
fi
# create the 2.x virtualenv
if [[ ! $(workon | grep -e "^${INITIAL_ENV}$") ]]; then
e_header "Creating new virtualenv ${INITIAL_ENV}..."
mkvirtualenv ${INITIAL_ENV}
fi
e_header "Updating pip for all virtual environments..."
allvirtualenv pip install -U pip
e_header "Updating packages for ${INITIAL_ENV}..."
workon ${INITIAL_ENV}
pip install -r requirements.txt
deactivate
[[ $? ]] && e_success "Done"
else
printf "\n"
e_error "Error: Homebrew not found."
printf "Aborting...\n"
exit
fi
}
run_python
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment