From 3e60ab567d0b123cc47b4ee02af787d98d50c126 Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Thu, 5 May 2016 09:19:16 -0500 Subject: [PATCH] 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 --- install_rally.sh | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/install_rally.sh b/install_rally.sh index 1184816ee3..b428036916 100755 --- a/install_rally.sh +++ b/install_rally.sh @@ -273,26 +273,26 @@ download() { wget -nv $VERBOSE --no-check-certificate -O "$@"; } -download_from_pypi () { - local pkg=$1 +download_setuptools () { + 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 - local packages=$(download - "${BASE_PIP_URL}/${pkg}/") - - # 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) +print [u["url"] + for u in json.load(urllib2.urlopen("http://pypi.python.org/pypi/setuptools/json/"))["urls"] + if u["filename"].endswith(".tar.gz")].pop()') if [ -n "$url" ]; then - download "$(basename "$url")" "$BASE_PIP_URL"/"$pkg"/"$url" + download "$(basename "$url")" "$url" else - die $EX_PROTOCOL "Package '$pkg' not found on PyPI!" <<__EOF__ -Unable to download package '$pkg' from PyPI. + die $EX_PROTOCOL "Setuptools not found on PyPI!" <<__EOF__ +Unable to download package 'setuptools' from PyPI. __EOF__ fi } @@ -446,7 +446,7 @@ __EOF__ # Wheel installs require setuptools >= 0.8 for dist-info support. # 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 # python executable inside the virtualenv, not `$PYTHON', # which is the system python.