Skip to content

Commit 47d4639

Browse files
committed
more robust name finding
1 parent 065f619 commit 47d4639

File tree

4 files changed

+43
-27
lines changed

4 files changed

+43
-27
lines changed

meson.build

-2
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,3 @@ message(py3.path())
3131
message(py3.get_install_dir())
3232

3333
subdir('pyframe3dd')
34-
35-

pyframe3dd/__init__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from .pyframe3dd import Frame, StaticLoadCase, NodeData, ReactionData, ElementData, Options
2-
#import frame3dd
2+
3+
34

45

pyframe3dd/pyframe3dd.py

+40-24
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,43 @@
1212
import math
1313
from ctypes import POINTER, c_int, c_double, Structure, pointer
1414
from collections import namedtuple
15+
import platform
1516
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}")
3452

3553
c_int_p = POINTER(c_int)
3654
c_double_p = POINTER(c_double)
@@ -446,12 +464,10 @@ def __init__(self, nodes, reactions, elements, options):
446464

447465

448466
# 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))
455471

456472
self._pyframe3dd.run.argtypes = [POINTER(C_Nodes), POINTER(C_Reactions), POINTER(C_Elements),
457473
POINTER(C_OtherElementData), c_int, POINTER(C_LoadCase),

pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ test = ["pytest"]
7777
"Project" = "https://frame3dd.sourceforge.net"
7878

7979
[tool.meson-python.args]
80+
setup = ['--python.install-env=auto']
8081
install = ['--tags=runtime,python-runtime,bin']
8182

8283
[tool.black]

0 commit comments

Comments
 (0)