Skip to content

Commit 799c717

Browse files
committed
Changing the auto-install method.
1 parent eefdc06 commit 799c717

File tree

6 files changed

+74
-70
lines changed

6 files changed

+74
-70
lines changed

.travis-setup.sh

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ ls -l /dev/shm
1010
sudo apt-get update --fix-missing
1111

1212
# Install python-imaging from the environment rather then build it.
13-
# If the below fails, pip will build it via the .requirements
13+
# If the below fails, pip will build it via the requirements.txt
1414
sudo apt-get install python-imaging
1515
VIRTUAL_ENV_site_packages=$(echo $VIRTUAL_ENV/lib/*/site-packages)
1616
VIRTUAL_ENV_python_version=$(echo $VIRTUAL_ENV_site_packages | sed -e's@.*/\(.*\)/site-packages@\1@')
@@ -52,4 +52,5 @@ Firefox)
5252
;;
5353
esac
5454

55-
pip install -r .requirements --use-mirrors || pip install -r .requirements
55+
R=tools/python/requirements.txt
56+
pip install -r $R --use-mirrors || pip install -r $R

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ script:
3434
- if [ x$BROWSER == "xRemote" -a x$SAUCE_ACCESS_KEY == "x" ]; then
3535
true;
3636
else
37-
echo python run-tests.py -a $ARGS | bash;
37+
echo ./run-tests.sh $ARGS | bash;
3838
fi
3939

4040
after_failure:

run-tests.sh

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#! /bin/bash
2+
3+
# Update git submodules
4+
git submodule init
5+
git submodule update
6+
7+
# If already in a VIRTUAL_ENV assume the person knows what they are doing,
8+
# otherwise set up a python virtualenv with all the needed requirements.
9+
if [ x$VIRTUAL_ENV == x"" ]; then
10+
cd tools/python
11+
source setup.sh
12+
cd ../..
13+
fi
14+
15+
exec python tools/python/run-tests.py $@
File renamed without changes.

run-tests.py tools/python/run-tests.py

-67
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@
3232
"-d", "--dontexit", action='store_true', default=False,
3333
help="At end of testing, don't exit.")
3434

35-
parser.add_argument(
36-
"-a", "--auto-install", action='store_true', default=True,
37-
help="Auto install any dependencies.")
38-
3935
parser.add_argument(
4036
"-v", "--verbose", action='store_true', default=False,
4137
help="Output more information.")
@@ -84,69 +80,6 @@
8480

8581
import subprocess
8682

87-
# Set up the git repository
88-
if args.auto_install:
89-
subprocess.check_call(["git", "submodule", "init"])
90-
subprocess.check_call(["git", "submodule", "update"])
91-
92-
93-
# Install the python modules
94-
def autoinstall(name, package=None):
95-
if not package:
96-
package = name
97-
98-
if args.auto_install:
99-
try:
100-
import pip
101-
except ImportError:
102-
raise SystemExit("""\
103-
Can not autoinstall as PIP is not avaliable.
104-
105-
To install 'pip' please ask your administrator to install the package
106-
'python-pip' or run:
107-
# sudo apt-get install python-pip
108-
""")
109-
110-
from pip.req import InstallRequirement
111-
install = InstallRequirement(package, None)
112-
install.check_if_exists()
113-
114-
if install.satisfied_by is None:
115-
print "Unable to find %s, autoinstalling" % (name,)
116-
117-
if install.conflicts_with:
118-
raise SystemExit("""
119-
Can't install %s because it conflicts with already installed %s.
120-
121-
Please try installing %s manually with:
122-
# sudo pip install --upgrade %s
123-
""" % (name, install.conflicts_with, name, package.replace(">", "\>")))
124-
125-
ret = subprocess.call(["pip", "install", "--user", package])
126-
if ret == 0: # UNKNOWN_ERROR
127-
# Restart python is a nasty way, only method to get imports to
128-
# refresh.
129-
python = sys.executable
130-
os.execl(python, python, *sys.argv)
131-
else:
132-
raise SystemExit("""
133-
Unknown error occurred.
134-
135-
Please install the Python %s module.
136-
# sudo pip install %s
137-
""" % (name, package.replace(">", "\n")))
138-
139-
for line in file(".requirements").readlines():
140-
if line.startswith('#') or not line.strip():
141-
continue
142-
143-
if line.find('#') >= 0:
144-
package, name = line.split('#')
145-
146-
autoinstall(name.strip(), package.strip())
147-
else:
148-
autoinstall(line.strip())
149-
15083
if not args.sauce:
15184
# Get any selenium drivers we might need
15285
if args.browser == "Chrome":

tools/python/setup.sh

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#! /bin/bash
2+
3+
# Create the python environment needed by run-tests.py and closure-linter and
4+
# other Python tools.
5+
6+
OLD_PWD=$PWD
7+
8+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
9+
10+
cd $DIR
11+
if [ ! -f bin/activate ]; then
12+
echo "Setting up Python environment in $DIR"
13+
14+
if [ x$(which pip) == x -o x$(which virtualenv) == x ]; then
15+
cat <<EOF
16+
Can not autoinstall as pip and virtualenv are not avaliable.
17+
18+
To install 'pip' please do one of the following;
19+
20+
# sudo apt-get install python-pip python-virtualenv
21+
22+
or
23+
24+
# sudo easy_install pip
25+
# sudo pip install virtualenv
26+
EOF
27+
exit 1
28+
fi
29+
30+
if virtualenv --system-site-packages .; then
31+
echo -e;
32+
else
33+
cat <<EOF
34+
Was unable to set up the virtualenv environment. Please see output for errors.
35+
EOF
36+
exit 1
37+
fi
38+
fi
39+
40+
source bin/activate
41+
42+
# Check if the dependencies are installed
43+
pip install --no-download -r requirements.txt > /dev/null 2>&1
44+
if [ $? -ne 0 ]; then
45+
# Install dependencies
46+
pip install -r requirements.txt
47+
if [ $? -ne 0 ]; then
48+
cat <<EOF
49+
Unable to install the required dependencies. Please see error output above.
50+
EOF
51+
exit 1
52+
fi
53+
fi
54+
55+
cd $OLD_PWD

0 commit comments

Comments
 (0)