Gentoo Archives: gentoo-dev

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