]>
Commit | Line | Data |
---|---|---|
11fdf7f2 | 1 | #!/usr/bin/env bash |
7c673cae FG |
2 | # |
3 | # Copyright (C) 2016 <contact@redhat.com> | |
4 | # | |
5 | # Author: Loic Dachary <loic@dachary.org> | |
6 | # | |
7 | # This program is free software; you can redistribute it and/or modify | |
8 | # it under the terms of the GNU Library Public License as published by | |
9 | # the Free Software Foundation; either version 2, or (at your option) | |
10 | # any later version. | |
11 | # | |
12 | # This program is distributed in the hope that it will be useful, | |
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | # GNU Library Public License for more details. | |
16 | # | |
17 | ||
11fdf7f2 | 18 | SCRIPTNAME="$(basename $0)" |
11fdf7f2 TL |
19 | if [ `uname` == FreeBSD ]; then |
20 | GETOPT="/usr/local/bin/getopt" | |
21 | else | |
22 | GETOPT=getopt | |
23 | fi | |
24 | ||
25 | function usage { | |
26 | echo | |
27 | echo "$SCRIPTNAME - automate setup of Python virtual environment" | |
28 | echo " (for use in building Ceph)" | |
29 | echo | |
30 | echo "Usage:" | |
31 | echo " $SCRIPTNAME [--python=PYTHON_BINARY] TARGET_DIRECTORY" | |
32 | echo | |
11fdf7f2 TL |
33 | echo " TARGET_DIRECTORY will be created if it doesn't exist," |
34 | echo " and completely destroyed and re-created if it does!" | |
35 | echo | |
36 | exit 1 | |
37 | } | |
38 | ||
39 | TEMP=$($GETOPT --options "h" --long "help,python:" --name "$SCRIPTNAME" -- "$@") | |
40 | test $? != 0 && usage | |
41 | eval set -- "$TEMP" | |
42 | ||
92f5a8d4 | 43 | PYTHON_OPTION="" |
11fdf7f2 TL |
44 | while true ; do |
45 | case "$1" in | |
46 | -h|--help) usage ;; # does not return | |
92f5a8d4 | 47 | --python) PYTHON_OPTION="--python=$2" ; shift ; shift ;; |
11fdf7f2 TL |
48 | --) shift ; break ;; |
49 | *) echo "Internal error" ; exit 1 ;; | |
50 | esac | |
51 | done | |
52 | ||
7c673cae | 53 | DIR=$1 |
11fdf7f2 TL |
54 | if [ -z "$DIR" ] ; then |
55 | echo "$SCRIPTNAME: need a directory path, but none was provided" | |
56 | usage | |
57 | fi | |
7c673cae FG |
58 | rm -fr $DIR |
59 | mkdir -p $DIR | |
92f5a8d4 | 60 | virtualenv $PYTHON_OPTION $DIR |
7c673cae FG |
61 | . $DIR/bin/activate |
62 | ||
63 | if pip --help | grep -q disable-pip-version-check; then | |
64 | DISABLE_PIP_VERSION_CHECK=--disable-pip-version-check | |
65 | else | |
66 | DISABLE_PIP_VERSION_CHECK= | |
67 | fi | |
68 | ||
69 | # older versions of pip will not install wrap_console scripts | |
70 | # when using wheel packages | |
71 | pip $DISABLE_PIP_VERSION_CHECK --log $DIR/log.txt install --upgrade 'pip >= 6.1' | |
72 | ||
73 | if pip --help | grep -q disable-pip-version-check; then | |
74 | DISABLE_PIP_VERSION_CHECK=--disable-pip-version-check | |
75 | else | |
76 | DISABLE_PIP_VERSION_CHECK= | |
77 | fi | |
78 | ||
79 | if test -d wheelhouse ; then | |
80 | export NO_INDEX=--no-index | |
81 | fi | |
82 | ||
11fdf7f2 | 83 | pip $DISABLE_PIP_VERSION_CHECK --log $DIR/log.txt install $NO_INDEX --find-links=file://$(pwd)/wheelhouse 'tox >=2.9.1' |
7c673cae | 84 | if test -f requirements.txt ; then |
11fdf7f2 TL |
85 | if ! test -f wheelhouse/md5 || ! md5sum -c wheelhouse/md5 > /dev/null; then |
86 | NO_INDEX='' | |
87 | fi | |
94b18763 | 88 | pip $DISABLE_PIP_VERSION_CHECK --log $DIR/log.txt install $NO_INDEX --find-links=file://$(pwd)/wheelhouse -r requirements.txt |
7c673cae | 89 | fi |