From 683ff42d3cac11dbd25ed82f4c419215c5c1f84f Mon Sep 17 00:00:00 2001 From: Franck Yelles Date: Thu, 19 Jun 2014 02:14:42 -0700 Subject: [PATCH] Support of an alternate pypi server Currently pip will get the package from the https://pypi.python.org server. For CI, it's a problem as Internet connection can be down, the pypi server down, etc... The usecase is for a company/user that maintain a local pypi mirror and give the option to use this server instead of the official one Change-Id: I83aac4646cb78827a92c9636d78238f8a6118642 Implements: blueprint support-local-pypi-server --- stack.sh | 2 +- tools/install_pip.sh | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/stack.sh b/stack.sh index bd99b5b752..51854cc25c 100755 --- a/stack.sh +++ b/stack.sh @@ -652,7 +652,7 @@ source $TOP_DIR/tools/install_prereqs.sh # Configure an appropriate python environment if [[ "$OFFLINE" != "True" ]]; then - $TOP_DIR/tools/install_pip.sh + PYPI_ALTERNATIVE_URL=$PYPI_ALTERNATIVE_URL $TOP_DIR/tools/install_pip.sh fi # Do the ugly hacks for borken packages and distros diff --git a/tools/install_pip.sh b/tools/install_pip.sh index 150faaa258..55ef93e44d 100755 --- a/tools/install_pip.sh +++ b/tools/install_pip.sh @@ -50,6 +50,25 @@ function install_get_pip { } +function configure_pypi_alternative_url { + PIP_ROOT_FOLDER="$HOME/.pip" + PIP_CONFIG_FILE="$PIP_ROOT_FOLDER/pip.conf" + if [[ ! -d $PIP_ROOT_FOLDER ]]; then + echo "Creating $PIP_ROOT_FOLDER" + mkdir $PIP_ROOT_FOLDER + fi + if [[ ! -f $PIP_CONFIG_FILE ]]; then + echo "Creating $PIP_CONFIG_FILE" + touch $PIP_CONFIG_FILE + fi + if ! ini_has_option "$PIP_CONFIG_FILE" "global" "index-url"; then + #it means that the index-url does not exist + iniset "$PIP_CONFIG_FILE" "global" "index-url" "$PYPI_OVERRIDE" + fi + +} + + # Show starting versions get_versions @@ -60,6 +79,10 @@ uninstall_package python-pip install_get_pip +if [[ -n $PYPI_ALTERNATIVE_URL ]]; then + configure_pypi_alternative_url +fi + pip_install -U setuptools get_versions