From a4f6610ec9d8dae274f355772dc895bd25843ecd Mon Sep 17 00:00:00 2001 From: Daniel Weindl Date: Wed, 12 Jan 2022 21:13:11 +0100 Subject: [PATCH] Add environment variable AMICI_DLL_DIRS to control DLL directories on Windows (#1637) Since Python3.8, external DLL directories need to be added via os.add_dll_directory. This change provides the AMICI_DLL_DIRS environment variable as an alternative way to specify these directories. Also, upgrades OpenBLAS to 0.3.19 and runs Windows tests on Python 3.8. --- .github/workflows/test_windows.yml | 14 +++++++++++++- documentation/python_installation.rst | 4 ++-- scripts/installOpenBLAS.ps1 | 2 +- swig/amici.i | 11 +++++++++++ 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test_windows.yml b/.github/workflows/test_windows.yml index bf6c8d80df..72706c7ae1 100644 --- a/.github/workflows/test_windows.yml +++ b/.github/workflows/test_windows.yml @@ -9,9 +9,19 @@ jobs: env: AMICI_SKIP_CMAKE_TESTS: "TRUE" - openBLAS_version: "0.3.12" + openBLAS_version: "0.3.19" + AMICI_DLL_DIRS: "C:\\BLAS\\bin" + + strategy: + matrix: + python-version: [ "3.8" ] steps: + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - uses: actions/checkout@master - run: git fetch --prune --unshallow @@ -48,5 +58,7 @@ jobs: shell: bash run: pip install -v $(ls -t dist/amici-*.tar.gz | head -1) + - run: python -m amici + - name: Run Python tests run: python -m pytest --ignore-glob=*petab* --ignore-glob=*special* python/tests diff --git a/documentation/python_installation.rst b/documentation/python_installation.rst index 59e98dc285..5380beccde 100644 --- a/documentation/python_installation.rst +++ b/documentation/python_installation.rst @@ -268,7 +268,7 @@ by MSVC (see Visual Studio above). ``KERNEL32.dll`` is part of Windows and in .. note:: - Since Python 3.8, the library directory needs to be set as follows: + Since Python 3.8, the library directory needs to be set either from Python: .. code-block:: python @@ -277,7 +277,7 @@ by MSVC (see Visual Studio above). ``KERNEL32.dll`` is part of Windows and in os.add_dll_directory("C:\\BLAS\\bin") import amici - Adding it to ``PATH`` will not work. + or via the environment variable ``AMICI_DLL_DIRS``. Further topics ++++++++++++++ diff --git a/scripts/installOpenBLAS.ps1 b/scripts/installOpenBLAS.ps1 index 11f0e931fa..22cccbdbac 100644 --- a/scripts/installOpenBLAS.ps1 +++ b/scripts/installOpenBLAS.ps1 @@ -1,5 +1,5 @@ Write-Host 'script installOpenBLAS.ps1 started' -$version = '0.3.12' +$version = '0.3.19' New-Item -Path 'C:\BLAS' -ItemType Directory -Force # create directory # Enforce stronger cryptography [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12 diff --git a/swig/amici.i b/swig/amici.i index 09b74411b9..f62845e62f 100644 --- a/swig/amici.i +++ b/swig/amici.i @@ -189,6 +189,17 @@ RDataReporting = enum('RDataReporting') %template(SteadyStateStatusVector) std::vector; +%pythonbegin %{ +import sys +import os + +if sys.platform == 'win32': + for dll_dir in os.environ.get("AMICI_DLL_DIRS", "").split(os.pathsep): + os.add_dll_directory(dll_dir) + +%} + + // add module docstring and import additional types for typehints %pythonbegin %{ """