Skip to content

Commit cd384e2

Browse files
authored
fix use configured Python in pullLicenses script (#38162)
* fix use configured Python in pullLicenses script * bootstrap pip in pullLicenses when venv has no ensurepip
1 parent d89dcac commit cd384e2

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

sdks/java/container/license_scripts/license_script.sh

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ set -e
1818

1919
# Get currently used Python version from Gradle or assume a default.
2020
PYTHON=${1:-python3}
21+
if ! command -v "${PYTHON}" >/dev/null 2>&1; then
22+
if command -v python3 >/dev/null 2>&1; then
23+
PYTHON=python3
24+
else
25+
PYTHON=python
26+
fi
27+
fi
2128
SCRIPT_DIR="${PWD}/license_scripts"
2229
ENV_DIR="${PWD}/build/virtualenv"
2330

@@ -39,8 +46,19 @@ echo "Copying already-fetched licenses from ${EXISTING_LICENSE_DIR} to ${DOWNLOA
3946
if [ -d "$DOWNLOAD_DIR" ]; then rm -rf "$DOWNLOAD_DIR" ; fi
4047
mkdir -p "$DOWNLOAD_DIR"
4148
cp -r "${EXISTING_LICENSE_DIR}"/*.jar "${DOWNLOAD_DIR}"
42-
python -m venv --clear ${ENV_DIR} --without-pip --system-site-packages
49+
${PYTHON} -m venv --clear ${ENV_DIR} --without-pip --system-site-packages
4350
. ${ENV_DIR}/bin/activate
51+
if ! python -m pip --version >/dev/null 2>&1; then
52+
GET_PIP_URL="https://bootstrap.pypa.io/get-pip.py"
53+
if command -v curl >/dev/null 2>&1; then
54+
curl -sSL "$GET_PIP_URL" | python
55+
elif command -v wget >/dev/null 2>&1; then
56+
wget -qO- "$GET_PIP_URL" | python
57+
else
58+
echo "Neither curl nor wget found; cannot bootstrap pip"
59+
exit 1
60+
fi
61+
fi
4462
python -m pip install --retries 10 --upgrade pip setuptools wheel
4563

4664
# install packages

0 commit comments

Comments
 (0)