[PATCH gnupgpy 5/5] build: Remove distutils related code from configure macros

Lucas via Gnupg-devel <[email protected]>
Newsgroups gmane.comp.encryption.gpg.devel
Message-ID <e328beb58d5b6ae8000fa923fb27355a03a04c10.1742770151.git.lucc@posteo.de>
* m4/ax_python_devel.m4, m4/python.m4: Remove all distutils related code
and only check for the stdlib sysconfig module instead.
--

Signed-off-by: Lucas Hoffmann <[email protected]>
---
 m4/ax_python_devel.m4 | 66 ++++++++++++-------------------------------
 m4/python.m4          | 42 ++++++---------------------
 2 files changed, 26 insertions(+), 82 deletions(-)

_______________________________________________
Gnupg-devel mailing list
[email protected]
https://lists.gnupg.org/mailman/listinfo/gnupg-devel
0005-build-Remove-distutils-related-code-from-configure-m.patch (text/x-patch, 8 KB)
diff --git a/m4/ax_python_devel.m4 b/m4/ax_python_devel.m4
index ca6f4cf..6d2a1f2 100644
--- a/m4/ax_python_devel.m4
+++ b/m4/ax_python_devel.m4
@@ -188,31 +188,22 @@ variable to configure. See ``configure --help'' for reference.
 
 	if test $ax_python_devel_found = yes; then
 	   #
-	   # Check if you have distutils, else fail
+	   # 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".
+		AC_MSG_WARN([cannot import Python module "sysconfig".
 Please check your Python installation. The error was:
 $ac_sysconfig_result])
-			if ! $ax_python_devel_optional; then
-			   AC_MSG_ERROR([Giving up])
-			fi
-			ax_python_devel_found=no
-			PYTHON_VERSION=""
+		if ! $ax_python_devel_optional; then
+		   AC_MSG_ERROR([Giving up])
 		fi
+		ax_python_devel_found=no
+		PYTHON_VERSION=""
 	   fi
 	fi
 
@@ -222,19 +213,10 @@ $ac_sysconfig_result])
 	   #
 	   AC_MSG_CHECKING([for Python include path])
 	   if test -z "$PYTHON_CPPFLAGS"; then
-		if test "$IMPORT_SYSCONFIG" = "import sysconfig"; then
-			# sysconfig module has different functions
-			python_path=`$PYTHON -c "$IMPORT_SYSCONFIG; \
-				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
+		python_path=`$PYTHON -c "import sysconfig; \
+			print (sysconfig.get_path ('include'));"`
+		plat_python_path=`$PYTHON -c "import sysconfig; \
+			print (sysconfig.get_path ('platinclude'));"`
 		if test -n "${python_path}"; then
 			if test "${plat_python_path}" != "${python_path}"; then
 				python_path="-I$python_path -I$plat_python_path"
@@ -284,7 +266,7 @@ EOD`
 		ac_python_libdir=`cat<<EOD | $PYTHON -
 
 # There should be only one
-$IMPORT_SYSCONFIG
+import sysconfig
 e = sysconfig.get_config_var('LIBDIR')
 if e is not None:
 	print (e)
@@ -293,7 +275,7 @@ EOD`
 		# Now, for the library:
 		ac_python_library=`cat<<EOD | $PYTHON -
 
-$IMPORT_SYSCONFIG
+import sysconfig
 c = sysconfig.get_config_vars()
 if 'LDVERSION' in c:
 	print ('python'+c[['LDVERSION']])
@@ -342,9 +324,8 @@ EOD`
 	   #
 	   AC_MSG_CHECKING([for Python site-packages path])
 	   if test -z "$PYTHON_SITE_PKG"; then
-		if test "$IMPORT_SYSCONFIG" = "import sysconfig"; then
-			PYTHON_SITE_PKG=`$PYTHON -c "
-$IMPORT_SYSCONFIG;
+		PYTHON_SITE_PKG=`$PYTHON -c "
+import sysconfig;
 if hasattr(sysconfig, 'get_default_scheme'):
     scheme = sysconfig.get_default_scheme()
 else:
@@ -357,11 +338,6 @@ if prefix == 'NONE':
     prefix = '$ac_default_prefix'
 sitedir = sysconfig.get_path('purelib', scheme, vars={'base': prefix})
 print(sitedir)"`
-		else
-			# distutils.sysconfig way
-			PYTHON_SITE_PKG=`$PYTHON -c "$IMPORT_SYSCONFIG; \
-				print (sysconfig.get_python_lib(0,0));"`
-		fi
 	   fi
 	   AC_MSG_RESULT([$PYTHON_SITE_PKG])
 	   AC_SUBST([PYTHON_SITE_PKG])
@@ -371,9 +347,8 @@ print(sitedir)"`
 	   #
 	   AC_MSG_CHECKING([for Python platform specific site-packages path])
 	   if test -z "$PYTHON_PLATFORM_SITE_PKG"; then
-		if test "$IMPORT_SYSCONFIG" = "import sysconfig"; then
-			PYTHON_PLATFORM_SITE_PKG=`$PYTHON -c "
-$IMPORT_SYSCONFIG;
+		PYTHON_PLATFORM_SITE_PKG=`$PYTHON -c "
+import sysconfig;
 if hasattr(sysconfig, 'get_default_scheme'):
     scheme = sysconfig.get_default_scheme()
 else:
