Skip to content

Commit e41176b

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 e368910 commit e41176b

File tree

3 files changed

+31
-45
lines changed

3 files changed

+31
-45
lines changed

config/python.m4

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -36,32 +36,25 @@ python_majorversion=`echo "$python_fullversion" | sed '[s/^\([0-9]*\).*/\1/]'`
3636
python_minorversion=`echo "$python_fullversion" | sed '[s/^[0-9]*\.\([0-9]*\).*/\1/]'`
3737
python_version=`echo "$python_fullversion" | sed '[s/^\([0-9]*\.[0-9]*\).*/\1/]'`
3838
# Reject unsupported Python versions as soon as practical.
39-
if test "$python_majorversion" -lt 3 -a "$python_minorversion" -lt 4; then
40-
AC_MSG_ERROR([Python version $python_version is too old (version 2.4 or later is required)])
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)])
4141
fi
4242
43-
AC_MSG_CHECKING([for Python distutils module])
44-
if "${PYTHON}" -c 'import distutils' 2>&AS_MESSAGE_LOG_FD
43+
AC_MSG_CHECKING([for Python sysconfig module])
44+
if "${PYTHON}" -c 'import sysconfig' 2>&AS_MESSAGE_LOG_FD
4545
then
4646
AC_MSG_RESULT(yes)
4747
else
4848
AC_MSG_RESULT(no)
49-
AC_MSG_ERROR([distutils module not found])
49+
AC_MSG_ERROR([sysconfig module not found])
5050
fi
5151
5252
AC_MSG_CHECKING([Python configuration directory])
53-
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'))))"`
5454
AC_MSG_RESULT([$python_configdir])
5555
56-
AC_MSG_CHECKING([Python include directories])
57-
python_includespec=`${PYTHON} -c "
58-
import distutils.sysconfig
59-
a = '-I' + distutils.sysconfig.get_python_inc(False)
60-
b = '-I' + distutils.sysconfig.get_python_inc(True)
61-
if a == b:
62-
print(a)
63-
else:
64-
print(a + ' ' + b)"`
56+
AC_MSG_CHECKING([Python include directory])
57+
python_includespec=`${PYTHON} -c "import sysconfig; print('-I' + sysconfig.get_config_var('INCLUDEPY'))"`
6558
if test "$PORTNAME" = win32 ; then
6659
python_includespec=`echo $python_includespec | sed 's,[[\]],/,g'`
6760
fi
@@ -95,8 +88,8 @@ AC_DEFUN([PGAC_CHECK_PYTHON_EMBED_SETUP],
9588
[AC_REQUIRE([_PGAC_CHECK_PYTHON_DIRS])
9689
AC_MSG_CHECKING([how to link an embedded Python application])
9790
98-
python_libdir=`${PYTHON} -c "import distutils.sysconfig; print(' '.join(filter(None,distutils.sysconfig.get_config_vars('LIBDIR'))))"`
99-
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'))))"`
10093
10194
# If LDLIBRARY exists and has a shlib extension, use it verbatim.
10295
ldlibrary=`echo "${python_ldlibrary}" | sed -e 's/\.so$//' -e 's/\.dll$//' -e 's/\.dylib$//' -e 's/\.sl$//'`
@@ -108,11 +101,11 @@ else
108101
# Otherwise, guess the base name of the shlib.
109102
# LDVERSION was added in Python 3.2, before that use VERSION,
110103
# or failing that, $python_version from _PGAC_CHECK_PYTHON_DIRS.
111-
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'))))"`
112105
if test x"${python_ldversion}" != x""; then
113106
ldlibrary="python${python_ldversion}"
114107
else
115-
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'))))"`
116109
if test x"${python_version_var}" != x""; then
117110
ldlibrary="python${python_version_var}"
118111
else
@@ -172,7 +165,7 @@ PL/Python.])
172165
fi
173166
python_libspec="-L${python_libdir} -l${ldlibrary}"
174167
175-
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'))))"`
176169
177170
AC_MSG_RESULT([${python_libspec} ${python_additional_libs}])
178171

configure

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9889,38 +9889,31 @@ python_majorversion=`echo "$python_fullversion" | sed 's/^\([0-9]*\).*/\1/'`
98899889
python_minorversion=`echo "$python_fullversion" | sed 's/^[0-9]*\.\([0-9]*\).*/\1/'`
98909890
python_version=`echo "$python_fullversion" | sed 's/^\([0-9]*\.[0-9]*\).*/\1/'`
98919891
# Reject unsupported Python versions as soon as practical.
9892-
if test "$python_majorversion" -lt 3 -a "$python_minorversion" -lt 4; then
9893-
as_fn_error $? "Python version $python_version is too old (version 2.4 or later is required)" "$LINENO" 5
9892+
if test "$python_majorversion" -lt 3 -a "$python_minorversion" -lt 7; then
9893+
as_fn_error $? "Python version $python_version is too old (version 2.7 or later is required)" "$LINENO" 5
98949894
fi
98959895

