blob: 7b42c8c485f92c2a53b22099fdadd38cc7bfdfbc [file] [log] [blame]
Dean Troyer62d1d692013-08-01 17:40:40 -05001#!/usr/bin/env bash
2
3# **install_pip.sh**
4
Monty Taylordace92f2013-08-10 23:49:47 -03005# install_pip.sh [--pip-version <version>] [--use-get-pip] [--force]
Dean Troyer62d1d692013-08-01 17:40:40 -05006#
7# Update pip and friends to a known common version
8
9# Assumptions:
Dean Troyer62d1d692013-08-01 17:40:40 -050010# - update pip to $INSTALL_PIP_VERSION
11
Adam Spiersc85ade72013-10-01 00:35:16 +010012set -o errexit
13set -o xtrace
14
Dean Troyer62d1d692013-08-01 17:40:40 -050015# Keep track of the current directory
16TOOLS_DIR=$(cd $(dirname "$0") && pwd)
17TOP_DIR=`cd $TOOLS_DIR/..; pwd`
18
Dean Troyerdc97cb72015-03-28 08:20:50 -050019# Change dir to top of DevStack
Dean Troyer62d1d692013-08-01 17:40:40 -050020cd $TOP_DIR
21
22# Import common functions
Clark Boylan05aa3842015-08-03 11:14:13 -070023source $TOP_DIR/stackrc
Dean Troyer62d1d692013-08-01 17:40:40 -050024
25FILES=$TOP_DIR/files
26
Sean Dague7b63c5e2014-06-04 16:25:52 -040027PIP_GET_PIP_URL=https://bootstrap.pypa.io/get-pip.py
Sean Daguef625ffe2014-06-05 07:04:41 -040028LOCAL_PIP="$FILES/$(basename $PIP_GET_PIP_URL)"
Dean Troyer62d1d692013-08-01 17:40:40 -050029
30GetDistro
31echo "Distro: $DISTRO"
32
Ian Wienandaee18c72014-02-21 15:35:08 +110033function get_versions {
Attila Fazekas46ea7232013-10-07 07:29:27 +020034 PIP=$(which pip 2>/dev/null || which pip-python 2>/dev/null || true)
Dean Troyer62d1d692013-08-01 17:40:40 -050035 if [[ -n $PIP ]]; then
Dean Troyer62d1d692013-08-01 17:40:40 -050036 PIP_VERSION=$($PIP --version | awk '{ print $2}')
Monty Taylordace92f2013-08-10 23:49:47 -030037 echo "pip: $PIP_VERSION"
Attila Fazekas46ea7232013-10-07 07:29:27 +020038 else
39 echo "pip: Not Installed"
Dean Troyer62d1d692013-08-01 17:40:40 -050040 fi
41}
42
Dean Troyer62d1d692013-08-01 17:40:40 -050043
Ian Wienandaee18c72014-02-21 15:35:08 +110044function install_get_pip {
Dean Troyerdc97cb72015-03-28 08:20:50 -050045 # The OpenStack gate and others put a cached version of get-pip.py
Ian Wienand7c4ce9e2015-03-10 11:32:26 +110046 # for this to find, explicitly to avoid download issues.
47 #
Dean Troyerdc97cb72015-03-28 08:20:50 -050048 # However, if DevStack *did* download the file, we want to check
49 # for updates; people can leave their stacks around for a long
Ian Wienand7c4ce9e2015-03-10 11:32:26 +110050 # time and in the mean-time pip might get upgraded.
51 #
52 # Thus we use curl's "-z" feature to always check the modified
53 # since and only download if a new version is out -- but only if
54 # it seems we downloaded the file originally.
55 if [[ ! -r $LOCAL_PIP || -r $LOCAL_PIP.downloaded ]]; then
56 curl --retry 6 --retry-delay 5 \
57 -z $LOCAL_PIP -o $LOCAL_PIP $PIP_GET_PIP_URL || \
Sean Daguef625ffe2014-06-05 07:04:41 -040058 die $LINENO "Download of get-pip.py failed"
Ian Wienand7c4ce9e2015-03-10 11:32:26 +110059 touch $LOCAL_PIP.downloaded
Dean Troyer62d1d692013-08-01 17:40:40 -050060 fi
Adam Gandelman130efef2014-12-27 14:01:00 -080061 sudo -H -E python $LOCAL_PIP
Dean Troyer62d1d692013-08-01 17:40:40 -050062}
63
Dean Troyer62d1d692013-08-01 17:40:40 -050064
Franck Yelles683ff422014-06-19 02:14:42 -070065function configure_pypi_alternative_url {
66 PIP_ROOT_FOLDER="$HOME/.pip"
67 PIP_CONFIG_FILE="$PIP_ROOT_FOLDER/pip.conf"
68 if [[ ! -d $PIP_ROOT_FOLDER ]]; then
69 echo "Creating $PIP_ROOT_FOLDER"
70 mkdir $PIP_ROOT_FOLDER
71 fi
72 if [[ ! -f $PIP_CONFIG_FILE ]]; then
73 echo "Creating $PIP_CONFIG_FILE"
74 touch $PIP_CONFIG_FILE
75 fi
76 if ! ini_has_option "$PIP_CONFIG_FILE" "global" "index-url"; then
Dean Troyerdc97cb72015-03-28 08:20:50 -050077 # It means that the index-url does not exist
Franck Yelles683ff422014-06-19 02:14:42 -070078 iniset "$PIP_CONFIG_FILE" "global" "index-url" "$PYPI_OVERRIDE"
79 fi
80
81}
82
Jeremy Stanley35b52832014-12-18 17:27:22 +000083# Setuptools 8 implements PEP 440, and 8.0.4 adds a warning triggered any time
84# pkg_resources inspects the list of installed Python packages if there are
85# non-compliant version numbers in the egg-info (for example, from distro
86# system packaged Python libraries). This is off by default after 8.2 but can
87# be enabled by uncommenting the lines below.
88#PYTHONWARNINGS=$PYTHONWARNINGS,always::RuntimeWarning:pkg_resources
89#export PYTHONWARNINGS
Franck Yelles683ff422014-06-19 02:14:42 -070090
Dean Troyer62d1d692013-08-01 17:40:40 -050091# Show starting versions
92get_versions
93
Dean Troyer62d1d692013-08-01 17:40:40 -050094# Do pip
Dean Troyer62d1d692013-08-01 17:40:40 -050095
Monty Taylordace92f2013-08-10 23:49:47 -030096# Eradicate any and all system packages
97uninstall_package python-pip
Dean Troyer62d1d692013-08-01 17:40:40 -050098
Sean Dague7b63c5e2014-06-04 16:25:52 -040099install_get_pip
Monty Taylordace92f2013-08-10 23:49:47 -0300100
Franck Yelles683ff422014-06-19 02:14:42 -0700101if [[ -n $PYPI_ALTERNATIVE_URL ]]; then
102 configure_pypi_alternative_url
103fi
104
Jeremy Stanleyb7ebc472014-12-17 03:32:42 +0000105pip_install -U setuptools
Mathieu Gagné76ed4272014-06-05 16:50:40 -0400106
Monty Taylordace92f2013-08-10 23:49:47 -0300107get_versions