Skip to content

Commit a72c430

Browse files
committed
Replace use of deprecated Python module distutils.sysconfig, take 2.
With Python 3.10, configure spits out warnings about the module distutils.sysconfig being deprecated and scheduled for removal in Python 3.12. Change the uses in configure to use the module sysconfig instead. The logic stays largely the same, although we have to rely on INCLUDEPY instead of the deprecated get_python_inc function. Note that sysconfig exists since Python 2.7, so this moves the minimum required version up from Python 2.6 (or 2.4, before v13). Also, sysconfig didn't exist in Python 3.1, so the minimum 3.x version is now 3.2. Back-patch of commit bd233bd into all supported branches. In v10, this also includes back-patching v11's beff4bb, primarily because this opinion is clearly out-of-date: While at it, get rid of the code's assumption that both the major and minor numbers contain exactly one digit. That will foreseeably be broken by Python 3.10 in perhaps four or five years. That's far enough out that we probably don't need to back-patch this. Peter Eisentraut, Tom Lane, Andres Freund Discussion: https://postgr.es/m/c74add3c-09c4-a9dd-1a03-a846e5b2fc52@enterprisedb.com
1 parent f83d427 commit a72c430

File tree

3 files changed

+52
-57
lines changed

3 files changed

+52
-57
lines changed

