Skip to content

Commit 803f0b1

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 00fdfde commit 803f0b1

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
@@ -37,32 +37,25 @@ python_majorversion=`echo "$python_fullversion" | sed '[s/^\([0-9]*\).*/\1/]'`
3737
python_minorversion=`echo "$python_fullversion" | sed '[s/^[0-9]*\.\([0-9]*\).*/\1/]'`
3838
python_version=`echo "$python_fullversion" | sed '[s/^\([0-9]*\.[0-9]*\).*/\1/]'`
3939
# Reject unsupported Python versions as soon as practical.
40-
if test "$python_majorversion" -lt 3 -a "$python_minorversion" -lt 6; then
41-
AC_MSG_ERROR([Python version $python_version is too old (version 2.6 or later is required)])
40+
if test "$python_majorversion" -lt 3 -a "$python_minorversion" -lt 7; then
41+
AC_MSG_ERROR([Python version $python_version is too old (version 2.7 or later is required)])
4242
fi
4343
44-
AC_MSG_CHECKING([for Python distutils module])
45-
if "${PYTHON}" -c 'import distutils' 2>&AS_MESSAGE_LOG_FD
44+
AC_MSG_CHECKING([for Python sysconfig module])
45+
if "${PYTHON}" -c 'import sysconfig' 2>&AS_MESSAGE_LOG_FD
4646
then
4747
AC_MSG_RESULT(yes)
4848
else
4949
AC_MSG_RESULT(no)
50-
AC_MSG_ERROR([distutils module not found])
50+
AC_MSG_ERROR([sysconfig module not found])
5151
fi
5252
5353
AC_MSG_CHECKING([Python configuration directory])
54-
python_configdir=`${PYTHON} -c "import distutils.sysconfig; print(' '.join(filter(None,distutils.sysconfig.get_config_vars('LIBPL'))))"`
54+
python_configdir=`${PYTHON} -c "import sysconfig; print(' '.join(filter(None,sysconfig.get_config_vars('LIBPL'))))"`
5555
AC_MSG_RESULT([$python_configdir])
5656
57-
AC_MSG_CHECKING([Python include directories])
58-
python_includespec=`${PYTHON} -c "
59-
import distutils.sysconfig
60-
a = '-I' + distutils.sysconfig.get_python_inc(False)
61-
b = '-I' + distutils.sysconfig.get_python_inc(True)
62-
if a == b:
63-
print(a)
64-
else:
65-
print(a + ' ' + b)"`
57+
AC_MSG_CHECKING([Python include directory])
58+
python_includespec=`${PYTHON} -c "import sysconfig; print('-I' + sysconfig.get_config_var('INCLUDEPY'))"`
6659
if test "$PORTNAME" = win32 ; then
6760
python_includespec=`echo $python_includespec | sed 's,[[\]],/,g'`
6861
fi
@@ -96,8 +89,8 @@ AC_DEFUN([PGAC_CHECK_PYTHON_EMBED_SETUP],
9689
[AC_REQUIRE([_PGAC_CHECK_PYTHON_DIRS])
9790
AC_MSG_CHECKING([how to link an embedded Python application])
9891
99-
python_libdir=`${PYTHON} -c "import distutils.sysconfig; print(' '.join(filter(None,distutils.sysconfig.get_config_vars('LIBDIR'))))"`
100-
python_ldlibrary=`${PYTHON} -c "import distutils.sysconfig; print(' '.join(filter(None,distutils.sysconfig.get_config_vars('LDLIBRARY'))))"`
92+
python_libdir=`${PYTHON} -c "import sysconfig; print(' '.join(filter(None,sysconfig.get_config_vars('LIBDIR'))))"`
93+
python_ldlibrary=`${PYTHON} -c "import sysconfig; print(' '.join(filter(None,sysconfig.get_config_vars('LDLIBRARY'))))"`
10194
10295
# If LDLIBRARY exists and has a shlib extension, use it verbatim.
10396
ldlibrary=`echo "${python_ldlibrary}" | sed -e 's/\.so$//' -e 's/\.dll$//' -e 's/\.dylib$//' -e 's/\.sl$//'`
@@ -109,11 +102,11 @@ else
109102
# Otherwise, guess the base name of the shlib.
110103
# LDVERSION was added in Python 3.2, before that use VERSION,
111104
# or failing that, $python_version from _PGAC_CHECK_PYTHON_DIRS.
112-
python_ldversion=`${PYTHON} -c "import distutils.sysconfig; print(' '.join(filter(None,distutils.sysconfig.get_config_vars('LDVERSION'))))"`
105+
python_ldversion=`${PYTHON} -c "import sysconfig; print(' '.join(filter(None,sysconfig.get_config_vars('LDVERSION'))))"`
113106
if test x"${python_ldversion}" != x""; then
114107
ldlibrary="python${python_ldversion}"
115108
else
116-
python_version_var=`${PYTHON} -c "import distutils.sysconfig; print(' '.join(filter(None,distutils.sysconfig.get_config_vars('VERSION'))))"`
109+
python_version_var=`${PYTHON} -c "import sysconfig; print(' '.join(filter(None,sysconfig.get_config_vars('VERSION'))))"`
117110
if test x"${python_version_var}" != x""; then
118111
ldlibrary="python${python_version_var}"
119112
else
@@ -173,7 +166,7 @@ PL/Python.])
173166
fi
174167
python_libspec="-L${python_libdir} -l${ldlibrary}"
175168
176-
python_additional_libs=`${PYTHON} -c "import distutils.sysconfig; print(' '.join(filter(None,distutils.sysconfig.get_config_vars('LIBS','LIBC','LIBM','BASEMODLIBS'))))"`
169+
python_additional_libs=`${PYTHON} -c "import sysconfig; print(' '.join(filter(None,sysconfig.get_config_vars('LIBS','LIBC','LIBM','BASEMODLIBS'))))"`
177170
178171
AC_MSG_RESULT([${python_libspec} ${python_additional_libs}])
179172

