Gentoo Archives: gentoo-python

From: "Michał Górny" <mgorny@g.o>
To: gentoo-python@l.g.o
Cc: python@g.o, "Michał Górny" <mgorny@g.o>
Subject: [gentoo-python] [PATCH python-any-r1] Introduce python_gen_any_dep().
Date: Thu, 19 Sep 2013 22:39:49
Message-Id: 1379630416-11496-1-git-send-email-mgorny@gentoo.org
1 This thingie allows you to get huge, beautiful dependency blocks that
2 can accompany python_check_deps() in making python-any-r1 finally work
3 like it is supposed to.
4
5 Use like:
6
7 $(python_gen_any_dep 'dev-python/foo[${PYTHON_USEDEP}] ...')
8
9 beware: single quotes!
10
11 and get:
12
13 || (
14 ( dev-lang/python:2.7 dev-python/foo[...2_7...] )
15 ( dev-lang/python:2.6 dev-python/foo[...2_6...] )
16 )
17 ---
18 gx86/eclass/python-any-r1.eclass | 61 ++++++++++++++++++++++++++++++++++++++++
19 1 file changed, 61 insertions(+)
20
21 diff --git a/gx86/eclass/python-any-r1.eclass b/gx86/eclass/python-any-r1.eclass
22 index 3be995f..72ec914 100644
23 --- a/gx86/eclass/python-any-r1.eclass
24 +++ b/gx86/eclass/python-any-r1.eclass
25 @@ -156,6 +156,67 @@ _python_build_set_globals
26 # python_targets_python2_7(-)?,python_single_target_python2_7(+)?
27 # @CODE
28
29 +# @FUNCTION: python_gen_any_dep
30 +# @USAGE: <dependency-block>
31 +# @DESCRIPTION:
32 +# Generate an any-of dependency that enforces a version match between
33 +# the Python interpreter and Python packages. <dependency-block> needs
34 +# to list one or more dependencies with verbatim '${PYTHON_USEDEP}'
35 +# references (quoted!) that will get expanded inside the function.
36 +#
37 +# This should be used along with an appropriate python_check_deps()
38 +# that checks which of the any-of blocks were matched.
39 +#
40 +# Example use:
41 +# @CODE
42 +# DEPEND="$(python_gen_any_dep '
43 +# dev-python/foo[${PYTHON_USEDEP}]
44 +# || ( dev-python/bar[${PYTHON_USEDEP}]
45 +# dev-python/baz[${PYTHON_USEDEP}] )')"
46 +#
47 +# python_check_deps() {
48 +# has_version "dev-python/foo[${PYTHON_USEDEP}]" \
49 +# && { has_version "dev-python/bar[${PYTHON_USEDEP}]" \
50 +# || has_version "dev-python/baz[${PYTHON_USEDEP}]"; }
51 +# }
52 +# @CODE
53 +#
54 +# Example value:
55 +# @CODE
56 +# || (
57 +# (
58 +# dev-lang/python:2.7
59 +# dev-python/foo[python_targets_python2_7(-)?,python_single_target_python2_7(+)?]
60 +# || ( dev-python/bar[python_targets_python2_7(-)?,python_single_target_python2_7(+)?]
61 +# dev-python/baz[python_targets_python2_7(-)?,python_single_target_python2_7(+)?] )
62 +# )
63 +# (
64 +# dev-lang/python:2.6
65 +# dev-python/foo[python_targets_python2_6(-)?,python_single_target_python2_6(+)?]
66 +# || ( dev-python/bar[python_targets_python2_6(-)?,python_single_target_python2_6(+)?]
67 +# dev-python/baz[python_targets_python2_6(-)?,python_single_target_python2_6(+)?] )
68 +# )
69 +# )
70 +# @CODE
71 +python_gen_any_dep() {
72 + debug-print-function ${FUNCNAME} "${@}"
73 +
74 + local depstr=${1}
75 + [[ ${depstr} ]] || die "No dependency string provided"
76 +
77 + local PYTHON_PKG_DEP out=
78 + for i in "${_PYTHON_ALL_IMPLS[@]}"; do
79 + has "${i}" "${PYTHON_COMPAT[@]}" || continue
80 +
81 + local PYTHON_USEDEP="python_targets_${i}(-),python_single_target_${i}(+)"
82 + python_export "${i}" PYTHON_PKG_DEP
83 +
84 + local i_depstr=${depstr//\$\{PYTHON_USEDEP\}/${PYTHON_USEDEP}}
85 + out="( ${PYTHON_PKG_DEP} ${i_depstr} ) ${out}"
86 + done
87 + echo "|| ( ${out})"
88 +}
89 +
90 # @FUNCTION: _python_EPYTHON_supported
91 # @USAGE: <epython>
92 # @INTERNAL
93 --
94 1.8.3.2

Replies