config/python.m4

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -29,35 +29,32 @@ fi
2929
# as well as the Python version.
3030
AC_DEFUN([_PGAC_CHECK_PYTHON_DIRS],
3131
[AC_REQUIRE([PGAC_PATH_PYTHON])
32-
AC_MSG_CHECKING([for Python distutils module])
33-
if "${PYTHON}" -c 'import distutils' 2>&AS_MESSAGE_LOG_FD
32+
python_fullversion=`${PYTHON} -c "import sys; print(sys.version)" | sed q`
33+
AC_MSG_NOTICE([using python $python_fullversion])
34+
# python_fullversion is typically n.n.n plus some trailing junk
35+
python_majorversion=`echo "$python_fullversion" | sed '[s/^\([0-9]*\).*/\1/]'`
36+
python_minorversion=`echo "$python_fullversion" | sed '[s/^[0-9]*\.\([0-9]*\).*/\1/]'`
37+
python_version=`echo "$python_fullversion" | sed '[s/^\([0-9]*\.[0-9]*\).*/\1/]'`
38+
# Reject unsupported Python versions as soon as practical.
39+
if test "$python_majorversion" -lt 3 -a "$python_minorversion" -lt 7; then
40+
AC_MSG_ERROR([Python version $python_version is too old (version 2.7 or later is required)])
41+
fi
42+
43+
AC_MSG_CHECKING([for Python sysconfig module])
44+
if "${PYTHON}" -c 'import sysconfig' 2>&AS_MESSAGE_LOG_FD
3445
then
3546
AC_MSG_RESULT(yes)
3647
else
3748
AC_MSG_RESULT(no)
38-
AC_MSG_ERROR([distutils module not found])
49+
AC_MSG_ERROR([sysconfig module not found])
3950
fi
51+
4052
AC_MSG_CHECKING([Python configuration directory])
41-
python_majorversion=`${PYTHON} -c "import sys; print(sys.version[[0]])"`
42-
python_minorversion=`${PYTHON} -c "import sys; print(sys.version[[2]])"`
43-
python_version=`${PYTHON} -c "import sys; print(sys.version[[:3]])"`
44-
python_configdir=`${PYTHON} -c "import distutils.sysconfig; print(' '.join(filter(None,distutils.sysconfig.get_config_vars('LIBPL'))))"`
53+
python_configdir=`${PYTHON} -c "import sysconfig; print(' '.join(filter(None,sysconfig.get_config_vars('LIBPL'))))"`
4554
AC_MSG_RESULT([$python_configdir])
4655
47-
# Reject unsupported Python versions as soon as practical.
48-
if test "$python_majorversion" -lt 3 -a "$python_minorversion" -lt 4; then
49-
AC_MSG_ERROR([Python version $python_version is too old (version 2.4 or later is required)])
50-
fi
51-
52-
AC_MSG_CHECKING([Python include directories])
53-
python_includespec=`${PYTHON} -c "
54-
import distutils.sysconfig
55-
a = '-I' + distutils.sysconfig.get_python_inc(False)
56-
b = '-I' + distutils.sysconfig.get_python_inc(True)
57-
if a == b:
58-
print(a)
59-
else:
60-
print(a + ' ' + b)"`
56+
AC_MSG_CHECKING([Python include directory])
57+
python_includespec=`${PYTHON} -c "import sysconfig; print('-I' + sysconfig.get_config_var('INCLUDEPY'))"`
6158
if test "$PORTNAME" = win32 ; then
6259
python_includespec=`echo $python_includespec | sed 's,[[\]],/,g'`
6360
fi
@@ -91,8 +88,8 @@ AC_DEFUN([PGAC_CHECK_PYTHON_EMBED_SETUP],
9188
[AC_REQUIRE([_PGAC_CHECK_PYTHON_DIRS])
9289
AC_MSG_CHECKING([how to link an embedded Python application])
9390
94-
python_libdir=`${PYTHON} -c "import distutils.sysconfig; print(' '.join(filter(None,distutils.sysconfig.get_config_vars('LIBDIR'))))"`
95-
python_ldlibrary=`${PYTHON} -c "import distutils.sysconfig; print(' '.join(filter(None,distutils.sysconfig.get_config_vars('LDLIBRARY'))))"`
91+
python_libdir=`${PYTHON} -c "import sysconfig; print(' '.join(filter(None,sysconfig.get_config_vars('LIBDIR'))))"`
92+
python_ldlibrary=`${PYTHON} -c "import sysconfig; print(' '.join(filter(None,sysconfig.get_config_vars('LDLIBRARY'))))"`
9693
9794
# If LDLIBRARY exists and has a shlib extension, use it verbatim.
9895
ldlibrary=`echo "${python_ldlibrary}" | sed -e 's/\.so$//' -e 's/\.dll$//' -e 's/\.dylib$//' -e 's/\.sl$//'`
@@ -104,11 +101,11 @@ else
104101
# Otherwise, guess the base name of the shlib.
105102
# LDVERSION was added in Python 3.2, before that use VERSION,
106103
# or failing that, $python_version from _PGAC_CHECK_PYTHON_DIRS.
107-
python_ldversion=`${PYTHON} -c "import distutils.sysconfig; print(' '.join(filter(None,distutils.sysconfig.get_config_vars('LDVERSION'))))"`
104+
python_ldversion=`${PYTHON} -c "import sysconfig; print(' '.join(filter(None,sysconfig.get_config_vars('LDVERSION'))))"`
108105
if test x"${python_ldversion}" != x""; then
109106
ldlibrary="python${python_ldversion}"
110107
else
111-
python_version_var=`${PYTHON} -c "import distutils.sysconfig; print(' '.join(filter(None,distutils.sysconfig.get_config_vars('VERSION'))))"`
108+
python_version_var=`${PYTHON} -c "import sysconfig; print(' '.join(filter(None,sysconfig.get_config_vars('VERSION'))))"`
112109
if test x"${python_version_var}" != x""; then
113110
ldlibrary="python${python_version_var}"
114111
else
@@ -168,7 +165,7 @@ PL/Python.])
168165
fi
169166
python_libspec="-L${python_libdir} -l${ldlibrary}"
170167
171-
python_additional_libs=`${PYTHON} -c "import distutils.sysconfig; print(' '.join(filter(None,distutils.sysconfig.get_config_vars('LIBS','LIBC','LIBM','BASEMODLIBS'))))"`
168+
python_additional_libs=`${PYTHON} -c "import sysconfig; print(' '.join(filter(None,sysconfig.get_config_vars('LIBS','LIBC','LIBM','BASEMODLIBS'))))"`
172169
173170
AC_MSG_RESULT([${python_libspec} ${python_additional_libs}])
174171

configure

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8230,41 +8230,39 @@ if test x"$PYTHON" = x""; then
82308230
fi
82318231

82328232

8233-
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for Python distutils module" >&5
8234-
$as_echo_n "checking for Python distutils module... " >&6; }
8235-
if "${PYTHON}" -c 'import distutils' 2>&5
8233+
python_fullversion=`${PYTHON} -c "import sys; print(sys.version)" | sed q`
8234+
{ $as_echo "$as_me:${as_lineno-$LINENO}: using python $python_fullversion" >&5
8235+
$as_echo "$as_me: using python $python_fullversion" >&6;}
8236+
# python_fullversion is typically n.n.n plus some trailing junk
8237+
python_majorversion=`echo "$python_fullversion" | sed 's/^\([0-9]*\).*/\1/'`
8238+
python_minorversion=`echo "$python_fullversion" | sed 's/^[0-9]*\.\([0-9]*\).*/\1/'`
8239+
python_version=`echo "$python_fullversion" | sed 's/^\([0-9]*\.[0-9]*\).*/\1/'`
8240+
# Reject unsupported Python versions as soon as practical.
8241+
if test "$python_majorversion" -lt 3 -a "$python_minorversion" -lt 7; then
8242+
as_fn_error $? "Python version $python_version is too old (version 2.7 or later is required)" "$LINENO" 5
8243+
fi
8244+
8245+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for Python sysconfig module" >&5
8246+
$as_echo_n "checking for Python sysconfig module... " >&6; }
8247+
if "${PYTHON}" -c 'import sysconfig' 2>&5
82368248
then
82378249
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
82388250
$as_echo "yes" >&6; }
82398251
else
82408252
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
82418253
$as_echo "no" >&6; }
8242-
as_fn_error $? "distutils module not found" "$LINENO" 5
8254+
as_fn_error $? "sysconfig module not found" "$LINENO" 5
82438255
fi
8256+
82448257
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking Python configuration directory" >&5
82458258
$as_echo_n "checking Python configuration directory... " >&6; }
8246-
python_majorversion=`${PYTHON} -c "import sys; print(sys.version[0])"`
8247-
python_minorversion=`${PYTHON} -c "import sys; print(sys.version[2])"`
8248-
python_version=`${PYTHON} -c "import sys; print(sys.version[:3])"`
8249-
python_configdir=`${PYTHON} -c "import distutils.sysconfig; print(' '.join(filter(None,distutils.sysconfig.get_config_vars('LIBPL'))))"`
8259+
python_configdir=`${PYTHON} -c "import sysconfig; print(' '.join(filter(None,sysconfig.get_config_vars('LIBPL'))))"`
82508260
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $python_configdir" >&5
82518261
$as_echo "$python_configdir" >&6; }
82528262

