Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

BUILD: add _distributor_init.py to preload dll on windows #50

Merged
merged 1 commit into from
Jun 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ install:
build_script:
- cd numpy
- git checkout %BUILD_COMMIT%
# Create _distributor_init.py
- cd ..
- python -c "import openblas_support; openblas_support.make_init('numpy')"
- cd numpy
# Append license text relevant for the built wheel
- type ..\LICENSE_win32.txt >> LICENSE.txt
- ps: |
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*.pyc
*~
*.swp
tmp_for_test/
working/
downloads/
Expand Down
42 changes: 42 additions & 0 deletions openblas_support.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import os
import textwrap

def make_init(dirname):
'''
Create a _distributor_init.py file for OpenBlas
'''
with open(os.path.join(dirname, '_distributor_init.py'), 'wt') as fid:
fid.write(textwrap.dedent("""
'''
Helper to preload windows dlls to prevent dll not found errors.
Once a DLL is preloaded, its namespace is made available to any
subsequent DLL. This file originated in the numpy-wheels repo,
and is created as part of the scripts that build the wheel.
'''
import os
from ctypes import WinDLL
import glob
if os.name == 'nt':
# convention for storing / loading the DLL from
# numpy/.libs/, if present
try:
basedir = os.path.dirname(os.path.dirname(__file__))
except:
pass
else:
libs_dir = os.path.abspath(os.path.join(basedir, '.libs'))
DLL_filenames = []
if os.path.isdir(libs_path):
for filename in glob.glob(os.path.join(libs_dir,
'*openblas*dll')):
# NOTE: would it change behavior to load ALL
# DLLs at this path vs. the name restriction?
WinDLL(os.path.abspath(filename))
DLL_filenames.append(filename)
if len(DLL_filenames) > 1:
import warnings
warnings.warn("loaded more than 1 DLL from .libs:\\n%s" %
"\\n".join(DLL_filenames),
stacklevel=1)
"""))