From ac3ee42458ebb6204c75135cbeb30201777e4116 Mon Sep 17 00:00:00 2001 From: Leo Date: Thu, 8 Aug 2019 19:01:39 -0300 Subject: [PATCH] feat(abuild): add support for pyX.Y providers Now all python packages that install python modules under /usr/lib/pythonX.Y/site-packages will have a provider that indicates their MAJOR (X) and MINOR (Y) versions. pyX maps to the MAJOR version of the package, its objective is to allow users to quickly install a python module without having to search around for the correct package, doing `apk add py3.9:foo` will install whatever packages provides the foo module. The directories checked only go one level deep, so '/usr/lib/python3.9/site-packages/date' will generate py3:date=$pkgver-r$pkgrel. files ending with .py also count and are added with their .py prefix stripped away. so '/usr/lib/python3.9/site-packages/six.py' will generate py3:six=$pkgver-r$pkgrel. The reason for doing this is the same as creating pc:, so: and cmd:, it is more reliable and robust to depened on what we known of what the package provides than to try to guess via the pkgname. Co-authored-by: Chloe Kudryavtsev --- abuild.in | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/abuild.in b/abuild.in index 303834c..aad4223 100644 --- a/abuild.in +++ b/abuild.in @@ -1225,6 +1225,46 @@ prepare_command_provides() { done } +prepare_py_provides() { + local dir="${subpkgdir:-$pkgdir}" py_providers="" + options_has "!tracedeps" && return 0 + cd "$dir" || return 1 + + # Find all directories under site-packages, ignore __pycache__ and + # .egg-info packages, store the basename with the proper pyX.Y prefix + # one per-line + py_providers="$(find 'usr/lib/python'*/site-packages \ + -print0 -mindepth 1 -maxdepth 1 \ + -type f -iname '*.py' -o -type d \ + 2>/dev/null | xargs -0 -I '{}' sh -c ' + d="{}" + + # Check if we were given a directory then check if there + # is a file called __init__.py inside, this is required + # to import modules, if there is no __init__.py then the + # installed directory is not actually a module, this is a + # special case for packages that use c-extensions and + # install their .c and .h files to $sitelib. + if [ -d "$d" ] && [ ! -f "$d"/__init__.py ]; then + exit 0 + fi + + # Find out which version of python we are building for + # this will find out by looking at the MAJOR and MINOR + # versions in /usr/lib/pythonMAJOR.MINOR + pyver="${d##*usr/lib/python}" + pyver="${pyver%%/*}" + + # Strip the .py prefix if it exists + d="${d%%.py*}" + + echo "py$pyver:${d##*/}" + ')" + local i; for i in $py_providers; do + echo "$i=$pkgver-r$pkgrel" >> "$controldir"/.provides-py + done +} + # check if dir has arch specific binaries dir_has_arch_binaries() { local dir="$1" @@ -1294,6 +1334,7 @@ prepare_package() { && prepare_symlinks \ && prepare_pkgconfig_provides \ && prepare_command_provides \ + && prepare_py_provides \ || return 1 archcheck } @@ -1447,6 +1488,10 @@ trace_apk_deps() { sed 's/^/provides = cmd:/' "$dir"/.provides-command | sort -u \ >> "$dir"/.PKGINFO fi + if [ -f "$dir"/.provides-py ]; then + sed 's/^/provides = /' "$dir"/.provides-py | sort -u \ + >> "$dir"/.PKGINFO + fi [ -z "$autodeps" ] && return 0 for i in $autodeps; do echo "depend = $i"