From 3471c22f52a396fc04eb064eb363afa8f098cd6a Mon Sep 17 00:00:00 2001 From: Chun-wei Fan Date: Mon, 25 Apr 2022 15:28:44 +0800 Subject: [PATCH 1/2] testsuite: Fix introspection test on Windows ...when we are using Python 3.8.x or later. Python 3.8.x or later on Windows require one to call os.add_dll_directory() on every directory that contains dependent non-system DLLs of a module that are not bundled/installed with the module. Since we are very likely running programs that rely on dependent items in %PATH%, make things easier for people by calling os.add_dll_directory() on all the valid paths in %PATH% in api.py, so that the test will run successfully on Windows with Python 3.8.x or later. --- testsuite/introspection/api.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/testsuite/introspection/api.py b/testsuite/introspection/api.py index c35b2b7448..a0afd6be57 100755 --- a/testsuite/introspection/api.py +++ b/testsuite/introspection/api.py @@ -1,6 +1,19 @@ #! /usr/bin/env python3 +import os import sys + +# Python 3.8.x or later on Windows require os.add_dll_directory() +# to be called on every directory that contains the required +# non-bundled, non-system DLLs of a module so that the module can +# be loaded successfully by Python. Make things easiler for people +# by calling os.add_dll_directory() on the valid paths in %PATH%. +if hasattr(os, 'add_dll_directory'): + paths = os.environ['PATH'].split(os.pathsep) + for path in paths: + if path != '' and os.path.isdir(path): + os.add_dll_directory(path) + import gi gi.require_version('Gtk', '4.0') From 65a7df47f20913caa6b051e19b558ebcad4fe083 Mon Sep 17 00:00:00 2001 From: Chun-wei Fan Date: Tue, 26 Apr 2022 11:19:16 +0800 Subject: [PATCH 2/2] Introspection test: Reverse os.add_dll_directory() order It looks like os.add_dll_directory() works in a LIFO order, so we call os.add_dll_directory() from the end of the list of directories in %PATH% so that the directories are searched in the correct order. --- testsuite/introspection/api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testsuite/introspection/api.py b/testsuite/introspection/api.py index a0afd6be57..a2feac37ea 100755 --- a/testsuite/introspection/api.py +++ b/testsuite/introspection/api.py @@ -9,7 +9,7 @@ import sys # be loaded successfully by Python. Make things easiler for people # by calling os.add_dll_directory() on the valid paths in %PATH%. if hasattr(os, 'add_dll_directory'): - paths = os.environ['PATH'].split(os.pathsep) + paths = reversed(os.environ['PATH'].split(os.pathsep)) for path in paths: if path != '' and os.path.isdir(path): os.add_dll_directory(path)