+# Sanity check
+if ! [[ -n "$WORKSPACE" ]]; then
+ echo >&2 "$helpmessage"
+ echo >&2
+ echo >&2 "Error: WORKSPACE environment variable not set"
+ echo >&2
+ exit 1
+fi
+
+echo "WORKSPACE=$WORKSPACE"
+
+if [[ -z "$CONFIGSRC" ]] && [[ -d "$HOME/arvados-api-server" ]]; then
+ # Jenkins expects us to use this by default.
+ CONFIGSRC="$HOME/arvados-api-server"
+fi
+
+# Clean up .pyc files that may exist in the workspace
+cd "$WORKSPACE"
+find -name '*.pyc' -delete
+
+# Set up temporary install dirs (unless existing dirs were supplied)
+for tmpdir in VENVDIR GOPATH GEMHOME
+do
+ if [[ -n "${!tmpdir}" ]]; then
+ leave_temp[$tmpdir]=1
+ else
+ eval $tmpdir=$(mktemp -d)
+ fi
+done
+
+# When our "bundle install"s need to install new gems to satisfy
+# dependencies, we want them to go where "gem install --user-install"
+# would put them. If rvm is in use (or something else has set
+# GEM_HOME) we assume "bundle install" already does something
+# reasonable.
+
+if [ -z "$GEM_HOME" ]; then
+ user_gempath="$(gem env gempath)"
+ export GEM_HOME="${user_gempath%%:*}"
+fi
+PATH="$(gem env gemdir)/bin:$PATH"
+
+# When we build and install our own gems, we install them in our
+# $GEMHOME tmpdir, and we want them to be at the front of GEM_PATH and
+# PATH so integration tests prefer them over other versions that
+# happen to be installed in $user_gempath, system dirs, etc.
+
+tmpdir_gem_home="$(env - PATH="$PATH" HOME="$GEMHOME" gem env gempath | cut -f1 -d:)"
+PATH="${tmpdir_gem_home%%:*}/bin:$PATH"
+export GEM_PATH="$tmpdir_gem_home:$(gem env gempath)"
+
+echo "PATH=$PATH"
+echo "Will install dependencies to $GEM_HOME"
+echo "Will install arvados gems to $tmpdir_gem_home"
+echo "Gem search path is GEM_PATH=$GEM_PATH"
+
+if ! which bundler >/dev/null
+then
+ gem install --user-install bundler || fatal 'Could not install bundler'
+fi
+
+export GOPATH
+mkdir -p "$GOPATH/src/git.curoverse.com"
+ln -sfn "$WORKSPACE" "$GOPATH/src/git.curoverse.com/arvados.git" \
+ || fatal "symlink failed"
+
+virtualenv --setuptools "$VENVDIR" || fatal "virtualenv $VENVDIR failed"
+. "$VENVDIR/bin/activate"
+
+# Needed for run_test_server.py which is used by certain (non-Python) tests.
+pip install PyYAML
+