8253-
# Reject unsupported Python versions as soon as practical.
8254-
if test "$python_majorversion" -lt 3 -a "$python_minorversion" -lt 4; then
8255-
as_fn_error $? "Python version $python_version is too old (version 2.4 or later is required)" "$LINENO" 5
8256-
fi
8257-
8258-
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking Python include directories" >&5
8259-
$as_echo_n "checking Python include directories... " >&6; }
8260-
python_includespec=`${PYTHON} -c "
8261-
import distutils.sysconfig
8262-
a = '-I' + distutils.sysconfig.get_python_inc(False)
8263-
b = '-I' + distutils.sysconfig.get_python_inc(True)
8264-
if a == b:
8265-
print(a)
8266-
else:
8267-
print(a + ' ' + b)"`
8263+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking Python include directory" >&5
8264+
$as_echo_n "checking Python include directory... " >&6; }
8265+
python_includespec=`${PYTHON} -c "import sysconfig; print('-I' + sysconfig.get_config_var('INCLUDEPY'))"`
82688266
if test "$PORTNAME" = win32 ; then
82698267
python_includespec=`echo $python_includespec | sed 's,[\],/,g'`
82708268
fi
@@ -8276,8 +8274,8 @@ $as_echo "$python_includespec" >&6; }
82768274
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to link an embedded Python application" >&5
82778275
$as_echo_n "checking how to link an embedded Python application... " >&6; }
82788276

