[pygobject] tests: Support CPython 3.8 on Windows



commit 0f3ba012512acfd74e5942ff6858c22611c4a79a
Author: Christoph Reiter <reiter christoph gmail com>
Date:   Sat Apr 9 12:20:10 2022 +0200

    tests: Support CPython 3.8 on Windows
    
    Python 3.8 no longer uses PATH for searching DLLs so we have to
    add them manually.
    
    Note that unlike PATH add_dll_directory() has no defined order,
    so if there are two same DLLs in PATH we might get a random one.
    
    This only makes sure that 'setup.py test' and 'pytest' continue working.
    If you include pygobject manually you have to call os.add_dll_directory()
    yourself with the location of the DLLs you ship.

 tests/__init__.py | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
---
diff --git a/tests/__init__.py b/tests/__init__.py
index 2bcb52e7..a7b7ff22 100644
--- a/tests/__init__.py
+++ b/tests/__init__.py
@@ -6,8 +6,24 @@ import atexit
 import warnings
 
 
+def set_dll_search_path():
+    # Python 3.8 no longer searches for DLLs in PATH, so we have to add
+    # everything in PATH manually. Note that unlike PATH add_dll_directory
+    # has no defined order, so if there are two cairo DLLs in PATH we
+    # might get a random one.
+    if os.name != "nt" or not hasattr(os, "add_dll_directory"):
+        return
+    for p in os.environ.get("PATH", "").split(os.pathsep):
+        try:
+            os.add_dll_directory(p)
+        except OSError:
+            pass
+
+
 def init_test_environ():
 
+    set_dll_search_path()
+
     def dbus_launch_session():
         if os.name == "nt" or sys.platform == "darwin":
             return (-1, "")


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]