@@ -386,11 +361,6 @@ if prefix == 'NONE':
     prefix = '$ac_default_prefix'
 sitedir = sysconfig.get_path('platlib', scheme, vars={'platbase': prefix})
 print(sitedir)"`
-		else
-			# distutils.sysconfig way
-			PYTHON_PLATFORM_SITE_PKG=`$PYTHON -c "$IMPORT_SYSCONFIG; \
-				print (sysconfig.get_python_lib(1,0));"`
-		fi
 	   fi
 	   AC_MSG_RESULT([$PYTHON_PLATFORM_SITE_PKG])
 	   AC_SUBST([PYTHON_PLATFORM_SITE_PKG])
@@ -400,7 +370,7 @@ print(sitedir)"`
 	   #
 	   AC_MSG_CHECKING(python extra libraries)
 	   if test -z "$PYTHON_EXTRA_LIBS"; then
-	      PYTHON_EXTRA_LIBS=`$PYTHON -c "$IMPORT_SYSCONFIG; \
+	      PYTHON_EXTRA_LIBS=`$PYTHON -c "import sysconfig; \
                 conf = sysconfig.get_config_var; \
                 print (conf('LIBS') + ' ' + conf('SYSLIBS'))"`
 	   fi
@@ -412,7 +382,7 @@ print(sitedir)"`
 	   #
 	   AC_MSG_CHECKING(python extra linking flags)
 	   if test -z "$PYTHON_EXTRA_LDFLAGS"; then
-		PYTHON_EXTRA_LDFLAGS=`$PYTHON -c "$IMPORT_SYSCONFIG; \
+		PYTHON_EXTRA_LDFLAGS=`$PYTHON -c "import sysconfig; \
 			conf = sysconfig.get_config_var; \
 			print (conf('LINKFORSHARED'))"`
 		# Hack for macos, it sticks this in here.
diff --git a/m4/python.m4 b/m4/python.m4
index cc63831..4f6fd50 100644
--- a/m4/python.m4
+++ b/m4/python.m4
@@ -218,33 +218,13 @@ AC_DEFUN([AM_PATH_PYTHON],
   # Substituting python_exec_prefix_subst.
   AC_SUBST([PYTHON_EXEC_PREFIX], [$am_python_exec_prefix_subst])
 
-  # Factor out some code duplication into this shell variable.
-  am_python_setup_sysconfig="\
-import sys
-# Prefer sysconfig over distutils.sysconfig, for better compatibility
-# with python 3.x.  See automake bug#10227.
-try:
-    import sysconfig
-except ImportError:
-    can_use_sysconfig = 0
-else:
-    can_use_sysconfig = 1
-# Can't use sysconfig in CPython 2.7, since it's broken in virtualenvs:
-# <https://github.com/pypa/virtualenv/issues/118>
-try:
-    from platform import python_implementation
-    if python_implementation() == 'CPython' and sys.version[[:3]] == '2.7':
-        can_use_sysconfig = 0
-except ImportError:
-    pass" # end of am_python_setup_sysconfig
-
   dnl emacs-page Set up 4 directories:
 
   dnl 1. pythondir: where to install python scripts.  This is the
   dnl    site-packages directory, not the python standard library
   dnl    directory as in early automake betas.  This behavior
   dnl    is more consistent with lispdir.m4 for example.
-  dnl Query sysconfig or distutils (per above) for this directory.
+  dnl Query sysconfig for this directory.
   dnl
   AC_CACHE_CHECK([for $am_display_PYTHON script directory (pythondir)],
   [am_cv_python_pythondir],
@@ -254,12 +234,9 @@ except ImportError:
      am_py_prefix=$am_cv_python_prefix
    fi
    am_cv_python_pythondir=`$PYTHON -c "
-$am_python_setup_sysconfig
-if can_use_sysconfig:
-  sitedir = sysconfig.get_path('purelib', vars={'base':'$am_py_prefix'})
-else:
-  from distutils import sysconfig
-  sitedir = sysconfig.get_python_lib(0, 0, prefix='$am_py_prefix')
+import sys
+import sysconfig
+sitedir = sysconfig.get_path('purelib', vars={'base':'$am_py_prefix'})
 sys.stdout.write(sitedir)"`
    #
    case $am_cv_python_pythondir in
@@ -286,7 +263,7 @@ sys.stdout.write(sitedir)"`
 
   dnl 3. pyexecdir: directory for installing python extension modules
   dnl    (shared libraries).
-  dnl Query sysconfig or distutils for this directory.
+  dnl Query sysconfig for this directory.
   dnl Much of this is the same as for prefix setup above.
   dnl
   AC_CACHE_CHECK([for $am_display_PYTHON extension module directory (pyexecdir)],
@@ -297,12 +274,9 @@ sys.stdout.write(sitedir)"`
      am_py_exec_prefix=$am_cv_python_exec_prefix
    fi
    am_cv_python_pyexecdir=`$PYTHON -c "
-$am_python_setup_sysconfig
-if can_use_sysconfig:
-  sitedir = sysconfig.get_path('platlib', vars={'platbase':'$am_py_exec_prefix'})
-else:
-  from distutils import sysconfig
-  sitedir = sysconfig.get_python_lib(1, 0, prefix='$am_py_exec_prefix')
+import sys
+import sysconfig
+sitedir = sysconfig.get_path('platlib', vars={'platbase':'$am_py_exec_prefix'})
 sys.stdout.write(sitedir)"`
    #
    case $am_cv_python_pyexecdir in
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.