This commit is contained in:
2026-02-14 20:00:37 +08:00
parent 45be8dc7c8
commit bc660d97a5
10 changed files with 1 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
{
"id": "patch-python",
"name": "Patch Python Packages",
"installsAfter": ["ghcr.io/devcontainers/features/python"]
}

View File

@@ -0,0 +1,46 @@
#!/usr/bin/env bash
#-------------------------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
#-------------------------------------------------------------------------------------------------------------
USERNAME=${USERNAME:-"codespace"}
set -eux
if [ "$(id -u)" -ne 0 ]; then
echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.'
exit 1
fi
# Ensure that login shells get the correct path if the user updated the PATH using ENV.
rm -f /etc/profile.d/00-restore-env.sh
echo "export PATH=${PATH//$(sh -lc 'echo $PATH')/\$PATH}" > /etc/profile.d/00-restore-env.sh
chmod +x /etc/profile.d/00-restore-env.sh
export DEBIAN_FRONTEND=noninteractive
sudo_if() {
COMMAND="$*"
if [ "$(id -u)" -eq 0 ] && [ "$USERNAME" != "root" ]; then
su - "$USERNAME" -c "$COMMAND"
else
"$COMMAND"
fi
}
update_package() {
PYTHON_PATH=$1
PACKAGE=$2
VERSION=$3
sudo_if "$PYTHON_PATH -m pip uninstall --yes $PACKAGE"
sudo_if "$PYTHON_PATH -m pip install --upgrade --no-cache-dir $PACKAGE==$VERSION"
sudo_if "$PYTHON_PATH -m pip show --no-python-version-warning $PACKAGE"
}
# Updating pip version for python 3.11. Must be removed when pinned version 3.11 is updated to a different python version.
sudo_if /usr/local/python/3.11.*/bin/python -m pip install --upgrade pip
# https://github.com/advisories/GHSA-5rjg-fvgr-3xxf
# Updating setuptools version for python 3.11. Must be removed when pinned version 3.11 is updated to a different python version.
update_package /usr/local/python/3.11.*/bin/python setuptools "78.1.1"