1- import sys
2- import os
3-
4- if os .name == 'nt' :
5- # Manually load dlls before loading the extension modules.
6- # This is handled via rpaths on Unix based systems.
7- import ctypes
8- import os .path
9- def load_dynd_dll (rootpath ):
10- try :
11- ctypes .cdll .LoadLibrary (os .path .join (rootpath , 'libdyndt.dll' ))
12- return True
13- except OSError :
14- return False
15- # If libdyndt.dll has been placed in the dynd-python installation, use that
16- ndtdir = os .path .dirname (os .path .dirname (__file__ ))
17- loaded = load_dynd_dll (ndtdir )
18- # Next, try the default DLL search path
19- loaded = loaded or load_dynd_dll ('' )
20- if not loaded :
21- # Try to load it from the Program Files directories where libdynd
22- # installs by default. This matches the search path for libdynd used
23- # in the CMake build for dynd-python.
24- is_64_bit = sys .maxsize > 2 ** 32
25- processor_arch = os .environ .get ('PROCESSOR_ARCHITECTURE' )
26- err_str = ('Fallback search for libdyndt.dll failed because the "{}" '
27- 'environment variable was not set. Please make sure that '
28- 'either libdyndt is on the DLL search path or that it is '
29- 'in the default install directory and the runtime '
30- 'environment has the necessary system-specified '
31- 'environment variables properly set. On 64 bit Windows '
32- 'with 64 bit Python the needed variables are '
33- '"PROCESSOR_ARCHITECTURE" and "ProgramFiles". On 64 bit '
34- 'Windows with 32 bit Python the needed variables are '
35- '"PROCESSOR_ARCHITECTURE" and "ProgramFiles(x86)". On 32 '
36- 'bit Windows the needed variables are '
37- '"PROCESSOR_ARCHITECTURE" and "ProgramFiles".' )
38- if processor_arch is None :
39- raise RuntimeError (err_str .format ('PROCESSOR_ARCHITECTURE' ))
40- is_32_on_64_bit = (is_64_bit and not processor_arch .endswith ('64' ))
41- if not is_32_on_64_bit :
42- prog_files = os .environ .get ('ProgramFiles' )
43- if prog_files is None :
44- raise RuntimeError (err_str .format ('ProgramFiles' ))
45- else :
46- prog_files = os .environ .get ('ProgramFiles(x86)' )
47- if prog_files is None :
48- raise RuntimeError (err_str .format ('ProgramFiles(x86)' ))
49- dynd_lib_dir = os .path .join (prog_files , 'libdynd' , 'lib' )
50- if os .path .isdir (dynd_lib_dir ):
51- loaded = load_dynd_dll (dynd_lib_dir )
52- if not loaded :
53- raise ctypes .WinError (126 , 'Could not load libdyndt.dll' )
1+ from .. import common # ensure that libdyndt is loaded
542
553from .type import make_fixed_bytes , make_fixed_string , make_struct , \
564 make_fixed_dim , make_string , make_var_dim , make_fixed_dim_kind , \
@@ -63,6 +11,3 @@ def load_dynd_dll(rootpath):
6311from . import dynd_ctypes as ctypes
6412
6513from . import json
66-
67- del os
68- del sys
0 commit comments