Skip to content

Commit

Permalink
feature: add chroot-pip helper
Browse files Browse the repository at this point in the history
  • Loading branch information
autumnjolitz committed Oct 8, 2024
1 parent d5c4f86 commit 5a9dc97
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
1 change: 1 addition & 0 deletions 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 chroot-pip.sh /usr/local/bin/chroot-pip
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 ; \
Expand Down
29 changes: 29 additions & 0 deletions chroot-pip.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env sh

if [ "x$CACHE_ROOT" = 'x' ] || [ "x$BUILD_ROOT" = 'x' ]; then
>&2 echo "CACHE_ROOT (${CACHE_ROOT:-not-set}) and/or BUILD_ROOT (${BUILD_ROOT:-not-set}) is not set!"
exit 1
fi

set -e
set -o pipefail

setup () {
return 0
}

fini () {
python -m compileall -b $BUILD_ROOT/usr/local/lib/python$PYTHON_VERSION/site-packages
export ALLOW_SITE_PACKAGES=1
find $BUILD_ROOT/usr/local/lib/python$PYTHON_VERSION/site-packages \
-type f -name '*.py' -exec sh -c "remove-py-if-pyc-exists {}" \; ;\
return $?
}

trap fini EXIT
setup
export PYTHONPATH=$BUILD_ROOT/usr/local/lib/python$PYTHON_VERSION/site-packages
export PIP_PREFIX=$BUILD_ROOT/usr/local

set -x
python -m pip $@
4 changes: 3 additions & 1 deletion remove-py-if-pyc-exists.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#!/usr/bin/env sh

ALLOW_SITE_PACKAGES=${ALLOW_SITE_PACKAGES:-0}

if [ -f "${1}c" ]; then
if ! case "$1" in *site-packages/*) false ;; *) true ;; esac ; then
if [ "x$ALLOW_SITE_PACKAGES" = 'x0' ] && ! case "$1" in *site-packages/*) false ;; *) true ;; esac ; then
echo 'Skipping optimization of '"$1"
exit 0
fi
Expand Down

0 comments on commit 5a9dc97

Please sign in to comment.