|
12 | 12 | import math
|
13 | 13 | from ctypes import POINTER, c_int, c_double, Structure, pointer
|
14 | 14 | from collections import namedtuple
|
| 15 | +import platform |
15 | 16 | import os
|
16 |
| -#from distutils.sysconfig import get_config_var |
17 |
| - |
18 |
| -from sys import platform |
19 |
| - |
20 |
| -libext = None #get_config_var('EXT_SUFFIX') |
21 |
| -if libext is None or libext == '': |
22 |
| - if platform == "linux" or platform == "linux2": |
23 |
| - libext = '.so' |
24 |
| - elif platform == "darwin": |
25 |
| - libext = '.dylib' |
26 |
| - #libext = '.so' |
27 |
| - elif platform == "win32": |
28 |
| - libext = '.dll' |
29 |
| - #libext = '.pyd' |
30 |
| - elif platform == "cygwin": |
31 |
| - libext = '.dll' |
32 |
| - |
33 |
| -libname = '_pyframe3dd' + libext |
| 17 | +import sysconfig |
| 18 | +import sys |
| 19 | + |
| 20 | +if platform.system() == "Windows": |
| 21 | + lib_ext = ".dll" |
| 22 | +elif platform.system() == "Darwin": |
| 23 | + lib_ext = ".dylib" |
| 24 | +else: |
| 25 | + lib_ext = ".so" |
| 26 | + |
| 27 | +libname = '_pyframe3dd' + lib_ext |
| 28 | + |
| 29 | +pyframe3dd_dir = os.path.dirname( os.path.abspath(__file__) ) |
| 30 | + |
| 31 | +lib_opt = [os.path.join(pyframe3dd_dir, libname), # pip installs (regular and editable) |
| 32 | + os.path.join(os.path.dirname( os.path.dirname( pyframe3dd_dir )), "local", "lib", libname), # WEIS library |
| 33 | + os.path.join(os.path.dirname( sysconfig.get_path('stdlib') ), libname), # conda installs |
| 34 | + os.path.join(os.path.dirname( sysconfig.get_path('stdlib') ), "lib", libname), # conda installs |
| 35 | + os.path.join(os.path.dirname( sysconfig.get_path('stdlib') ), "Library", "lib", libname), # conda installs |
| 36 | + os.path.join( sysconfig.get_path('platlib'), "pyframe3dd", "lib", libname), # system-wide pip installs |
| 37 | + os.path.join( sysconfig.get_config_var("userbase"), "lib", "python", "site-packages", "pyframe3dd", libname), # system wide local |
| 38 | + ] |
| 39 | + |
| 40 | +for p in sys.meta_path: |
| 41 | + if "_build_path" in p.__dict__: |
| 42 | + lib_opt += [os.path.join(p._build_path, "pyframe3dd", libname)] |
| 43 | + |
| 44 | +lib_path = None |
| 45 | +for p in lib_opt: |
| 46 | + if os.path.exists(p): |
| 47 | + lib_path = str(p) |
| 48 | + break |
| 49 | + |
| 50 | +if lib_path is None: |
| 51 | + raise Exception(f"Cannot find {libname} in {lib_opt}") |
34 | 52 |
|
35 | 53 | c_int_p = POINTER(c_int)
|
36 | 54 | c_double_p = POINTER(c_double)
|
@@ -446,12 +464,10 @@ def __init__(self, nodes, reactions, elements, options):
|
446 | 464 |
|
447 | 465 |
|
448 | 466 | # load c module
|
449 |
| - mydir = os.path.dirname(os.path.realpath(__file__)) # get path to this file |
450 |
| - try: |
451 |
| - self._pyframe3dd = np.ctypeslib.load_library(libname, mydir) |
452 |
| - except: |
453 |
| - mydir = os.path.abspath(os.path.dirname(mydir)) |
454 |
| - self._pyframe3dd = np.ctypeslib.load_library(libname, mydir) |
| 467 | + #mydir = impresources.files(pyframe3dd) |
| 468 | + #with impresources.as_file(mydir) as f: |
| 469 | + # print(f) |
| 470 | + self._pyframe3dd = np.ctypeslib.load_library(libname, os.path.dirname(lib_path)) |
455 | 471 |
|
456 | 472 | self._pyframe3dd.run.argtypes = [POINTER(C_Nodes), POINTER(C_Reactions), POINTER(C_Elements),
|
457 | 473 | POINTER(C_OtherElementData), c_int, POINTER(C_LoadCase),
|
|
0 commit comments