1
1
#! /bin/bash
2
2
3
3
# This script tests the packaging of compdb on Ubuntu Trusty.
4
- # It has been made to run on Travis CI and locally on Ubuntu 14.04,
5
- # or locally inside docker thanks to docker/ubuntu-trusty.sh.
4
+
5
+ # It has been made to run on Travis CI and inside docker image of Ubuntu 14.04.
6
+ # For the docker image, one can use docker/ubuntu-trusty.sh.
7
+ # At this time it is not recommended to run this locally
8
+ # because files are created in the user home directory.
6
9
# The dependencies can be found in docker/ubuntu-trusty/Dockerfile.
7
10
8
11
if [[ ! -f compdb/__init__.py ]]; then
13
16
set -o errexit
14
17
set -o xtrace
15
18
19
+ # Initial goal for this script was to run in a "pristine" Ubuntu Trusty,
20
+ # with a stock installation of python,
21
+ # unfortunately Travis CI uses isolated virtualenvs:
22
+ # - https://docs.travis-ci.com/user/languages/python/#Travis-CI-Uses-Isolated-virtualenvs
23
+ #
24
+ # This means, one has to accomodate the 'pip install' commands
25
+ # to not use the --user options when run under virtualenv.
26
+ # Doing otherwise, triggers the following error:
27
+ # $ pip install --user .
28
+ # Can not perform a '--user' install. User site-packages are not visible in this virtualenv.
29
+ #
30
+ # virtualenv detection logic copied from pip:
31
+ # - https://github.com/pypa/pip/blob/ccd75d4daf7753b6587cffbb1ba52e7dfa5e9915/pip/locations.py#L41-L51
32
+ USER_OPTS=" "
33
+ if python -c ' import sys; sys.exit(hasattr(sys, "real_prefix"))' ||
34
+ python -c ' import sys; sys.exit(sys.prefix != getattr(sys, "base_prefix", sys.prefix))'
35
+ then
36
+ USER_OPTS=" --user"
37
+ fi
38
+
16
39
# First generate release files to ~/dist
17
40
virtualenv .venv
18
41
source .venv/bin/activate
@@ -25,13 +48,18 @@ rm -r .venv
25
48
26
49
# Install from source
27
50
mkdir ~ /userbase
28
- PYTHONUSERBASE=~ /userbase python setup.py install --user
29
- PYTHONUSERBASE=~ /userbase PATH=" $HOME /userbase/bin:$PATH " compdb version
51
+ env PYTHONPATH=$( PYTHONUSERBASE=~ /userbase python -m site --user-site) \
52
+ PYTHONUSERBASE=~ /userbase \
53
+ python setup.py install --user
54
+ env PYTHONPATH=$( PYTHONUSERBASE=~ /userbase python -m site --user-site) \
55
+ PYTHONUSERBASE=~ /userbase \
56
+ PATH=" $HOME /userbase/bin:$PATH " \
57
+ compdb version
30
58
rm -r ~ /userbase
31
59
32
60
# Install from source with pip
33
61
mkdir ~ /userbase
34
- PYTHONUSERBASE=~ /userbase pip install --user .
62
+ PYTHONUSERBASE=~ /userbase pip install ${USER_OPTS} .
35
63
PYTHONUSERBASE=~ /userbase PATH=" $HOME /userbase/bin:$PATH " compdb version
36
64
rm -r ~ /userbase
37
65
@@ -48,7 +76,7 @@ rm -r .venv
48
76
49
77
# Wheel
50
78
mkdir ~ /userbase
51
- PYTHONUSERBASE=~ /userbase pip install --user ~ /dist/compdb-* .whl
79
+ PYTHONUSERBASE=~ /userbase pip install ${USER_OPTS} ~ /dist/compdb-* .whl
52
80
PYTHONUSERBASE=~ /userbase PATH=" $HOME /userbase/bin:$PATH " compdb version
53
81
rm -r ~ /userbase
54
82
@@ -66,7 +94,7 @@ rm -r .venv
66
94
67
95
# pip install source distribution
68
96
mkdir ~ /userbase
69
- PYTHONUSERBASE=~ /userbase pip install --user ~ /dist/compdb-* .tar.gz
97
+ PYTHONUSERBASE=~ /userbase pip install ${USER_OPTS} ~ /dist/compdb-* .tar.gz
70
98
PYTHONUSERBASE=~ /userbase PATH=" $HOME /userbase/bin:$PATH " compdb version
71
99
rm -r ~ /userbase
72
100
0 commit comments