abuild: scan for python3 version requirements

Packages installing python3 site packages for python3 in version 3.x.y
depend on python3~3.x. This automatically adds the required
dependencies.

Unit test cases have been added by reusing the `py3-foo-and-bar` test
package. However, the path of that has been renamed to contain spaces
to be extra sure the logic is safe in regrade to spaces in path
names.
This commit is contained in:
Marian Buschsieweke 2023-03-20 10:19:12 +01:00 committed by Natanael Copa
parent 40ecb4b07c
commit 6806a0d39b
4 changed files with 64 additions and 1 deletions

View File

@ -1481,6 +1481,11 @@ trace_apk_deps() {
autodeps="$autodeps $i"
done
# python3 dependencies
for i in $(sort -u "$dir"/.python3-needs 2>/dev/null); do
autodeps="$autodeps $i"
done
# pkg-config depends
for i in $(sort -u "$dir"/.needs-pc 2>/dev/null); do
# first check if its provided by same apkbuild
@ -1674,6 +1679,25 @@ scan_symlink_targets() {
done
}
# check if python3 site packages are installed and depend on a compatible version
scan_python3_dependency() {
local controldir="$2" datadir="$3"
local site_pkg_dirs
if site_pkg_dirs="$(find "$datadir"/usr/lib/ -type d -regex '.*python3\.[0-9]\+/site-packages' -mindepth 2 -maxdepth 2 2>/dev/null)"; then
local pyver_count="$(echo "$site_pkg_dirs" | wc -l)"
if [ "$pyver_count" -gt 1 ]; then
error "package contains python3 modules for conflicting python3 versions"
exit 1
fi
local pyver="${site_pkg_dirs##*usr/lib/python}"
pyver="${pyver%%/*}"
if [ -n "$pyver" ]; then
echo "python3~$pyver" \
>> "$controldir"/.python3-needs
fi
fi
}
#find pkg-config dependencies
scan_pkgconfig_depends() {
local provides_pc="$1" controldir= name= datadir=
@ -1721,6 +1745,7 @@ create_apks() {
subpkgname=$name
scan_shared_objects "$name" "$dir" "$datadir"
scan_symlink_targets "$name" "$dir" "$datadir"
scan_python3_dependency "$name" "$dir" "$datadir"
done
for file in "$pkgbasedir"/.control.*/.provides-pc; do
scan_pkgconfig_depends "$file"

View File

@ -16,6 +16,8 @@ init_tests \
abuild_checksum_duplicates \
abuild_subpkg_dep_leak \
abuild_py_providers_creation \
abuild_py_dependency_scan \
abuild_py_dependency_scan_conflict \
abuild_reject_init_with_improper_shebang \
abuild_valid_pkgnames \
abuild_invalid_pkgnames \
@ -331,13 +333,32 @@ abuild_subpkg_dep_leak_body() {
abuild_py_providers_creation_body() {
init_keys
cp -ra "$testrepo" .
cd testrepo/py3-foo-and-bar
cd testrepo/py3\ foo\ and\ bar
abuild rootpkg || atf_fail "abuild failed"
atf_check -s exit:0 \
-o match:"provides = py3.9:foo=1.0.0-r0" \
cat pkg/.control.py3-foo-and-bar/.PKGINFO
}
abuild_py_dependency_scan_body() {
init_keys
cp -ra "$testrepo" .
cd testrepo/py3\ foo\ and\ bar
abuild rootpkg || atf_fail "abuild failed"
atf_check -s exit:0 \
-o match:"depend = python3~3.9" \
cat pkg/.control.py3-foo-and-bar/.PKGINFO
}
abuild_py_dependency_scan_conflict_body() {
init_keys
cp -ra "$testrepo" .
cd testrepo/py3-conflicting-python-versions
atf_check -s exit:1 \
-e match:"ERROR.*package contains python3 modules for conflicting python3 versions" \
abuild rootpkg
}
abuild_reject_init_with_improper_shebang_body() {
mkdir invalid-initd
cd invalid-initd

View File

@ -0,0 +1,17 @@
# Maintainer: Test user <user@example.com>
pkgname=py3-conflicting-python-versions
pkgver=1.0.0
pkgrel=0
pkgdesc="dummy package for test"
url="https://alpinelinux.org"
license="MIT"
builddir="$srcdir"
package() {
for pyver in 3.9 3.42; do
local sitedir="usr/lib/python$pyver/site-packages"
mkdir -p "$pkgdir"/$sitedir/foo
touch "$pkgdir"/$sitedir/foo/__init__.py
touch "$pkgdir"/$sitedir/bar.py
done
}