This is an automated email from the ASF dual-hosted git repository.

astitcher pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/qpid-proton.git


The following commit(s) were added to refs/heads/main by this push:
     new ba49d2309 PROTON-2755: Make python code and binding work with python 
3.12
ba49d2309 is described below

commit ba49d2309c5a1abf0afcaad6d61d48fc5a6b7b85
Author: Andrew Stitcher <astitc...@apache.org>
AuthorDate: Fri Jul 14 15:40:37 2023 -0400

    PROTON-2755: Make python code and binding work with python 3.12
    
    - Fix test venv to install setuptools as that is no longer installed by 
default
    - Fix the bindings extension builder not use distutils as that is now 
removed
    - Fix remaining uses of assertEquals->assertEqual as that changed long ago!
    - Use importlib to look for modules as that has been the correct way since
      python 3.1 and pkgutil is now deprecated
    - Add py312 to the tox tests
---
 python/CMakeLists.txt                       |  2 +-
 python/ext_build.py                         |  7 ++-----
 python/tests/proton_tests/utils.py          | 17 +++++++++--------
 python/tox.ini                              |  2 +-
 tools/cmake/Modules/CheckPythonModule.cmake |  2 +-
 5 files changed, 14 insertions(+), 16 deletions(-)

diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt
index a2480b795..1972772f8 100644
--- a/python/CMakeLists.txt
+++ b/python/CMakeLists.txt
@@ -198,7 +198,7 @@ if (BUILD_TESTING)
   add_custom_command(
     OUTPUT ${pytest_venv}/env.txt
     COMMAND ${Python_EXECUTABLE} -m venv ${pytest_venv}
-    COMMAND ${pytest_executable} -m pip install --disable-pip-version-check 
cffi
+    COMMAND ${pytest_executable} -m pip install --disable-pip-version-check 
cffi setuptools
     COMMAND ${pytest_executable} -m pip freeze > ${pytest_venv}/env.txt
     BYPRODUCTS ${pytest_executable}
   )
diff --git a/python/ext_build.py b/python/ext_build.py
index 8590cdb37..7247366a1 100644
--- a/python/ext_build.py
+++ b/python/ext_build.py
@@ -21,7 +21,6 @@ import os
 
 import cffi.pkgconfig
 
-from distutils import ccompiler
 from cffi import FFI
 
 
@@ -46,13 +45,11 @@ for root, _, files in os.walk(proton_core_src):
         if file_.endswith(('.c', '.cpp')):
             sources.append(os.path.join(root, file_))
 
-compiler_type = ccompiler.get_default_compiler()
-
-if compiler_type == 'msvc':
+if os.name == 'nt':
     sources += [
         os.path.join(proton_c_src, 'compiler', 'msvc', 'start.c')
     ]
-elif compiler_type == 'unix':
+elif os.name == 'posix':
     sources += [
         os.path.join(proton_c_src, 'compiler', 'gcc', 'start.c')
     ]
diff --git a/python/tests/proton_tests/utils.py 
b/python/tests/proton_tests/utils.py
index 0b8d059b2..ba3439fc5 100644
--- a/python/tests/proton_tests/utils.py
+++ b/python/tests/proton_tests/utils.py
@@ -48,6 +48,7 @@ class EchoServer(MessagingHandler, Thread):
         self.timeout = timeout
         self.url = url
         self.senders = {}
+        self.acceptor = None
         self.container = None
         self.event = Event()
 
@@ -110,8 +111,8 @@ class SyncRequestResponseTest(Test):
             for i in range(5):
                 body = "%s%s" % (name, i)
                 response = client.call(Message(address=address, body=body))
-                self.assertEquals(response.address, client.reply_to)
-                self.assertEquals(response.body, body)
+                self.assertEqual(response.address, client.reply_to)
+                self.assertEqual(response.body, body)
 
         server = EchoServer(Url(host="127.0.0.1", port=free_tcp_port()), 
self.timeout)
         server.start()
@@ -134,9 +135,9 @@ class SyncRequestResponseTest(Test):
         client = SyncRequestResponse(connection)
         client.connection.close()
         server.join(timeout=self.timeout)
-        self.assertEquals(server.properties_received, True)
-        self.assertEquals(server.offered_capabilities_received, True)
-        self.assertEquals(server.desired_capabilities_received, True)
+        self.assertEqual(server.properties_received, True)
+        self.assertEqual(server.offered_capabilities_received, True)
+        self.assertEqual(server.desired_capabilities_received, True)
 
     def test_allowed_mechs_external(self):
         # All this test does it make sure that if we pass allowed_mechs to 
BlockingConnection, it is actually used.
@@ -166,6 +167,6 @@ class SyncRequestResponseTest(Test):
         client = SyncRequestResponse(connection)
         client.connection.close()
         server.join(timeout=self.timeout)
-        self.assertEquals(server.properties_received, True)
-        self.assertEquals(server.offered_capabilities_received, True)
-        self.assertEquals(server.desired_capabilities_received, True)
+        self.assertEqual(server.properties_received, True)
+        self.assertEqual(server.offered_capabilities_received, True)
+        self.assertEqual(server.desired_capabilities_received, True)
diff --git a/python/tox.ini b/python/tox.ini
index 8c122344f..f47890069 100644
--- a/python/tox.ini
+++ b/python/tox.ini
@@ -1,6 +1,6 @@
 [tox]
 # This will be overridden by ctest setting TOXENV for anything but this default
-envlist = py38,py39,py310,py311
+envlist = py38,py39,py310,py311,py312
 minversion = 1.7.2
 skip_missing_interpreters = True
 
diff --git a/tools/cmake/Modules/CheckPythonModule.cmake 
b/tools/cmake/Modules/CheckPythonModule.cmake
index 9000364cc..14ef075a5 100644
--- a/tools/cmake/Modules/CheckPythonModule.cmake
+++ b/tools/cmake/Modules/CheckPythonModule.cmake
@@ -39,7 +39,7 @@
 macro (CHECK_PYTHON_MODULE MODULE VARIABLE)
   if (NOT ${VARIABLE} AND Python_EXECUTABLE)
     execute_process(
-      COMMAND ${Python_EXECUTABLE} -c "import sys, pkgutil; sys.exit(0 if 
pkgutil.find_loader('${MODULE}') else 1)"
+      COMMAND ${Python_EXECUTABLE} -c "import sys, importlib.util; sys.exit(0 
if importlib.util.find_spec('${MODULE}') else 1)"
       RESULT_VARIABLE RESULT)
     if (RESULT EQUAL 0)
       if(NOT CMAKE_REQUIRED_QUIET)


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org
For additional commands, e-mail: commits-h...@qpid.apache.org

Reply via email to