9896-
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for Python distutils module" >&5
9897-
$as_echo_n "checking for Python distutils module... " >&6; }
9898-
if "${PYTHON}" -c 'import distutils' 2>&5
9896+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for Python sysconfig module" >&5
9897+
$as_echo_n "checking for Python sysconfig module... " >&6; }
9898+
if "${PYTHON}" -c 'import sysconfig' 2>&5
98999899
then
99009900
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
99019901
$as_echo "yes" >&6; }
99029902
else
99039903
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
99049904
$as_echo "no" >&6; }
9905-
as_fn_error $? "distutils module not found" "$LINENO" 5
9905+
as_fn_error $? "sysconfig module not found" "$LINENO" 5
99069906
fi
99079907

99089908
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking Python configuration directory" >&5
99099909
$as_echo_n "checking Python configuration directory... " >&6; }
9910-
python_configdir=`${PYTHON} -c "import distutils.sysconfig; print(' '.join(filter(None,distutils.sysconfig.get_config_vars('LIBPL'))))"`
9910+
python_configdir=`${PYTHON} -c "import sysconfig; print(' '.join(filter(None,sysconfig.get_config_vars('LIBPL'))))"`
99119911
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $python_configdir" >&5
99129912
$as_echo "$python_configdir" >&6; }
99139913

9914-
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking Python include directories" >&5
9915-
$as_echo_n "checking Python include directories... " >&6; }
9916-
python_includespec=`${PYTHON} -c "
9917-
import distutils.sysconfig
9918-
a = '-I' + distutils.sysconfig.get_python_inc(False)
9919-
b = '-I' + distutils.sysconfig.get_python_inc(True)
9920-
if a == b:
9921-
print(a)
9922-
else:
9923-
print(a + ' ' + b)"`
9914+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking Python include directory" >&5
9915+
$as_echo_n "checking Python include directory... " >&6; }
9916+
python_includespec=`${PYTHON} -c "import sysconfig; print('-I' + sysconfig.get_config_var('INCLUDEPY'))"`
99249917
if test "$PORTNAME" = win32 ; then
99259918
python_includespec=`echo $python_includespec | sed 's,[\],/,g'`
99269919
fi
@@ -9932,8 +9925,8 @@ $as_echo "$python_includespec" >&6; }
99329925
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to link an embedded Python application" >&5
99339926
$as_echo_n "checking how to link an embedded Python application... " >&6; }
99349927

9935-
python_libdir=`${PYTHON} -c "import distutils.sysconfig; print(' '.join(filter(None,distutils.sysconfig.get_config_vars('LIBDIR'))))"`
9936-
python_ldlibrary=`${PYTHON} -c "import distutils.sysconfig; print(' '.join(filter(None,distutils.sysconfig.get_config_vars('LDLIBRARY'))))"`
9928+
python_libdir=`${PYTHON} -c "import sysconfig; print(' '.join(filter(None,sysconfig.get_config_vars('LIBDIR'))))"`
9929+
python_ldlibrary=`${PYTHON} -c "import sysconfig; print(' '.join(filter(None,sysconfig.get_config_vars('LDLIBRARY'))))"`
99379930

99389931
# If LDLIBRARY exists and has a shlib extension, use it verbatim.
99399932
ldlibrary=`echo "${python_ldlibrary}" | sed -e 's/\.so$//' -e 's/\.dll$//' -e 's/\.dylib$//' -e 's/\.sl$//'`
@@ -9945,11 +9938,11 @@ else
99459938
# Otherwise, guess the base name of the shlib.
99469939
# LDVERSION was added in Python 3.2, before that use VERSION,
99479940
# or failing that, $python_version from _PGAC_CHECK_PYTHON_DIRS.
9948-
python_ldversion=`${PYTHON} -c "import distutils.sysconfig; print(' '.join(filter(None,distutils.sysconfig.get_config_vars('LDVERSION'))))"`
9941+
python_ldversion=`${PYTHON} -c "import sysconfig; print(' '.join(filter(None,sysconfig.get_config_vars('LDVERSION'))))"`
99499942
if test x"${python_ldversion}" != x""; then
99509943
ldlibrary="python${python_ldversion}"
99519944
else
9952-
python_version_var=`${PYTHON} -c "import distutils.sysconfig; print(' '.join(filter(None,distutils.sysconfig.get_config_vars('VERSION'))))"`
9945+
python_version_var=`${PYTHON} -c "import sysconfig; print(' '.join(filter(None,sysconfig.get_config_vars('VERSION'))))"`
99539946
if test x"${python_version_var}" != x""; then
99549947
ldlibrary="python${python_version_var}"
99559948
else
@@ -10009,7 +10002,7 @@ PL/Python." "$LINENO" 5
1000910002
fi
1001010003
python_libspec="-L${python_libdir} -l${ldlibrary}"
1001110004

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

1001410007
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: ${python_libspec} ${python_additional_libs}" >&5
1001510008
$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
@@ -189,10 +189,10 @@ su - postgres
189189
To build the <application>PL/Python</application> server programming
190190
language, you need a <productname>Python</productname>
191191
installation with the header files and
192-
the <application>distutils</application> module. The minimum
193-
required version is <productname>Python</productname> 2.4.
192+
the <application>sysconfig</application> module. The minimum
193+
required version is <productname>Python</productname> 2.7.
194194
<productname>Python 3</productname> is supported if it's
195-
version 3.1 or later; but see
195+
version 3.2 or later; but see
196196
<xref linkend="plpython-python23"/>
197197
when using Python 3.
198198
</para>

0 commit comments

Comments
 (0)