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 3/7] python-utils-r1.eclass: Obtain include directory from the interpreter
Date: Sun, 08 Nov 2015 09:38:32
Message-Id: 1446975311-19708-4-git-send-email-mgorny@gentoo.org
In Reply to: [gentoo-dev] [PATCHES] python-utils-r1.eclass: Getter cleanup & ABIFLAGS preparation by "Michał Górny"
1 Obtain the Python include directory using the distutils.sysconfig module
2 of the Python interpreter rather than hardcoding values for it. This
3 makes the code more maintainable, and clears the way for re-enabling
4 ABIFLAGS on new Python versions.
5 ---
6 eclass/python-utils-r1.eclass | 21 +++++++--------------
7 eclass/tests/python-utils-r1.sh | 17 +++++++++++++----
8 2 files changed, 20 insertions(+), 18 deletions(-)
9
10 diff --git a/eclass/python-utils-r1.eclass b/eclass/python-utils-r1.eclass
11 index 69166cf..a0274f6 100644
12 --- a/eclass/python-utils-r1.eclass
13 +++ b/eclass/python-utils-r1.eclass
14 @@ -138,6 +138,7 @@ _python_impl_supported() {
15 # The path to Python include directory.
16 #
17 # Set and exported on request using python_export().
18 +# Requires a proper build-time dependency on the Python implementation.
19 #
20 # Example value:
21 # @CODE
22 @@ -279,21 +280,13 @@ python_export() {
23 debug-print "${FUNCNAME}: PYTHON_SITEDIR = ${PYTHON_SITEDIR}"
24 ;;
25 PYTHON_INCLUDEDIR)
26 - local dir
27 - case "${impl}" in
28 - python*)
29 - dir=/usr/include/${impl}
30 - ;;
31 - pypy|pypy3)
32 - dir=/usr/$(get_libdir)/${impl}/include
33 - ;;
34 - *)
35 - die "${impl} lacks header files"
36 - ;;
37 - esac
38 -
39 - export PYTHON_INCLUDEDIR=${EPREFIX}${dir}
40 + export PYTHON_INCLUDEDIR=$("${PYTHON}" -c 'import distutils.sysconfig; print(distutils.sysconfig.get_python_inc())')
41 debug-print "${FUNCNAME}: PYTHON_INCLUDEDIR = ${PYTHON_INCLUDEDIR}"
42 +
43 + # Jython gives a non-existing directory
44 + if [[ ! -d ${PYTHON_INCLUDEDIR} ]]; then
45 + die "${impl} does not install any header files!"
46 + fi
47 ;;
48 PYTHON_LIBPATH)
49 local libname
50 diff --git a/eclass/tests/python-utils-r1.sh b/eclass/tests/python-utils-r1.sh
51 index bd05e9e..dc6676b 100755
52 --- a/eclass/tests/python-utils-r1.sh
53 +++ b/eclass/tests/python-utils-r1.sh
54 @@ -64,7 +64,9 @@ inherit python-utils-r1
55 test_var EPYTHON python2_7 python2.7
56 test_var PYTHON python2_7 /usr/bin/python2.7
57 test_var PYTHON_SITEDIR python2_7 /usr/lib/python2.7/site-packages
58 -test_var PYTHON_INCLUDEDIR python2_7 /usr/include/python2.7
59 +if [[ -x /usr/bin/python2.7 ]]; then
60 + test_var PYTHON_INCLUDEDIR python2_7 /usr/include/python2.7
61 +fi
62 test_var PYTHON_LIBPATH python2_7 /usr/lib/libpython2.7$(get_libname)
63 test_var PYTHON_PKG_DEP python2_7 '*dev-lang/python*:2.7'
64 test_var PYTHON_SCRIPTDIR python2_7 /usr/lib/python-exec/python2.7
65 @@ -72,7 +74,10 @@ test_var PYTHON_SCRIPTDIR python2_7 /usr/lib/python-exec/python2.7
66 test_var EPYTHON python3_4 python3.4
67 test_var PYTHON python3_4 /usr/bin/python3.4
68 test_var PYTHON_SITEDIR python3_4 /usr/lib/python3.4/site-packages
69 -test_var PYTHON_INCLUDEDIR python3_4 /usr/include/python3.4
70 +if [[ -x /usr/bin/python3.4 ]]; then
71 + abiflags=$(/usr/bin/python3.4 -c 'import sysconfig; print(sysconfig.get_config_var("ABIFLAGS"))')
72 + test_var PYTHON_INCLUDEDIR python3_4 "/usr/include/python3.4${abiflags}"
73 +fi
74 test_var PYTHON_LIBPATH python3_4 /usr/lib/libpython3.4$(get_libname)
75 test_var PYTHON_PKG_DEP python3_4 '*dev-lang/python*:3.4'
76 test_var PYTHON_SCRIPTDIR python3_4 /usr/lib/python-exec/python3.4
77 @@ -86,14 +91,18 @@ test_var PYTHON_SCRIPTDIR jython2_7 /usr/lib/python-exec/jython2.7
78 test_var EPYTHON pypy pypy
79 test_var PYTHON pypy /usr/bin/pypy
80 test_var PYTHON_SITEDIR pypy /usr/lib/pypy/site-packages
81 -test_var PYTHON_INCLUDEDIR pypy /usr/lib/pypy/include
82 +if [[ -x /usr/bin/pypy ]]; then
83 + test_var PYTHON_INCLUDEDIR pypy "/usr/lib*/pypy/include"
84 +fi
85 test_var PYTHON_PKG_DEP pypy '*virtual/pypy*:0='
86 test_var PYTHON_SCRIPTDIR pypy /usr/lib/python-exec/pypy
87
88 test_var EPYTHON pypy3 pypy3
89 test_var PYTHON pypy3 /usr/bin/pypy3
90 test_var PYTHON_SITEDIR pypy3 /usr/lib/pypy3/site-packages
91 -test_var PYTHON_INCLUDEDIR pypy3 /usr/lib/pypy3/include
92 +if [[ -x /usr/bin/pypy3 ]]; then
93 + test_var PYTHON_INCLUDEDIR pypy3 /usr/lib/pypy3/include
94 +fi
95 test_var PYTHON_PKG_DEP pypy3 '*virtual/pypy3*:0='
96 test_var PYTHON_SCRIPTDIR pypy3 /usr/lib/python-exec/pypy3
97
98 --
99 2.6.3