Skip to content

Commit

Permalink
Update handling of Windows DLLs in Python wrapper (#175)
Browse files Browse the repository at this point in the history
* Update ci.yml

* Update mdi.py

* Update mdi.py

* Update mdi.py

* Update mdi.py

* Update mdi.py

* Update mdi.py

* Update mdi.py

* Update mdi.py

* Update CMakeLists.txt

* Update mdi_global.h
  • Loading branch information
taylor-a-barnes authored Jan 28, 2025
1 parent 26a8626 commit 25b5892
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,9 @@ jobs:
- uses: actions/checkout@v2

# Set the Python version
- uses: actions/setup-python@v2
- uses: actions/setup-python@v5
with:
python-version: '3.6'
python-version: '3.12'

- name: Install dependencies
run: |
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ else()
endif()

project(mdi
VERSION 1.4.35
VERSION 1.4.36
LANGUAGES ${use_C} ${use_CXX} ${use_Fortran})

# Check for MPI
Expand Down
10 changes: 10 additions & 0 deletions MDI_Library/mdi.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@
mdi = ctypes.CDLL(mdi_path, ctypes.RTLD_GLOBAL)
MDI_COMMAND_LENGTH = ctypes.c_int.in_dll(mdi, "MDI_COMMAND_LENGTH").value
except (ValueError, AttributeError, OSError) as e:

# Add the path to the library to the PATH variable
os.path.dirname(mdi_path)
os.environ["PATH"] += ";" + str(mdi_path)

# On Windows, every DLL directory must be added through "add_dll_directory", or Python will refuse to open them
for p in os.environ["PATH"].split( ';' ):
if os.path.isdir( p ):
os.add_dll_directory( p )

mdi = ctypes.WinDLL(mdi_path, ctypes.RTLD_GLOBAL)
MDI_COMMAND_LENGTH = ctypes.c_int.in_dll(mdi, "MDI_COMMAND_LENGTH").value

Expand Down
2 changes: 1 addition & 1 deletion MDI_Library/mdi_global.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
// MDI version numbers
#define MDI_MAJOR_VERSION_ 1
#define MDI_MINOR_VERSION_ 4
#define MDI_PATCH_VERSION_ 35
#define MDI_PATCH_VERSION_ 36

// length of an MDI command in characters
#define MDI_COMMAND_LENGTH_ 256
Expand Down

0 comments on commit 25b5892

Please sign in to comment.