From 489fc06e405ca8301d4f7a3e967572ceec93e24a Mon Sep 17 00:00:00 2001 From: psykose Date: Fri, 14 Apr 2023 06:31:50 +0000 Subject: [PATCH] abuild: prune python cache dirs by default these will be generated post-install in a hook. ref https://gitlab.alpinelinux.org/alpine/aports/-/issues/11906 --- abuild.in | 9 ++++++++ tests/abuild_test | 54 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/abuild.in b/abuild.in index aa69ea7..0d7fe84 100755 --- a/abuild.in +++ b/abuild.in @@ -790,6 +790,15 @@ postcheck() { find "$dir" -name '*.la' -type f -delete fi + # remove all python .pyc cache unless intentionally kept + if ! options_has "keeppycache"; then + # wildcard should always get the system python dir, and this is faster than + # trying to calculate the python version. + find "$dir"/usr/lib/python* \ + \( -type d -a -name "__pycache__" \) \ + -exec rm -r {} + + fi + # look for /usr/lib/charset.alias if [ -e "$dir"/usr/lib/charset.alias ] \ && ! options_has "charset.alias"; then diff --git a/tests/abuild_test b/tests/abuild_test index 3e30553..9f54466 100755 --- a/tests/abuild_test +++ b/tests/abuild_test @@ -33,7 +33,8 @@ init_tests \ abuild_devhelp \ abuild_check_maintainer \ abuild_cleanoldpkg \ - abuild_path_with_spaces + abuild_path_with_spaces \ + abuild_pycache export ABUILD_SHAREDIR=$(atf_get_srcdir)/.. export ABUILD_CONF=/dev/null @@ -824,3 +825,54 @@ abuild_path_with_spaces_body() { -e match:"Build complete" \ abuild } + +abuild_pycache_body() { + init_keys + + mkdir -p pycachetest + cd pycachetest + + cat >APKBUILD <<-EOF + # Maintainer: Joe User + pkgname="pycachetest" + pkgver="1.0" + pkgrel=0 + pkgdesc="Dummy test package" + url="https://gitlab.alpinelinux.org/alpine/aports" + arch="noarch" + license="MIT" + source="" + prepare() { + mkdir -p "\$builddir" + } + + check() { + true + } + + package() { + mkdir -p "\$pkgdir"/usr/lib/python3.11/site-packages/test/__pycache__/ + touch "\$pkgdir"/usr/lib/python3.11/site-packages/test/__pycache__/main.cpython-311.pyc + } + EOF + + abuild clean unpack prepare build rootpkg + + if [ -e pkg/pycachetest/usr/lib/python3.11/site-packages/test/__pycache__/main.cpython-311.pyc ]; then + atf_fail ".pyc was not deleted" + fi + + if [ -e pkg/pycachetest/usr/lib/python3.11/site-packages/test/__pycache__ ]; then + atf_fail "__pycache__ dir was not deleted" + fi + + options="keeppycache" abuild clean unpack prepare build rootpkg + + if ! [ -e pkg/pycachetest/usr/lib/python3.11/site-packages/test/__pycache__/main.cpython-311.pyc ]; then + atf_fail ".pyc was deleted but shouldn't have been" + fi + + if ! [ -e pkg/pycachetest/usr/lib/python3.11/site-packages/test/__pycache__ ]; then + atf_fail "__pycache__ dir was deleted but shouldn't have been" + fi +}