From 17671bede152938e24d0f1e3e10ee1efe56bd598 Mon Sep 17 00:00:00 2001 From: Axel Huebl Date: Wed, 16 Nov 2022 11:15:32 -0600 Subject: [PATCH] Windows: Add PATH to .dll directories Python 3.8+ on Windows: DLL search paths for dependent shared libraries. Refs.: - https://github.com/python/cpython/issues/80266 - https://docs.python.org/3.8/library/os.html#os.add_dll_directory --- .github/workflows/windows.yml | 1 + src/amrex/__init__.py | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 623021f9..aca7f2a1 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -58,4 +58,5 @@ jobs: if(!$?) { Exit $LASTEXITCODE } - name: Unit tests run: | + set PATH="C:/Program Files (x86)/pyAMReX/bin/;%PATH%" ctest --test-dir build -C Debug --output-on-failure diff --git a/src/amrex/__init__.py b/src/amrex/__init__.py index f79a5eba..a22aac17 100644 --- a/src/amrex/__init__.py +++ b/src/amrex/__init__.py @@ -1,3 +1,21 @@ +import os + +# Python 3.8+ on Windows: DLL search paths for dependent +# shared libraries +# Refs.: +# - https://github.com/python/cpython/issues/80266 +# - https://docs.python.org/3.8/library/os.html#os.add_dll_directory +if os.name == "nt": + # add anything in the current directory + pwd = __file__.rsplit(os.sep, 1)[0] + os.sep + os.add_dll_directory(pwd) + # add anything in PATH + paths = os.environ.get("PATH", "") + for p in paths.split(";"): + if os.path.exists(p): + os.add_dll_directory(p) + +# import core bindings to C++ from . import amrex_pybind from .amrex_pybind import * # noqa