configure

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10339,38 +10339,31 @@ python_majorversion=`echo "$python_fullversion" | sed 's/^\([0-9]*\).*/\1/'`
1033910339
python_minorversion=`echo "$python_fullversion" | sed 's/^[0-9]*\.\([0-9]*\).*/\1/'`
1034010340
python_version=`echo "$python_fullversion" | sed 's/^\([0-9]*\.[0-9]*\).*/\1/'`
1034110341
# Reject unsupported Python versions as soon as practical.
10342-
if test "$python_majorversion" -lt 3 -a "$python_minorversion" -lt 6; then
10343-
as_fn_error $? "Python version $python_version is too old (version 2.6 or later is required)" "$LINENO" 5
10342+
if test "$python_majorversion" -lt 3 -a "$python_minorversion" -lt 7; then
10343+
as_fn_error $? "Python version $python_version is too old (version 2.7 or later is required)" "$LINENO" 5
1034410344
fi
1034510345

10346-
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for Python distutils module" >&5
10347-
$as_echo_n "checking for Python distutils module... " >&6; }
10348-
if "${PYTHON}" -c 'import distutils' 2>&5
10346+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for Python sysconfig module" >&5
10347+
$as_echo_n "checking for Python sysconfig module... " >&6; }
10348+
if "${PYTHON}" -c 'import sysconfig' 2>&5
1034910349
then
1035010350
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
1035110351
$as_echo "yes" >&6; }
1035210352
else
1035310353
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
1035410354
$as_echo "no" >&6; }
10355-
as_fn_error $? "distutils module not found" "$LINENO" 5
10355+
as_fn_error $? "sysconfig module not found" "$LINENO" 5
1035610356
fi
1035710357

1035810358
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking Python configuration directory" >&5
1035910359
$as_echo_n "checking Python configuration directory... " >&6; }
10360-
python_configdir=`${PYTHON} -c "import distutils.sysconfig; print(' '.join(filter(None,distutils.sysconfig.get_config_vars('LIBPL'))))"`
10360+
python_configdir=`${PYTHON} -c "import sysconfig; print(' '.join(filter(None,sysconfig.get_config_vars('LIBPL'))))"`
1036110361
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $python_configdir" >&5
1036210362
$as_echo "$python_configdir" >&6; }
1036310363

