install_rally.sh: Get latest pypi links more robustly

This parses the JSON from PyPI with a real JSON parser rather than
trying to parse the HTML with shell tools, which should be more
failsafe going forward.

Change-Id: I3d2476428bc6da3a0b11a38e4fdd12c2d64272f4
This commit is contained in:
Chris St. Pierre 2016-05-05 09:19:16 -05:00
parent a7ea4dc9fe
commit 3e60ab567d

View File

@ -273,26 +273,26 @@ download() {
wget -nv $VERBOSE --no-check-certificate -O "$@"; wget -nv $VERBOSE --no-check-certificate -O "$@";
} }
download_from_pypi () { download_setuptools () {
local pkg=$1 local url
# NOTE(stpierre): This (admittedly ugly) one-liner parses the JSON
# returned from pypi and fetches the URL for the latest version of
# the source (i.e., .tar.gz) package. It's safe here to look for
# the .tar.gz explicitly (rather than matching on package type ==
# source) because we untar it later anyway.
url=$(python -c '
import json
import urllib2
# NOTE(amaretskiy): get packages list in HTML print [u["url"]
local packages=$(download - "${BASE_PIP_URL}/${pkg}/") for u in json.load(urllib2.urlopen("http://pypi.python.org/pypi/setuptools/json/"))["urls"]
if u["filename"].endswith(".tar.gz")].pop()')
# NOTE(amaretskiy): filter packages URLs
packages=$(echo ${packages} | sed -En "s/.*href=\"(.*${pkg}-.*\\.gz)\#.*/\1/p")
# NOTE(amaretskiy): sort packages URLs by their version part
packages=$(echo ${packages} | sort -t / -k 7 -V)
# NOTE(amaretskiy): finally, the URL is in the last line
local url=$(echo ${packages} | tail -1)
if [ -n "$url" ]; then if [ -n "$url" ]; then
download "$(basename "$url")" "$BASE_PIP_URL"/"$pkg"/"$url" download "$(basename "$url")" "$url"
else else
die $EX_PROTOCOL "Package '$pkg' not found on PyPI!" <<__EOF__ die $EX_PROTOCOL "Setuptools not found on PyPI!" <<__EOF__
Unable to download package '$pkg' from PyPI. Unable to download package 'setuptools' from PyPI.
__EOF__ __EOF__
fi fi
} }
@ -446,7 +446,7 @@ __EOF__
# Wheel installs require setuptools >= 0.8 for dist-info support. # Wheel installs require setuptools >= 0.8 for dist-info support.
# #
if pip wheel --help 1>/dev/null 2>/dev/null; then if pip wheel --help 1>/dev/null 2>/dev/null; then
(cd "$DESTDIR" && download_from_pypi setuptools) (cd "$DESTDIR" && download_setuptools)
# setup.py must be called with `python', which will be the # setup.py must be called with `python', which will be the
# python executable inside the virtualenv, not `$PYTHON', # python executable inside the virtualenv, not `$PYTHON',
# which is the system python. # which is the system python.