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 v2 11/20] python-utils-r2.eclass: Remove PYTHON_SITEDIR export
Date: Thu, 05 Mar 2020 15:15:01
Message-Id: 20200305151024.125834-12-mgorny@gentoo.org
In Reply to: [gentoo-dev] [PATCH v2 00/20] python-r2 suite by "Michał Górny"
1 Signed-off-by: Michał Górny <mgorny@g.o>
2 ---
3 eclass/python-utils-r2.eclass | 34 +++++++++++----------------------
4 eclass/tests/python-utils-r2.sh | 25 ++++++++++++++++++------
5 2 files changed, 30 insertions(+), 29 deletions(-)
6
7 diff --git a/eclass/python-utils-r2.eclass b/eclass/python-utils-r2.eclass
8 index dab4a5b5c87e..4f9df6000e16 100644
9 --- a/eclass/python-utils-r2.eclass
10 +++ b/eclass/python-utils-r2.eclass
11 @@ -238,10 +238,6 @@ _python_impl_matches() {
12 # implementation (either as PYTHON_TARGETS value, e.g. python2_7,
13 # or an EPYTHON one, e.g. python2.7). If no implementation passed,
14 # the current one will be obtained from ${EPYTHON}.
15 -#
16 -# The variables which can be exported are: PYTHON, EPYTHON,
17 -# PYTHON_SITEDIR. They are described more completely in the eclass
18 -# variable documentation.
19 _python_export() {
20 debug-print-function ${FUNCNAME} "${@}"
21
22 @@ -275,15 +271,6 @@ _python_export() {
23 export PYTHON=${EPREFIX}/usr/bin/${impl}
24 debug-print "${FUNCNAME}: PYTHON = ${PYTHON}"
25 ;;
26 - PYTHON_SITEDIR)
27 - [[ -n ${PYTHON} ]] || die "PYTHON needs to be set for ${var} to be exported, or requested before it"
28 - # sysconfig can't be used because:
29 - # 1) pypy doesn't give site-packages but stdlib
30 - # 2) jython gives paths with wrong case
31 - PYTHON_SITEDIR=$("${PYTHON}" -c 'import distutils.sysconfig; print(distutils.sysconfig.get_python_lib())') || die
32 - export PYTHON_SITEDIR
33 - debug-print "${FUNCNAME}: PYTHON_SITEDIR = ${PYTHON_SITEDIR}"
34 - ;;
35 PYTHON_INCLUDEDIR)
36 [[ -n ${PYTHON} ]] || die "PYTHON needs to be set for ${var} to be exported, or requested before it"
37 PYTHON_INCLUDEDIR=$("${PYTHON}" -c 'import distutils.sysconfig; print(distutils.sysconfig.get_python_inc())') || die
38 @@ -393,16 +380,18 @@ _python_export() {
39 }
40
41 # @FUNCTION: python_get_sitedir
42 -# @USAGE: [<impl>]
43 # @DESCRIPTION:
44 -# Obtain and print the 'site-packages' path for the given
45 -# implementation. If no implementation is provided, ${EPYTHON} will
46 -# be used.
47 +# Obtain and print the 'site-packages' path for ${EPYTHON}.
48 python_get_sitedir() {
49 debug-print-function ${FUNCNAME} "${@}"
50 -
51 - _python_export "${@}" PYTHON_SITEDIR
52 - echo "${PYTHON_SITEDIR}"
53 + [[ ${EPYTHON} ]] || die "EPYTHON must be set before calling ${FUNCNAME}"
54 +
55 + # sysconfig can't be used because:
56 + # 1) pypy doesn't give site-packages but stdlib
57 + # 2) jython gives paths with wrong case
58 + local out=$("${EPYTHON}" -c 'import distutils.sysconfig; print(distutils.sysconfig.get_python_lib())') || die
59 + debug-print "${FUNCNAME} -> ${out}"
60 + echo "${out}"
61 }
62
63 # @FUNCTION: python_get_includedir
64 @@ -752,7 +741,7 @@ python_newscript() {
65 # @CODE
66 # src_install() {
67 # python_moduleinto bar
68 -# # installs ${PYTHON_SITEDIR}/bar/baz.py
69 +# # installs $(python_get_sitedir)/bar/baz.py
70 # python_foreach_impl python_domodule baz.py
71 # }
72 # @CODE
73 @@ -788,8 +777,7 @@ python_domodule() {
74 d=${python_moduleroot}
75 else
76 # relative to site-packages
77 - local PYTHON_SITEDIR=${PYTHON_SITEDIR}
78 - [[ ${PYTHON_SITEDIR} ]] || _python_export PYTHON_SITEDIR
79 + local PYTHON_SITEDIR=$(python_get_sitedir)
80
81 d=${PYTHON_SITEDIR#${EPREFIX}}/${python_moduleroot//.//}
82 fi
83 diff --git a/eclass/tests/python-utils-r2.sh b/eclass/tests/python-utils-r2.sh
84 index c5e618256519..423a0465d39a 100755
85 --- a/eclass/tests/python-utils-r2.sh
86 +++ b/eclass/tests/python-utils-r2.sh
87 @@ -19,6 +19,19 @@ test_var() {
88 tend ${?}
89 }
90
91 +test_get() {
92 + local getter=python_get_${1}
93 + local impl=${2}
94 + local expect=${3}
95 +
96 + tbegin "${getter} for ${impl}"
97 +
98 + local val=$(EPYTHON=${impl} ${getter})
99 + [[ ${val} == ${expect} ]] || eerror "(${impl}: ${getter}: ${val} != ${expect}"
100 +
101 + tend ${?}
102 +}
103 +
104 test_is() {
105 local func=${1}
106 local expect=${2}
107 @@ -63,7 +76,7 @@ inherit python-utils-r2
108 test_var EPYTHON python2_7 python2.7
109 test_var PYTHON python2_7 /usr/bin/python2.7
110 if [[ -x /usr/bin/python2.7 ]]; then
111 - test_var PYTHON_SITEDIR python2_7 "/usr/lib*/python2.7/site-packages"
112 + test_get sitedir python2.7 "/usr/lib*/python2.7/site-packages"
113 test_var PYTHON_INCLUDEDIR python2_7 /usr/include/python2.7
114 test_var PYTHON_LIBPATH python2_7 "/usr/lib*/libpython2.7$(get_libname)"
115 test_var PYTHON_CONFIG python2_7 /usr/bin/python2.7-config
116 @@ -77,7 +90,7 @@ test_var EPYTHON python3_6 python3.6
117 test_var PYTHON python3_6 /usr/bin/python3.6
118 if [[ -x /usr/bin/python3.6 ]]; then
119 abiflags=$(/usr/bin/python3.6 -c 'import sysconfig; print(sysconfig.get_config_var("ABIFLAGS"))')
120 - test_var PYTHON_SITEDIR python3_6 "/usr/lib*/python3.6/site-packages"
121 + test_get sitedir python3.6 "/usr/lib*/python3.6/site-packages"
122 test_var PYTHON_INCLUDEDIR python3_6 "/usr/include/python3.6${abiflags}"
123 test_var PYTHON_LIBPATH python3_6 "/usr/lib*/libpython3.6${abiflags}$(get_libname)"
124 test_var PYTHON_CONFIG python3_6 "/usr/bin/python3.6${abiflags}-config"
125 @@ -91,7 +104,7 @@ test_var EPYTHON python3_7 python3.7
126 test_var PYTHON python3_7 /usr/bin/python3.7
127 if [[ -x /usr/bin/python3.7 ]]; then
128 abiflags=$(/usr/bin/python3.7 -c 'import sysconfig; print(sysconfig.get_config_var("ABIFLAGS"))')
129 - test_var PYTHON_SITEDIR python3_7 "/usr/lib/python3.7/site-packages"
130 + test_get sitedir python3.7 "/usr/lib/python3.7/site-packages"
131 test_var PYTHON_INCLUDEDIR python3_7 "/usr/include/python3.7${abiflags}"
132 test_var PYTHON_LIBPATH python3_7 "/usr/lib*/libpython3.7${abiflags}$(get_libname)"
133 test_var PYTHON_CONFIG python3_7 "/usr/bin/python3.7${abiflags}-config"
134 @@ -104,7 +117,7 @@ test_var PYTHON_SCRIPTDIR python3_7 /usr/lib/python-exec/python3.7
135 test_var EPYTHON jython2_7 jython2.7
136 test_var PYTHON jython2_7 /usr/bin/jython2.7
137 if [[ -x /usr/bin/jython2.7 ]]; then
138 - test_var PYTHON_SITEDIR jython2_7 /usr/share/jython-2.7/Lib/site-packages
139 + test_get sitedir jython2.7 /usr/share/jython-2.7/Lib/site-packages
140 fi
141 test_var PYTHON_PKG_DEP jython2_7 '*dev-java/jython*:2.7'
142 test_var PYTHON_SCRIPTDIR jython2_7 /usr/lib/python-exec/jython2.7
143 @@ -112,7 +125,7 @@ test_var PYTHON_SCRIPTDIR jython2_7 /usr/lib/python-exec/jython2.7
144 test_var EPYTHON pypy pypy
145 test_var PYTHON pypy /usr/bin/pypy
146 if [[ -x /usr/bin/pypy ]]; then
147 - test_var PYTHON_SITEDIR pypy "/usr/lib*/pypy2.7/site-packages"
148 + test_get sitedir pypy "/usr/lib*/pypy2.7/site-packages"
149 test_var PYTHON_INCLUDEDIR pypy "/usr/lib*/pypy2.7/include"
150 fi
151 test_var PYTHON_PKG_DEP pypy '*dev-python/pypy*:0='
152 @@ -121,7 +134,7 @@ test_var PYTHON_SCRIPTDIR pypy /usr/lib/python-exec/pypy
153 test_var EPYTHON pypy3 pypy3
154 test_var PYTHON pypy3 /usr/bin/pypy3
155 if [[ -x /usr/bin/pypy3 ]]; then
156 - test_var PYTHON_SITEDIR pypy3 "/usr/lib*/pypy3.?/site-packages"
157 + test_get sitedir pypy3 "/usr/lib*/pypy3.?/site-packages"
158 test_var PYTHON_INCLUDEDIR pypy3 "/usr/lib*/pypy3.?/include"
159 fi
160 test_var PYTHON_PKG_DEP pypy3 '*dev-python/pypy3*:0='
161 --
162 2.25.1