Skip to content

Commit

Permalink
fix: preserve the pip py runner
Browse files Browse the repository at this point in the history
  • Loading branch information
autumnjolitz committed Oct 7, 2024
1 parent 35df05f commit 707b55f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Dockerfile.alpine
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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/ \
Expand Down
10 changes: 10 additions & 0 deletions remove-py-if-pyc-exists.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 707b55f

Please sign in to comment.