]> git.proxmox.com Git - ceph.git/blame - ceph/src/tools/setup-virtualenv.sh
import quincy beta 17.1.0
[ceph.git] / ceph / src / tools / setup-virtualenv.sh
CommitLineData
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 18SCRIPTNAME="$(basename $0)"
11fdf7f2
TL
19if [ `uname` == FreeBSD ]; then
20 GETOPT="/usr/local/bin/getopt"
21else
22 GETOPT=getopt
23fi
24
25function 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
39TEMP=$($GETOPT --options "h" --long "help,python:" --name "$SCRIPTNAME" -- "$@")
40test $? != 0 && usage
41eval set -- "$TEMP"
42
a4b75251 43PYTHON=python3
11fdf7f2
TL
44while true ; do
45 case "$1" in
46 -h|--help) usage ;; # does not return
a4b75251 47 --python) PYTHON="$2" ; shift ; shift ;;
11fdf7f2
TL
48 --) shift ; break ;;
49 *) echo "Internal error" ; exit 1 ;;
50 esac
51done
52
a4b75251
TL
53if ! $PYTHON -VV; then
54 echo "$SCRIPTNAME: unable to locate a valid PYTHON_BINARY"
55 usage
56fi
57
7c673cae 58DIR=$1
11fdf7f2
TL
59if [ -z "$DIR" ] ; then
60 echo "$SCRIPTNAME: need a directory path, but none was provided"
61 usage
62fi
7c673cae
FG
63rm -fr $DIR
64mkdir -p $DIR
a4b75251 65$PYTHON -m venv $DIR
7c673cae
FG
66. $DIR/bin/activate
67
68if pip --help | grep -q disable-pip-version-check; then
69 DISABLE_PIP_VERSION_CHECK=--disable-pip-version-check
70else
71 DISABLE_PIP_VERSION_CHECK=
72fi
73
74# older versions of pip will not install wrap_console scripts
75# when using wheel packages
76pip $DISABLE_PIP_VERSION_CHECK --log $DIR/log.txt install --upgrade 'pip >= 6.1'
77
78if pip --help | grep -q disable-pip-version-check; then
79 DISABLE_PIP_VERSION_CHECK=--disable-pip-version-check
80else
81 DISABLE_PIP_VERSION_CHECK=
82fi
83
84if test -d wheelhouse ; then
20effc67
TL
85 NO_INDEX=--no-index
86 FIND_LINKS_OPT=--find-links=file://$(pwd)/wheelhouse
7c673cae
FG
87fi
88
20effc67 89pip $DISABLE_PIP_VERSION_CHECK --log $DIR/log.txt install $NO_INDEX $FIND_LINKS_OPT 'tox >=2.9.1'
9f95a23c
TL
90
91require_files=$(ls *requirements*.txt 2>/dev/null) || true
92constraint_files=$(ls *constraints*.txt 2>/dev/null) || true
93require=$(echo -n "$require_files" | sed -e 's/^/-r /')
94constraint=$(echo -n "$constraint_files" | sed -e 's/^/-c /')
95md5=wheelhouse/md5
96if test "$require"; then
97 if ! test -f $md5 || ! md5sum -c wheelhouse/md5 > /dev/null; then
11fdf7f2 98 NO_INDEX=''
20effc67 99 FIND_LINKS_OPT=''
11fdf7f2 100 fi
20effc67
TL
101 pip --exists-action i $DISABLE_PIP_VERSION_CHECK --log $DIR/log.txt install \
102 $NO_INDEX $FIND_LINKS_OPT $require $constraint
7c673cae 103fi