|
1 | 1 | #!/bin/bash -e |
2 | 2 |
|
3 | | -# On Mac OS X workers we are responsible for creating the Python virtual |
4 | | -# environment, because we set `language: generic' in the Travis CI build |
5 | | -# configuration file (to bypass the lack of Python runtime support). |
6 | | -if [ "$TRAVIS_OS_NAME" = osx ]; then |
7 | | - VIRTUAL_ENV="$HOME/virtualenv/python2.7" |
8 | | - if [ ! -x "$VIRTUAL_ENV/bin/python" ]; then |
9 | | - if ! which virtualenv &>/dev/null; then |
10 | | - # Install `virtualenv' in ~/.local (doesn't require `sudo' privileges). |
11 | | - pip install --user virtualenv |
12 | | - # Make sure ~/.local/bin is in the $PATH. |
13 | | - LOCAL_BINARIES=$(python -c 'import os, site; print(os.path.join(site.USER_BASE, "bin"))') |
14 | | - export PATH="$PATH:$LOCAL_BINARIES" |
| 3 | +main () { |
| 4 | + |
| 5 | + # On Mac OS X workers we are responsible for creating the Python virtual |
| 6 | + # environment, because we set `language: generic' in the Travis CI build |
| 7 | + # configuration file (to bypass the lack of Python runtime support). |
| 8 | + if [ "$TRAVIS_OS_NAME" = osx ]; then |
| 9 | + local environment="$HOME/virtualenv/python2.7" |
| 10 | + if [ -x "$environment/bin/python" ]; then |
| 11 | + msg "Activating virtual environment ($environment) .." |
| 12 | + source "$environment/bin/activate" |
| 13 | + else |
| 14 | + if ! which virtualenv &>/dev/null; then |
| 15 | + msg "Installing 'virtualenv' in per-user site-packages .." |
| 16 | + pip install --user virtualenv |
| 17 | + msg "Figuring out 'bin' directory of per-user site-packages .." |
| 18 | + LOCAL_BINARIES=$(python -c 'import os, site; print(os.path.join(site.USER_BASE, "bin"))') |
| 19 | + msg "Prefixing '$LOCAL_BINARIES' to PATH .." |
| 20 | + export PATH="$LOCAL_BINARIES:$PATH" |
| 21 | + fi |
| 22 | + msg "Creating virtual environment ($environment) .." |
| 23 | + virtualenv "$environment" |
| 24 | + msg "Activating virtual environment ($environment) .." |
| 25 | + source "$environment/bin/activate" |
| 26 | + msg "Checking if 'pip' executable works .." |
| 27 | + if ! pip --version; then |
| 28 | + msg "Bootstrapping working 'pip' installation using get-pip.py .." |
| 29 | + curl -s https://bootstrap.pypa.io/get-pip.py | python - |
| 30 | + fi |
15 | 31 | fi |
16 | | - virtualenv "$VIRTUAL_ENV" |
17 | 32 | fi |
18 | | - source "$VIRTUAL_ENV/bin/activate" |
19 | | -fi |
20 | 33 |
|
21 | | -# Install the required Python packages. |
22 | | -pip install --requirement=requirements-travis.txt |
| 34 | + # Install the required Python packages. |
| 35 | + pip install --requirement=requirements-travis.txt |
| 36 | + |
| 37 | + # Install the project itself, making sure that potential character encoding |
| 38 | + # and/or decoding errors in the setup script are caught as soon as possible. |
| 39 | + LC_ALL=C pip install . |
| 40 | + |
| 41 | +} |
| 42 | + |
| 43 | +msg () { |
| 44 | + echo "[install-on-travis.sh] $*" >&2 |
| 45 | +} |
23 | 46 |
|
24 | | -# Install the project itself, making sure that potential character encoding |
25 | | -# and/or decoding errors in the setup script are caught as soon as possible. |
26 | | -LC_ALL=C pip install . |
| 47 | +main "$@" |
0 commit comments