From 5844d9e700239ad10a5956cd7789bd02360bb0fa Mon Sep 17 00:00:00 2001 From: Ben Greiner Date: Wed, 29 May 2024 15:17:58 +0200 Subject: [PATCH] build,python: Build Python bindings without distutils * m4/python.m4: Add python3.12 and 3.11 as valid interpreters, remove EOL 3.4, 3.5, 3.7 (keep 3.6 because some distributions still ship and maintain it). * lang/python/Makefile.am (clean-local): Remove dist and gpg.egg-info created by Python 3.9+ on make install. * lang/python/setup.py.in: switch from distutils to setuptools where possible, remove obsolete and deprecated -py3 option of swig, add classifiers up to 3.12, remove 3.4, 3.5, 3.7. * lang/python/doc/src/gpgme-python-howto.org: replace distutils with setuptools * lang/python/examples/howto/advanced/cython/setup.py: replace distutils with setuptools -- This fixes building the Python bindings for Python 3.12 where distutils has been removed. Based on D545 --- lang/python/Makefile.am | 2 +- lang/python/doc/src/gpgme-python-howto.org | 2 +- .../examples/howto/advanced/cython/setup.py | 2 +- lang/python/setup.py.in | 19 ++++++++++++------- m4/python.m4 | 6 +++--- 5 files changed, 18 insertions(+), 13 deletions(-) diff --git a/lang/python/Makefile.am b/lang/python/Makefile.am index 68b98e8e..84b39c53 100644 --- a/lang/python/Makefile.am +++ b/lang/python/Makefile.am @@ -80,7 +80,7 @@ CLEANFILES = copystamp \ # 'make distclean' clears the write bit, breaking rm -rf. Fix the # permissions. clean-local: - rm -rf -- build + rm -rf -- build dist gpg.egg-info for PYTHON in $(PYTHONS); do \ find "$$(basename "$${PYTHON}")-gpg" -type d ! -perm -200 -exec chmod u+w {} ';' ; \ rm -rf -- "$$(basename "$${PYTHON}")-gpg" ; \ diff --git a/lang/python/doc/src/gpgme-python-howto.org b/lang/python/doc/src/gpgme-python-howto.org index b4367872..c40e2249 100644 --- a/lang/python/doc/src/gpgme-python-howto.org +++ b/lang/python/doc/src/gpgme-python-howto.org @@ -2945,7 +2945,7 @@ Save that into a file called =keycount.pyx= and then create a =setup.py= file which contains this: #+BEGIN_SRC python -i -from distutils.core import setup +from setuptools import setup from Cython.Build import cythonize setup( diff --git a/lang/python/examples/howto/advanced/cython/setup.py b/lang/python/examples/howto/advanced/cython/setup.py index f8dce034..849639e2 100644 --- a/lang/python/examples/howto/advanced/cython/setup.py +++ b/lang/python/examples/howto/advanced/cython/setup.py @@ -1,4 +1,4 @@ -from distutils.core import setup +from setuptools import setup from Cython.Build import cythonize setup( diff --git a/lang/python/setup.py.in b/lang/python/setup.py.in index 6f36861d..7b64ba7b 100755 --- a/lang/python/setup.py.in +++ b/lang/python/setup.py.in @@ -18,8 +18,12 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -from distutils.core import setup, Extension -from distutils.command.build import build +try: + from setuptools import setup, Extension + from setuptools.command.build import build +except ImportError: + from distutils.core import setup, Extension + from distutils.command.build import build import glob import os @@ -225,9 +229,8 @@ class BuildExtFirstHack(build): build.run(self) -py3 = [] if sys.version_info.major < 3 else ['-py3'] swig_sources = [] -swig_opts = ['-threads'] + py3 + extra_swig_opts +swig_opts = ['-threads'] + extra_swig_opts swige = Extension( 'gpg._gpgme', sources=swig_sources, @@ -282,10 +285,12 @@ GPGME and these bindings is available here: 'Programming Language :: Python :: 2', 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.4', - 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', - 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.8', + 'Programming Language :: Python :: 3.9', + 'Programming Language :: Python :: 3.10', + 'Programming Language :: Python :: 3.11', + 'Programming Language :: Python :: 3.12', 'Operating System :: POSIX', 'Operating System :: Microsoft :: Windows', 'Topic :: Communications :: Email', diff --git a/m4/python.m4 b/m4/python.m4 index 4b9483c0..a9ace09b 100644 --- a/m4/python.m4 +++ b/m4/python.m4 @@ -36,12 +36,12 @@ # numbers and dots only. AC_DEFUN([AM_PATH_PYTHON], [ - dnl Find a Python interpreter. Python versions prior to 2.7 are not - dnl supported. Python 3.0 through to Python 3.3 are also not supported. + dnl Find a Python interpreter. Python versions prior to 3.8 are + dnl end-of-life and not supported, with the exception of 2.7 and 3.6. m4_define_default([_AM_PYTHON_INTERPRETER_LIST], [python2 python2.7 dnl python dnl - python3 python3.10 python3.9 python3.8 python3.7 python3.6 python3.5 python3.4 + python3 python3.12 python3.11 python3.10 python3.9 python3.8 python3.6 ]) AC_ARG_VAR([PYTHON], [the Python interpreter])