8279-
python_libdir=`${PYTHON} -c "import distutils.sysconfig; print(' '.join(filter(None,distutils.sysconfig.get_config_vars('LIBDIR'))))"`
8280-
python_ldlibrary=`${PYTHON} -c "import distutils.sysconfig; print(' '.join(filter(None,distutils.sysconfig.get_config_vars('LDLIBRARY'))))"`
8277+
python_libdir=`${PYTHON} -c "import sysconfig; print(' '.join(filter(None,sysconfig.get_config_vars('LIBDIR'))))"`
8278+
python_ldlibrary=`${PYTHON} -c "import sysconfig; print(' '.join(filter(None,sysconfig.get_config_vars('LDLIBRARY'))))"`
82818279

82828280
# If LDLIBRARY exists and has a shlib extension, use it verbatim.
82838281
ldlibrary=`echo "${python_ldlibrary}" | sed -e 's/\.so$//' -e 's/\.dll$//' -e 's/\.dylib$//' -e 's/\.sl$//'`
@@ -8289,11 +8287,11 @@ else
82898287
# Otherwise, guess the base name of the shlib.
82908288
# LDVERSION was added in Python 3.2, before that use VERSION,
82918289
# or failing that, $python_version from _PGAC_CHECK_PYTHON_DIRS.
8292-
python_ldversion=`${PYTHON} -c "import distutils.sysconfig; print(' '.join(filter(None,distutils.sysconfig.get_config_vars('LDVERSION'))))"`
8290+
python_ldversion=`${PYTHON} -c "import sysconfig; print(' '.join(filter(None,sysconfig.get_config_vars('LDVERSION'))))"`
82938291
if test x"${python_ldversion}" != x""; then
82948292
ldlibrary="python${python_ldversion}"
82958293
else
8296-
python_version_var=`${PYTHON} -c "import distutils.sysconfig; print(' '.join(filter(None,distutils.sysconfig.get_config_vars('VERSION'))))"`
8294+
python_version_var=`${PYTHON} -c "import sysconfig; print(' '.join(filter(None,sysconfig.get_config_vars('VERSION'))))"`
82978295
if test x"${python_version_var}" != x""; then
82988296
ldlibrary="python${python_version_var}"
82998297
else
@@ -8353,7 +8351,7 @@ PL/Python." "$LINENO" 5
83538351
fi
83548352
python_libspec="-L${python_libdir} -l${ldlibrary}"
83558353

8356-
python_additional_libs=`${PYTHON} -c "import distutils.sysconfig; print(' '.join(filter(None,distutils.sysconfig.get_config_vars('LIBS','LIBC','LIBM','BASEMODLIBS'))))"`
8354+
python_additional_libs=`${PYTHON} -c "import sysconfig; print(' '.join(filter(None,sysconfig.get_config_vars('LIBS','LIBC','LIBM','BASEMODLIBS'))))"`
83578355

83588356
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: ${python_libspec} ${python_additional_libs}" >&5
83598357
$as_echo "${python_libspec} ${python_additional_libs}" >&6; }

doc/src/sgml/installation.sgml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,10 @@ su - postgres
193193
To build the <application>PL/Python</> server programming
194194
language, you need a <productname>Python</productname>
195195
installation with the header files and
196-
the <application>distutils</application> module. The minimum
197-
required version is <productname>Python</productname> 2.4.
196+
the <application>sysconfig</application> module. The minimum
197+
required version is <productname>Python</productname> 2.7.
198198
<productname>Python 3</productname> is supported if it's
199-
version 3.1 or later; but see
199+
version 3.2 or later; but see
200200
<![%standalone-include[the <application>PL/Python</> documentation]]>
201201
<![%standalone-ignore[<xref linkend="plpython-python23">]]>
202202
when using Python 3.

0 commit comments

Comments
 (0)