From a3bb4bfb9fa7a5ecbf1db2e39d344f39e47ee3aa Mon Sep 17 00:00:00 2001 From: Nate Hardison Date: Thu, 11 Apr 2013 16:03:48 -0700 Subject: [PATCH] Updating dev environment setup * Script now installs RVM in conventional location (~/.rvm) by default, though it allows for the override if desired. This will enable folks to install edX alongside other Ruby projects also using RVM. * Script now uses virtualenvwrapper to ease the process of enabling the edX virtualenv and to allow for easy switching back and forth between virtualenv projects. It now also installs the "mitx" virtualenv in the conventional location of ~/.virtualenv. * Adding a .rvmrc file so that the Ruby environment will be automatically activated (via `rvm use`) whenever the user hits the `mitx/` directory. --- .rvmrc | 1 + create-dev-env.sh | 141 +++++++++++++++++++++++++++++++++++----------- 2 files changed, 108 insertions(+), 34 deletions(-) create mode 100644 .rvmrc diff --git a/.rvmrc b/.rvmrc new file mode 100644 index 0000000000..348cf3e59c --- /dev/null +++ b/.rvmrc @@ -0,0 +1 @@ +rvm use 1.9.3-p374@mitx diff --git a/create-dev-env.sh b/create-dev-env.sh index f0ebca3ff7..9993461722 100755 --- a/create-dev-env.sh +++ b/create-dev-env.sh @@ -26,12 +26,15 @@ EOL printf '\E[0m' } + error() { printf '\E[31m'; echo "$@"; printf '\E[0m' } + output() { printf '\E[36m'; echo "$@"; printf '\E[0m' } + usage() { cat< $HOME/.rvmrc +# If we're not installing RVM in the default location, then we'll do some +# funky stuff to make sure that we load in the RVM stuff properly on login. +if [ "$HOME/.rvm" != $RUBY_DIR ]; then + if ! grep -q "export rvm_path=$RUBY_DIR" ~/.rvmrc; then + if [[ -f $HOME/.rvmrc ]]; then + output "Copying existing .rvmrc to .rvmrc.bak" + cp $HOME/.rvmrc $HOME/.rvmrc.bak + fi + output "Creating $HOME/.rvmrc so rvm uses $RUBY_DIR" + echo "export rvm_path=$RUBY_DIR" > $HOME/.rvmrc + fi fi curl -sL get.rvm.io | bash -s -- --version 1.15.7 -source $RUBY_DIR/scripts/rvm + +# Ensure we have RVM available as a shell function so that it can mess +# with the environment and set everything up properly. The RVM install +# process adds this line to login scripts, so this shouldn't be necessary +# for the user to do each time. +if [[ `type -t rvm` != "function" ]]; then + source $RUBY_DIR/scripts/rvm +fi + +# Ruby doesn't like to build with clang, which is the default on OS X, so +# use gcc instead. This may not work, since if your gcc was installed with +# XCode 4.2 or greater, you have an LLVM-based gcc, which also doesn't +# always play nicely with Ruby, though it seems to be better than clang. +# You may have to install apple-gcc42 using Homebrew if this doesn't work. +# See `rvm requirements` for more information. +case `uname -s` in + Darwin) + # TODO (Nate): test to see if CC is already set to gcc or something + # similar first (not clang). + export CC=gcc + ;; +esac + +# Let the repo override the version of Ruby to install +if [[ -r $BASE/mitx/.ruby-version ]]; then + RUBY_VER=`cat $BASE/mitx/.ruby-version` +fi + +# Current stable version of RVM (1.19.0) requires the following to build Ruby: +# +# autoconf automake libtool pkg-config libyaml libxml2 libxslt libksba openssl +# +# If we decide to upgrade from the current version (1.15.7), can run +# +# LESS="-E" rvm install $RUBY_VER --autolibs=3 --with-readline +# +# to have RVM look for a package manager like Homebrew and install any missing +# libs automatically. RVM's --autolibs flag defaults to 2, which will fail if +# any required libs are missing. LESS="-E" rvm install $RUBY_VER --with-readline +# Create the "mitx" gemset +rvm use "$RUBY_VER@mitx" --create + output "Installing gem bundler" gem install bundler output "Installing ruby packages" -# hack :( -cd $BASE/mitx || true -bundle install +bundle install --gemfile $BASE/mitx/Gemfile # Install Python virtualenv @@ -274,16 +326,31 @@ case `uname -s` in ;; esac +# virtualenvwrapper uses the $WORKON_HOME env var to determine where to place +# virtualenv directories. Make sure it matches the selected $PYTHON_DIR. +export WORKON_HOME=$PYTHON_DIR + +# Load in the mkvirtualenv function if needed +if [[ `type -t mkvirtualenv` != "function" ]]; then + source `which virtualenvwrapper.sh` +fi + +# Create MITx virtualenv and link it to repo +# virtualenvwrapper automatically sources the activation script if [[ $systempkgs ]]; then - virtualenv --system-site-packages "$PYTHON_DIR" + mkvirtualenv -a "$BASE/mitx" --system-site-packages mitx || { + error "mkvirtualenv exited with a non-zero error" + return 1 + } else # default behavior for virtualenv>1.7 is # --no-site-packages - virtualenv "$PYTHON_DIR" + mkvirtualenv -a "$BASE/mitx" mitx || { + error "mkvirtualenv exited with a non-zero error" + return 1 + } fi -# activate mitx python virtualenv -source $PYTHON_DIR/bin/activate # compile numpy and scipy if requested @@ -315,6 +382,8 @@ case `uname -s` in # need latest pytz before compiling numpy and scipy pip install -U pytz pip install numpy + # scipy needs cython + pip install cython # fixes problem with scipy on 10.8 pip install -e git+https://github.com/scipy/scipy#egg=scipy-dev ;; @@ -344,14 +413,18 @@ cat<