FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

ensure pip is installed and upgraded · Python-Repository-Hub/voltron@be11fbf · GitHub

Commit be11fbf

Browse files
committed
ensure pip is installed and upgraded
1 parent 4fcdedf commit be11fbf

1 file changed

Lines changed: 42 additions & 6 deletions

File tree

‎install.sh‎

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ YUM_DNF=$(command -v dnf)
3434
USER_MODE='--user'
3535
SUDO=''
3636

37+
#Old versions of pip default to pypi.python.org and fail to install anything
38+
PYPI_URL="https://pypi.org/simple"
39+
PIP_MIN_VER="10.0"
40+
PIP_BOOTSTRAP_URL="https://bootstrap.pypa.io/get-pip.py"
41+
3742
[[ -z "${GDB}" ]]
3843
BACKEND_GDB=$?
3944
[[ -z "${LLDB}" ]]
@@ -140,6 +145,36 @@ function install_packages {
140145
install_yum
141146
}
142147

148+
function curl_get_pip {
149+
echo "Attempting to curl pip bootstrapt script from $PIP_BOOTSTRAP_URL"
150+
curl "$PIP_BOOTSTRAP_URL" | ${SUDO} ${LLDB_PYTHON} - --upgrade "$USER_MODE" || return $?
151+
}
152+
153+
function ensure_pip {
154+
# Check if pip is installed already
155+
${LLDB_PYTHON} -m pip --version >/dev/null 2>&1
156+
if [ $? -ne 0 ];
157+
then
158+
# If not, attempt to install it using ensurepip
159+
echo "Attempting to install pip using 'ensurepip'."
160+
${SUDO} ${LLDB_PYTHON} -m ensurepip $USER_MODE || return $?
161+
fi
162+
# Some really old pip installations default to the old pypi.python.org, which no longer works.
163+
echo "Attempting to upgrade pip."
164+
${SUDO} ${LLDB_PYTHON} -m pip install "pip>=$PIP_MIN_VER" $USER_MODE -U --index-url "$PYPI_URL"
165+
if [ $? != 0 ];
166+
then
167+
# We may still fail here due to TLS incompatibility
168+
# TLS 1.x got turned off 2018-04-11
169+
# https://status.python.org/incidents/hdx7w97m5hr8
170+
# Curl may be new enough to support TLS 1.2, so try to curl the pip installer from pypa.io
171+
# It's able to download and install pip without TLS errors somehow
172+
echo "Failed to upgrade pip."
173+
echo "Attempting to fall back to installation via curl."
174+
curl_get_pip || return $?
175+
fi
176+
}
177+
143178
function get_lldb_python_exe {
144179
# Find the Python version used by LLDB
145180
local lldb_pyver=$(${LLDB} -Q -x -b --one-line 'script import platform; print(".".join(platform.python_version_tuple()[:2]))'|tail -1)
@@ -196,8 +231,9 @@ fi
196231

197232
if [ "${BACKEND_LLDB}" -eq 1 ]; then
198233

199-
LLDB_PYTHON=$(get_lldb_python_exe)
200-
${LLDB_PYTHON} -m pip install --user --upgrade six
234+
LLDB_PYTHON=$(get_lldb_python_exe) || quit "Failed to locate python interpreter." 1
235+
ensure_pip || quit "Failed to install pip." 1
236+
${LLDB_PYTHON} -m pip install --user --upgrade six || quit "Failed to install or upgrade 'six' python package." 1
201237

202238
if [ -n "${VENV}" ]; then
203239
echo "Creating virtualenv..."
@@ -206,18 +242,18 @@ if [ "${BACKEND_LLDB}" -eq 1 ]; then
206242
LLDB_PYTHON="${VENV}/bin/python"
207243
LLDB_SITE_PACKAGES=$(find "${VENV}" -name site-packages)
208244
elif [ -z "${USER_MODE}" ]; then
209-
LLDB_SITE_PACKAGES=$(${LLDB} -Q -x -b --one-line 'script import site; print(site.getsitepackages()[0])'|tail -1)
245+
LLDB_SITE_PACKAGES=$(${LLDB} -Q -x -b --one-line 'script import site; print(site.getsitepackages()[0])'|tail -1) || quit "Failed to locate site-packages." 1
210246
else
211-
LLDB_SITE_PACKAGES=$(${LLDB} -Q -x -b --one-line 'script import site; print(site.getusersitepackages())'|tail -1)
247+
LLDB_SITE_PACKAGES=$(${LLDB} -Q -x -b --one-line 'script import site; print(site.getusersitepackages())'|tail -1) || quit "Failed to locate site-packages." 1
212248
fi
213249

214-
install_packages
250+
install_packages || quit "Failed to install packages." 1
215251

216252
if [ "$LLDB_SITE_PACKAGES" == "$GDB_SITE_PACKAGES" ]; then
217253
echo "Skipping installation for LLDB - same site-packages directory"
218254
else
219255
# Install Voltron and dependencies
220-
${SUDO} ${LLDB_PYTHON} -m pip install -U $USER_MODE $DEV_MODE .
256+
${SUDO} ${LLDB_PYTHON} -m pip install -U $USER_MODE $DEV_MODE . || quit "Failed to install voltron." 1
221257
fi
222258

223259
# Add Voltron to lldbinit

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL