Browse code

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

Franck Yelles authored on 2014/06/19 18:14:42
Showing 2 changed files
... ...
@@ -652,7 +652,7 @@ source $TOP_DIR/tools/install_prereqs.sh
652 652
 
653 653
 # Configure an appropriate python environment
654 654
 if [[ "$OFFLINE" != "True" ]]; then
655
-    $TOP_DIR/tools/install_pip.sh
655
+    PYPI_ALTERNATIVE_URL=$PYPI_ALTERNATIVE_URL $TOP_DIR/tools/install_pip.sh
656 656
 fi
657 657
 
658 658
 # Do the ugly hacks for borken packages and distros
... ...
@@ -50,6 +50,25 @@ function install_get_pip {
50 50
 }
51 51
 
52 52
 
53
+function configure_pypi_alternative_url {
54
+    PIP_ROOT_FOLDER="$HOME/.pip"
55
+    PIP_CONFIG_FILE="$PIP_ROOT_FOLDER/pip.conf"
56
+    if [[ ! -d $PIP_ROOT_FOLDER ]]; then
57
+        echo "Creating $PIP_ROOT_FOLDER"
58
+        mkdir $PIP_ROOT_FOLDER
59
+    fi
60
+    if [[ ! -f $PIP_CONFIG_FILE ]]; then
61
+        echo "Creating $PIP_CONFIG_FILE"
62
+        touch $PIP_CONFIG_FILE
63
+    fi
64
+    if ! ini_has_option "$PIP_CONFIG_FILE" "global" "index-url"; then
65
+        #it means that the index-url does not exist
66
+        iniset "$PIP_CONFIG_FILE" "global" "index-url" "$PYPI_OVERRIDE"
67
+    fi
68
+
69
+}
70
+
71
+
53 72
 # Show starting versions
54 73
 get_versions
55 74
 
... ...
@@ -60,6 +79,10 @@ uninstall_package python-pip
60 60
 
61 61
 install_get_pip
62 62
 
63
+if [[ -n $PYPI_ALTERNATIVE_URL ]]; then
64
+    configure_pypi_alternative_url
65
+fi
66
+
63 67
 pip_install -U setuptools
64 68
 
65 69
 get_versions