Skip to content

Instantly share code, notes, and snippets.

@michaelxor
Forked from anonymous/py_install.sh
Last active January 2, 2016 13:49
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 michaelxor/8312644 to your computer and use it in GitHub Desktop.
Save michaelxor/8312644 to your computer and use it in GitHub Desktop.
#!/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"
# we'll need to source the included bash startup file
# to give us access to virtualenvwrapper functions
source config.bash
# contents of the above config file included for clarity:
# export WORKON_HOME=$HOME/.virtualenvs
# export PROJECT_HOME=$HOME/Code
# if [[ -r /usr/local/bin/virtualenvwrapper.sh ]]; then
# source /usr/local/bin/virtualenvwrapper.sh
# fi
# 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