]> git.proxmox.com Git - ceph.git/blob - ceph/src/tools/setup-virtualenv.sh
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / tools / setup-virtualenv.sh
1 #!/usr/bin/env bash
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
18 SCRIPTNAME="$(basename $0)"
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
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
43 PYTHON_OPTION=""
44 while true ; do
45 case "$1" in
46 -h|--help) usage ;; # does not return
47 --python) PYTHON_OPTION="--python=$2" ; shift ; shift ;;
48 --) shift ; break ;;
49 *) echo "Internal error" ; exit 1 ;;
50 esac
51 done
52
53 DIR=$1
54 if [ -z "$DIR" ] ; then
55 echo "$SCRIPTNAME: need a directory path, but none was provided"
56 usage
57 fi
58 rm -fr $DIR
59 mkdir -p $DIR
60 virtualenv $PYTHON_OPTION $DIR
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
83 pip $DISABLE_PIP_VERSION_CHECK --log $DIR/log.txt install $NO_INDEX --find-links=file://$(pwd)/wheelhouse 'tox >=2.9.1'
84 if test -f requirements.txt ; then
85 if ! test -f wheelhouse/md5 || ! md5sum -c wheelhouse/md5 > /dev/null; then
86 NO_INDEX=''
87 fi
88 pip $DISABLE_PIP_VERSION_CHECK --log $DIR/log.txt install $NO_INDEX --find-links=file://$(pwd)/wheelhouse -r requirements.txt
89 fi