10364-
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking Python include directories" >&5
10365-
$as_echo_n "checking Python include directories... " >&6; }
10366-
python_includespec=`${PYTHON} -c "
10367-
import distutils.sysconfig
10368-
a = '-I' + distutils.sysconfig.get_python_inc(False)
10369-
b = '-I' + distutils.sysconfig.get_python_inc(True)
10370-
if a == b:
10371-
print(a)
10372-
else:
10373-
print(a + ' ' + b)"`
10364+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking Python include directory" >&5
10365+
$as_echo_n "checking Python include directory... " >&6; }
10366+
python_includespec=`${PYTHON} -c "import sysconfig; print('-I' + sysconfig.get_config_var('INCLUDEPY'))"`
1037410367
if test "$PORTNAME" = win32 ; then
1037510368
python_includespec=`echo $python_includespec | sed 's,[\],/,g'`
1037610369
fi
@@ -10382,8 +10375,8 @@ $as_echo "$python_includespec" >&6; }
1038210375
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to link an embedded Python application" >&5
1038310376
$as_echo_n "checking how to link an embedded Python application... " >&6; }
1038410377

10385-
python_libdir=`${PYTHON} -c "import distutils.sysconfig; print(' '.join(filter(None,distutils.sysconfig.get_config_vars('LIBDIR'))))"`
10386-
python_ldlibrary=`${PYTHON} -c "import distutils.sysconfig; print(' '.join(filter(None,distutils.sysconfig.get_config_vars('LDLIBRARY'))))"`
10378+
python_libdir=`${PYTHON} -c "import sysconfig; print(' '.join(filter(None,sysconfig.get_config_vars('LIBDIR'))))"`
10379+
python_ldlibrary=`${PYTHON} -c "import sysconfig; print(' '.join(filter(None,sysconfig.get_config_vars('LDLIBRARY'))))"`
1038710380

1038810381
# If LDLIBRARY exists and has a shlib extension, use it verbatim.
1038910382
ldlibrary=`echo "${python_ldlibrary}" | sed -e 's/\.so$//' -e 's/\.dll$//' -e 's/\.dylib$//' -e 's/\.sl$//'`
@@ -10395,11 +10388,11 @@ else
1039510388
# Otherwise, guess the base name of the shlib.
1039610389
# LDVERSION was added in Python 3.2, before that use VERSION,
1039710390
# or failing that, $python_version from _PGAC_CHECK_PYTHON_DIRS.
10398-
python_ldversion=`${PYTHON} -c "import distutils.sysconfig; print(' '.join(filter(None,distutils.sysconfig.get_config_vars('LDVERSION'))))"`
10391+
python_ldversion=`${PYTHON} -c "import sysconfig; print(' '.join(filter(None,sysconfig.get_config_vars('LDVERSION'))))"`
1039910392
if test x"${python_ldversion}" != x""; then
1040010393
ldlibrary="python${python_ldversion}"
1040110394
else
10402-
python_version_var=`${PYTHON} -c "import distutils.sysconfig; print(' '.join(filter(None,distutils.sysconfig.get_config_vars('VERSION'))))"`
10395+
python_version_var=`${PYTHON} -c "import sysconfig; print(' '.join(filter(None,sysconfig.get_config_vars('VERSION'))))"`
1040310396
if test x"${python_version_var}" != x""; then
1040410397
ldlibrary="python${python_version_var}"
1040510398
else
@@ -10459,7 +10452,7 @@ PL/Python." "$LINENO" 5
1045910452
fi
1046010453
python_libspec="-L${python_libdir} -l${ldlibrary}"
1046110454

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

1046410457
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: ${python_libspec} ${python_additional_libs}" >&5
1046510458
$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
@@ -195,10 +195,10 @@ su - postgres
195195
To build the <application>PL/Python</application> server programming
196196
language, you need a <productname>Python</productname>
197197
installation with the header files and
198-
the <application>distutils</application> module. The minimum
199-
required version is <productname>Python</productname> 2.6.
198+
the <application>sysconfig</application> module. The minimum
199+
required version is <productname>Python</productname> 2.7.
200200
<productname>Python 3</productname> is supported if it's
201-
version 3.1 or later; but see
201+
version 3.2 or later; but see
202202
<xref linkend="plpython-python23"/>
203203
when using Python 3.
204204
</para>

0 commit comments

Comments
 (0)