Skip to content

Commit e37918a

Browse files
committed
Verify a valid HTTP client tool exists prior to installing Python
On Linux, Python installation requires that the Python code be downloaded. In order to download Python, pyenv uses one of aria2c, curl, and wget. When none of these is found, it fails to download Python. This commit ensures that python_installer fast-fails so that unnecessary activities such as cloning the pyenv repository need not happen when a valid HTTP client tool is not found.
1 parent abfeacd commit e37918a

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

scripts/python_installer

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ function echo_with_indentation() {
6464
echo -e " $message"
6565
}
6666

67+
function echo_error_message () {
68+
local message=$1
69+
echo_with_indentation "\033[38;5;9m$message\033[0m"
70+
}
71+
6772
function echo_recommendation_message() {
6873
local message=$1
6974
echo_with_indentation "\033[38;5;11m$message\033[0m"
@@ -146,6 +151,20 @@ function export_pyenv_and_pyenv_repository_paths() {
146151
export PATH="$PYENV_ROOT/bin:$PYENV_REPOSITORY_LOCATION/bin:$PATH"
147152
}
148153

154+
function verify_http_client_exists() {
155+
if type curl &>/dev/null; then
156+
return
157+
elif type aria2c &>/dev/null; then
158+
return
159+
elif [[ "$(wget --version 2>/dev/null || true)" = "GNU Wget 1.1"[0-3]* ]]; then
160+
echo_error_message "wget (>= 1.14) or curl (>= 7.18.1) is required to download and install Python."
161+
exit 1
162+
else
163+
echo_error_message "Could not find \`curl\`, \`wget\`, or \`aria2c\`. Please install one of these tools to continue Python installation"
164+
exit 1
165+
fi
166+
}
167+
149168
function main() {
150169
echo_step_title "Determining whether pyenv is already installed and in PATH"
151170

@@ -161,6 +180,9 @@ function main() {
161180
echo_step_title "Temporarily export necessary pyenv paths"
162181
export_pyenv_and_pyenv_repository_paths
163182

183+
echo_step_title "Checking whether Python can be downloaded (through curl, wget, or aria2c)"
184+
verify_http_client_exists
185+
164186
echo_step_title "Installing Python $PYTHON_VERSION"
165187
install_python
166188

0 commit comments

Comments
 (0)