@@ -24,23 +24,40 @@ def get_library_path(module_name: str) -> str:
24
24
"moordyn" : "libmoordyn_c_binding"
25
25
}
26
26
basename = module_map .get (module_name .lower (), f"lib{ module_name } _c_binding" )
27
- build_path = Path (".." ).joinpath (* [".." ] * 4 , " build" )
27
+ build_path = Path (".." ).joinpath (* [".." ] * 3 ) # for running from testing in a build dir
28
28
29
29
if sys .platform in ["linux" , "linux2" ]:
30
- return str (build_path / "modules" / module_name / f"{ basename } .so" )
31
-
30
+ ext = "so"
32
31
if sys .platform == "darwin" :
33
- return str (build_path / "modules" / module_name / f"{ basename } .dylib" )
32
+ ext = "dylib"
33
+
34
+ if sys .platform in ["linux" ,"linux2" ,"darwin" ]:
35
+ possible_paths = [
36
+ build_path / "modules" / module_name / f"{ basename } .{ ext } " ,
37
+ build_path / ".." / "install" / "lib" / f"{ basename } .{ ext } "
38
+ ]
39
+ for path in possible_paths :
40
+ if path .is_file ():
41
+ print (f"Loading library from { path } " )
42
+ return str (path )
43
+ sys .exit (
44
+ f"Cannot find lib{ module_name } _c_binding at"
45
+ f" { possible_paths [0 ]} or { possible_paths [1 ]} "
46
+ )
34
47
35
48
if sys .platform == "win32" :
36
49
bit_version = "Win32" if sys .maxsize <= 2 ** 32 else "x64"
37
50
possible_paths = [
38
51
build_path / "modules" / module_name / f"{ basename } .dll" ,
39
52
build_path / "bin" / f"{ module_name } _c_binding_{ bit_version } .dll"
40
53
]
41
- return str (next ((path for path in possible_paths if path .is_file ()), None )) or sys .exit (
54
+ for path in possible_paths :
55
+ if path .is_file ():
56
+ print (f"Loading library from { path } " )
57
+ return str (path )
58
+ sys .exit (
42
59
f"Python is { bit_version } bit and cannot find { bit_version } "
43
- f"bit { module_name } DLL in any expected location ."
60
+ f"bit { module_name } DLL at { path } ."
44
61
)
45
62
46
63
raise ValueError (f"Unsupported platform: { sys .platform } " )
0 commit comments