1 |
commit: 5c3f15f6a25cdf23d9c35b85edce35fe6dc9a946 |
2 |
Author: Michał Górny <mgorny <AT> gentoo <DOT> org> |
3 |
AuthorDate: Fri May 19 18:35:43 2017 +0000 |
4 |
Commit: Michał Górny <mgorny <AT> gentoo <DOT> org> |
5 |
CommitDate: Mon May 29 21:53:49 2017 +0000 |
6 |
URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=5c3f15f6 |
7 |
|
8 |
python-r1.eclass: Add python_gen_any_dep, to create any-of deps |
9 |
|
10 |
Add a python_gen_any_dep() function similar to the one in python-any-r1 |
11 |
to facilitate creating any-of dependencies for the new python_setup |
12 |
syntax. |
13 |
|
14 |
eclass/python-r1.eclass | 98 +++++++++++++++++++++++++++++++++++++++++++++++++ |
15 |
1 file changed, 98 insertions(+) |
16 |
|
17 |
diff --git a/eclass/python-r1.eclass b/eclass/python-r1.eclass |
18 |
index 2992f603cf8..5ec23d23d8c 100644 |
19 |
--- a/eclass/python-r1.eclass |
20 |
+++ b/eclass/python-r1.eclass |
21 |
@@ -468,6 +468,86 @@ python_gen_impl_dep() { |
22 |
echo "${matches[@]}" |
23 |
} |
24 |
|
25 |
+# @FUNCTION: python_gen_any_dep |
26 |
+# @USAGE: <dependency-block> [<impl-pattern>...] |
27 |
+# @DESCRIPTION: |
28 |
+# Generate an any-of dependency that enforces a version match between |
29 |
+# the Python interpreter and Python packages. <dependency-block> needs |
30 |
+# to list one or more dependencies with verbatim '${PYTHON_USEDEP}' |
31 |
+# references (quoted!) that will get expanded inside the function. |
32 |
+# Optionally, patterns may be specified to restrict the dependency |
33 |
+# to a subset of Python implementations supported by the ebuild. |
34 |
+# |
35 |
+# The patterns can be either fnmatch-style patterns (matched via bash |
36 |
+# == operator against PYTHON_COMPAT values) or '-2' / '-3' to indicate |
37 |
+# appropriately all enabled Python 2/3 implementations (alike |
38 |
+# python_is_python3). Remember to escape or quote the fnmatch patterns |
39 |
+# to prevent accidental shell filename expansion. |
40 |
+# |
41 |
+# This should be used along with an appropriate python_check_deps() |
42 |
+# that checks which of the any-of blocks were matched, and python_setup |
43 |
+# call that enables use of the matched implementation. |
44 |
+# |
45 |
+# Example use: |
46 |
+# @CODE |
47 |
+# DEPEND="$(python_gen_any_dep ' |
48 |
+# dev-python/foo[${PYTHON_USEDEP}] |
49 |
+# || ( dev-python/bar[${PYTHON_USEDEP}] |
50 |
+# dev-python/baz[${PYTHON_USEDEP}] )' -2)" |
51 |
+# |
52 |
+# python_check_deps() { |
53 |
+# has_version "dev-python/foo[${PYTHON_USEDEP}]" \ |
54 |
+# && { has_version "dev-python/bar[${PYTHON_USEDEP}]" \ |
55 |
+# || has_version "dev-python/baz[${PYTHON_USEDEP}]"; } |
56 |
+# } |
57 |
+# |
58 |
+# src_compile() { |
59 |
+# python_foreach_impl usual_code |
60 |
+# |
61 |
+# # some common post-build task that requires Python 2 |
62 |
+# python_setup -2 |
63 |
+# emake frobnicate |
64 |
+# } |
65 |
+# @CODE |
66 |
+# |
67 |
+# Example value: |
68 |
+# @CODE |
69 |
+# || ( |
70 |
+# ( |
71 |
+# dev-lang/python:2.7 |
72 |
+# dev-python/foo[python_targets_python2_7(-)?,python_single_target_python2_7(+)?] |
73 |
+# || ( dev-python/bar[python_targets_python2_7(-)?,python_single_target_python2_7(+)?] |
74 |
+# dev-python/baz[python_targets_python2_7(-)?,python_single_target_python2_7(+)?] ) |
75 |
+# ) |
76 |
+# ( |
77 |
+# dev-lang/python:3.3 |
78 |
+# dev-python/foo[python_targets_python3_3(-)?,python_single_target_python3_3(+)?] |
79 |
+# || ( dev-python/bar[python_targets_python3_3(-)?,python_single_target_python3_3(+)?] |
80 |
+# dev-python/baz[python_targets_python3_3(-)?,python_single_target_python3_3(+)?] ) |
81 |
+# ) |
82 |
+# ) |
83 |
+# @CODE |
84 |
+python_gen_any_dep() { |
85 |
+ debug-print-function ${FUNCNAME} "${@}" |
86 |
+ |
87 |
+ local depstr=${1} |
88 |
+ [[ ${depstr} ]] || die "No dependency string provided" |
89 |
+ shift |
90 |
+ |
91 |
+ local i PYTHON_PKG_DEP out= |
92 |
+ for i in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do |
93 |
+ if _python_impl_matches "${i}" "${@-*}"; then |
94 |
+ local PYTHON_USEDEP="python_targets_${i}(-),python_single_target_${i}(+)" |
95 |
+ python_export "${i}" PYTHON_PKG_DEP |
96 |
+ |
97 |
+ local i_depstr=${depstr//\$\{PYTHON_USEDEP\}/${PYTHON_USEDEP}} |
98 |
+ # note: need to strip '=' slot operator for || deps |
99 |
+ out="( ${PYTHON_PKG_DEP%=} ${i_depstr} ) ${out}" |
100 |
+ fi |
101 |
+ done |
102 |
+ echo "|| ( ${out})" |
103 |
+} |
104 |
+ |
105 |
# @ECLASS-VARIABLE: BUILD_DIR |
106 |
# @DESCRIPTION: |
107 |
# The current build directory. In global scope, it is supposed to |
108 |
@@ -608,6 +688,24 @@ python_foreach_impl() { |
109 |
# fi |
110 |
# } |
111 |
# @CODE |
112 |
+# |
113 |
+# Any-of mode example: |
114 |
+# @CODE |
115 |
+# DEPEND="doc? ( |
116 |
+# $(python_gen_any_dep 'dev-python/epydoc[${PYTHON_USEDEP}]' 'python2*') )" |
117 |
+# |
118 |
+# python_check_deps() { |
119 |
+# has_version "dev-python/epydoc[${PYTHON_USEDEP}]" |
120 |
+# } |
121 |
+# |
122 |
+# src_compile() { |
123 |
+# #... |
124 |
+# if use doc; then |
125 |
+# python_setup 'python2*' |
126 |
+# make doc |
127 |
+# fi |
128 |
+# } |
129 |
+# @CODE |
130 |
python_setup() { |
131 |
debug-print-function ${FUNCNAME} "${@}" |