Skip to content

Commit d231662

Browse files
authored
Fix: Handle case where Python version is already installed (#222) (#1115)
* Fix: Handle case where Python version is already installed in dev container (#617) * Incorporated Review Comment: Version exist handling
1 parent 68871f5 commit d231662

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

src/python/install.sh

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -465,16 +465,18 @@ install_prev_vers_cpython() {
465465
install_cpython() {
466466
VERSION=$1
467467
INSTALL_PATH="${PYTHON_INSTALL_PATH}/${VERSION}"
468+
469+
# Check if the specified Python version is already installed
468470
if [ -d "${INSTALL_PATH}" ]; then
469471
echo "(!) Python version ${VERSION} already exists."
470-
exit 1
472+
else
473+
mkdir -p /tmp/python-src ${INSTALL_PATH}
474+
cd /tmp/python-src
475+
cpython_tgz_filename="Python-${VERSION}.tgz"
476+
cpython_tgz_url="https://www.python.org/ftp/python/${VERSION}/${cpython_tgz_filename}"
477+
echo "Downloading ${cpython_tgz_filename}..."
478+
curl -sSL -o "/tmp/python-src/${cpython_tgz_filename}" "${cpython_tgz_url}"
471479
fi
472-
mkdir -p /tmp/python-src ${INSTALL_PATH}
473-
cd /tmp/python-src
474-
cpython_tgz_filename="Python-${VERSION}.tgz"
475-
cpython_tgz_url="https://www.python.org/ftp/python/${VERSION}/${cpython_tgz_filename}"
476-
echo "Downloading ${cpython_tgz_filename}..."
477-
curl -sSL -o "/tmp/python-src/${cpython_tgz_filename}" "${cpython_tgz_url}"
478480
}
479481

480482
install_from_source() {
@@ -560,20 +562,20 @@ install_using_oryx() {
560562
VERSION=$1
561563
INSTALL_PATH="${PYTHON_INSTALL_PATH}/${VERSION}"
562564

565+
# Check if the specified Python version is already installed
563566
if [ -d "${INSTALL_PATH}" ]; then
564567
echo "(!) Python version ${VERSION} already exists."
565-
exit 1
566-
fi
567-
568-
# The python install root path may not exist, so create it
569-
mkdir -p "${PYTHON_INSTALL_PATH}"
570-
oryx_install "python" "${VERSION}" "${INSTALL_PATH}" "lib" || return 1
568+
else
569+
# The python install root path may not exist, so create it
570+
mkdir -p "${PYTHON_INSTALL_PATH}"
571+
oryx_install "python" "${VERSION}" "${INSTALL_PATH}" "lib" || return 1
571572

572-
ln -s "${INSTALL_PATH}/bin/idle3" "${INSTALL_PATH}/bin/idle"
573-
ln -s "${INSTALL_PATH}/bin/pydoc3" "${INSTALL_PATH}/bin/pydoc"
574-
ln -s "${INSTALL_PATH}/bin/python3-config" "${INSTALL_PATH}/bin/python-config"
573+
ln -s "${INSTALL_PATH}/bin/idle3" "${INSTALL_PATH}/bin/idle"
574+
ln -s "${INSTALL_PATH}/bin/pydoc3" "${INSTALL_PATH}/bin/pydoc"
575+
ln -s "${INSTALL_PATH}/bin/python3-config" "${INSTALL_PATH}/bin/python-config"
575576

576-
add_symlink
577+
add_symlink
578+
fi
577579
}
578580

579581
sudo_if() {

0 commit comments

Comments
 (0)