From 6298ca29fd9390649222d7ee7d562cf77fb795f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 20 Apr 2023 17:09:37 +0200 Subject: [PATCH] python: add implicit DLL search paths on Windows, if they exist. This should make self-contained builds *actually* working out-of-the box, without having to fiddle with PATH or nasty copying of all DLLs somewhere inside a Python installation. --- src/python/corrade/__init__.py | 16 ++++++++++++++++ src/python/magnum/__init__.py | 4 ++++ 2 files changed, 20 insertions(+) diff --git a/src/python/corrade/__init__.py b/src/python/corrade/__init__.py index 2c06f2e..0bcf7d7 100644 --- a/src/python/corrade/__init__.py +++ b/src/python/corrade/__init__.py @@ -25,6 +25,22 @@ """Root Corrade module""" +# On Windows, if a known directory layout is detected, add paths containing +# binaries to the DLL search path +import platform +if platform.system() == 'Windows': + import os + + for directory in [ + # Prebuilt binaries from the magnum-ci repo have this file in + # python/corrade/ and DLLs in bin/ + '../../bin' + ]: + bin_path = os.path.join(os.path.dirname(__file__), directory) + if os.path.exists(bin_path): + os.add_dll_directory(bin_path) + break + from _corrade import * import sys diff --git a/src/python/magnum/__init__.py b/src/python/magnum/__init__.py index d55ae0b..1ecf70d 100644 --- a/src/python/magnum/__init__.py +++ b/src/python/magnum/__init__.py @@ -25,6 +25,10 @@ """Root Magnum module""" +# Important -- performs various platform-specific setup like adding DLL paths +# on Windows +import corrade + from _magnum import * # This feels extremely hackish, but without that it wouldn't be possible to