From 707b55fbdfe018f1e847544798c868de8f4e4d70 Mon Sep 17 00:00:00 2001 From: Autumn Jolitz Date: Mon, 7 Oct 2024 16:21:01 -0700 Subject: [PATCH] fix: preserve the pip py runner --- Dockerfile.alpine | 3 ++- remove-py-if-pyc-exists.sh | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 remove-py-if-pyc-exists.sh diff --git a/Dockerfile.alpine b/Dockerfile.alpine index ca159d8..55135b6 100644 --- a/Dockerfile.alpine +++ b/Dockerfile.alpine @@ -21,6 +21,7 @@ ENV BUILD_ROOT=$BUILD_ROOT \ _chroot="chroot $BUILD_ROOT" ADD --chmod=0755 chroot-apk.sh /usr/local/bin/chroot-apk +ADD --chmod=0755 remove-py-if-pyc-exists.sh /usr/local/bin/remove-py-if-pyc-exists RUN set -eu ; \ python -m pip install -U pip setuptools ; \ # Add to buildroot: @@ -38,7 +39,7 @@ RUN set -eu ; \ find /usr/local/lib/python$PYTHON_VERSION -type d -name '__pycache__' -print0 | xargs -0 rm -rf ; \ # compile all py to an adjacent pyc and remove the original, leaving only the bytecode python -m compileall -b /usr/local/lib/python$PYTHON_VERSION ; \ - find -type f -name '*.py' -exec sh -c "[ -f \"{}c\" ] && echo 'Removing \"{}\"' && rm -f \"{}\"" \; ;\ + find -type f -name '*.py' -exec sh -c "remove-py-if-pyc-exists {}" \; ;\ # make the new root: mkdir -p \ $CACHE_ROOT/ \ diff --git a/remove-py-if-pyc-exists.sh b/remove-py-if-pyc-exists.sh new file mode 100644 index 0000000..9bb66b1 --- /dev/null +++ b/remove-py-if-pyc-exists.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env sh + +if [ -f "${1}c" ]; then + if ! case "$1" in *site-packages/pip/__pip-*) false ;; *) true ;; esac ; then + echo 'Skipping optimization of '"$1" + exit 0 + fi + echo 'Removing '"${1}" + rm -f "${1}" +fi \ No newline at end of file