aboutsummaryrefslogtreecommitdiffstats
path: root/main/abuild/0001-feat-abuild-add-support-for-pyX.Y-providers.patch
blob: b41cc5b31484893c1660f3a7834bdd975623539e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
From ac3ee42458ebb6204c75135cbeb30201777e4116 Mon Sep 17 00:00:00 2001
From: Leo <thinkabit.ukim@gmail.com>
Date: Thu, 8 Aug 2019 19:01:39 -0300
Subject: [PATCH 1/2] 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 <toast@toast.cafe>
---
 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"
-- 
2.31.1