From 862320cfc15812bf70c4f15b92745159c5bf5acc Mon Sep 17 00:00:00 2001 From: Petter Reinholdtsen Date: Sat, 19 Oct 2024 22:33:40 +0200 Subject: [PATCH] Dropped use of depricated python3-setuptools / distutils. Make sure sysconfig.get_path("platlib") return correct path on Debian and Ubuntu systems, where /usr/lib/ should be used over /usr/local/lib. Based on e2c10a8ac20c37c231367d3731c79846082b3a53 by Andy Pugh, Fixes Debian issue #1080668. --- src/configure.ac | 19 ++++++++++++++++++- src/m4/ax_python.m4 | 2 +- src/m4/ax_python_devel.m4 | 33 ++++++++------------------------- 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/configure.ac b/src/configure.ac index 759b5b435de..3377b4100b8 100644 --- a/src/configure.ac +++ b/src/configure.ac @@ -1653,7 +1653,24 @@ fi AC_MSG_RESULT([$PYTHON_TK_VERSION]) AC_MSG_CHECKING(for site-package location) -SITEPY=`$PYTHON -c 'import distutils.sysconfig; print(distutils.sysconfig.get_python_lib())'` +case "$(lsb_release -is)" in + Debian|Ubuntu) + + # Setting DEB_PYTHON_INSTALL_LAYOUT adjust sysconfig 'platlib' path, see + # . This affect SITEPY and + # might also affect AX_PYTHON and AX_PYTHON_DEVEL. + + # The sed replacing python3.7 and similiar with python3 is to + # work with buster, which return version specific path. + # The sed replacing site-package to work with bullseye and + # older, which return ../site-packages, not .../dist-packages. + export DEB_PYTHON_INSTALL_LAYOUT=deb + SITEPY="$($PYTHON -c 'import sysconfig; import re; p2=sysconfig.get_path("platlib").replace("/site-packages", "/dist-packages"); print(re.sub(r"/python3[\.\d]+/","/python3/u", p2))')" + ;; + *) + SITEPY=`$PYTHON -c 'import distutils.sysconfig; print(distutils.sysconfig.get_python_lib())'` + ;; +esac AC_MSG_RESULT($SITEPY) AC_MSG_CHECKING(for working GLU quadrics) diff --git a/src/m4/ax_python.m4 b/src/m4/ax_python.m4 index 68dd655534e..53862678853 100644 --- a/src/m4/ax_python.m4 +++ b/src/m4/ax_python.m4 @@ -64,7 +64,7 @@ if test x$ax_python_bin != x; then AC_CHECK_LIB(${ax_python_bin}m, main, ax_python_lib=${ax_python_bin}m, ax_python_lib=no) fi if test x$ax_python_lib != xno; then - ax_python_header=`$ax_python_bin -c "from distutils.sysconfig import *; print(get_config_var('CONFINCLUDEPY'))"` + ax_python_header=`$ax_python_bin -c "import sysconfig; print(sysconfig.get_path('include'))"` if test x$ax_python_header != x; then break; fi diff --git a/src/m4/ax_python_devel.m4 b/src/m4/ax_python_devel.m4 index 1f480db6d23..1bec4142fae 100644 --- a/src/m4/ax_python_devel.m4 +++ b/src/m4/ax_python_devel.m4 @@ -186,25 +186,16 @@ variable to configure. See ``configure --help'' for reference. fi fi - if test $ax_python_devel_found = yes; then - # - # Check if you have distutils, else fail - # - AC_MSG_CHECKING([for the sysconfig Python package]) - ac_sysconfig_result=`$PYTHON -c "import sysconfig" 2>&1` - if test $? -eq 0; then + # + # Check if you have sysconfig, else fail + # + AC_MSG_CHECKING([for the sysconfig Python package]) + ac_sysconfig_result=`$PYTHON -c "import sysconfig" 2>&1` + if test $? -eq 0; then AC_MSG_RESULT([yes]) IMPORT_SYSCONFIG="import sysconfig" - else - AC_MSG_RESULT([no]) - - AC_MSG_CHECKING([for the distutils Python package]) - ac_sysconfig_result=`$PYTHON -c "from distutils import sysconfig" 2>&1` - if test $? -eq 0; then - AC_MSG_RESULT([yes]) - IMPORT_SYSCONFIG="from distutils import sysconfig" - else - AC_MSG_WARN([cannot import Python module "distutils". + else + AC_MSG_ERROR([cannot import Python module "sysconfig". Please check your Python installation. The error was: $ac_sysconfig_result]) if ! $ax_python_devel_optional; then @@ -212,8 +203,6 @@ $ac_sysconfig_result]) fi ax_python_devel_found=no PYTHON_VERSION="" - fi - fi fi if test $ax_python_devel_found = yes; then @@ -228,12 +217,6 @@ $ac_sysconfig_result]) print (sysconfig.get_path ('include'));"` plat_python_path=`$PYTHON -c "$IMPORT_SYSCONFIG; \ print (sysconfig.get_path ('platinclude'));"` - else - # old distutils way - python_path=`$PYTHON -c "$IMPORT_SYSCONFIG; \ - print (sysconfig.get_python_inc ());"` - plat_python_path=`$PYTHON -c "$IMPORT_SYSCONFIG; \ - print (sysconfig.get_python_inc (plat_specific=1));"` fi if test -n "${python_path}"; then if test "${plat_python_path}" != "${python_path}"; then