Skip to content

Commit e912a0d

Browse files
authored
Go Back To Parsing libtiledb Version From tiledb_version.h (#1240)
* Retrieve Full Path of `libtiledb.so` On Linux
1 parent 4934a17 commit e912a0d

File tree

1 file changed

+30
-22
lines changed

1 file changed

+30
-22
lines changed

setup.py

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,24 @@ def _libtiledb_exists(library_dirs):
9494
try:
9595
# note: this is a relative path on linux
9696
# https://bugs.python.org/issue21042
97-
CDLL(lib_name)
97+
98+
lib = CDLL(lib_name)
99+
100+
if os.name == "posix":
101+
# Workaround to retrieving full path of shared library based
102+
# on https://stackoverflow.com/a/35683698
103+
104+
dlinfo = lib.dlinfo
105+
dlinfo.argtypes = c_void_p, c_int, c_void_p
106+
dlinfo.restype = c_int
107+
108+
class LINKMAP(Structure):
109+
_fields_ = [("l_addr", c_void_p), ("l_name", c_char_p)]
110+
111+
lmptr = POINTER(LINKMAP)()
112+
dlinfo(lib._handle, 2, byref(lmptr))
113+
lib_name = lmptr.contents.l_name.decode()
114+
98115
return lib_name
99116
except:
100117
pass
@@ -284,7 +301,7 @@ def find_or_install_libtiledb(setuptools_cmd):
284301
if wheel_build and is_windows() and lib_exists:
285302
do_install = True
286303

287-
print("prefix_dir: ", prefix_dir or None)
304+
print("prefix_dir: ", prefix_dir)
288305
print("do_install: ", do_install)
289306

290307
if do_install:
@@ -377,35 +394,26 @@ def do_copy(src, dest):
377394
print("-------------------\n")
378395
setuptools_cmd.distribution.package_data.update({"tiledb": libtiledb_objects})
379396

380-
libtiledbso = CDLL(
381-
lib_exists or os.path.join(dest_dir, libtiledb_library_names()[0])
397+
libtiledb_dir = (
398+
os.path.dirname(os.path.dirname(lib_exists)) if lib_exists else prefix_dir
382399
)
383-
384-
libtiledbso.tiledb_version.argtypes = [
385-
POINTER(c_int),
386-
POINTER(c_int),
387-
POINTER(c_int),
388-
]
389-
major, minor, patch = c_int(), c_int(), c_int()
390-
libtiledbso.tiledb_version(major, minor, patch)
400+
version_header = os.path.join(
401+
libtiledb_dir, "include", "tiledb", "tiledb_version.h"
402+
)
403+
with open(version_header) as header:
404+
lines = list(header)[-3:]
405+
major, minor, patch = [int(l.split()[-1]) for l in lines]
391406

392407
ext_attr_update(
393408
"cython_compile_time_env",
394409
{
395410
"TILEDBPY_MODULAR": TILEDBPY_MODULAR,
396-
"LIBTILEDB_VERSION_MAJOR": major.value,
397-
"LIBTILEDB_VERSION_MINOR": minor.value,
398-
"LIBTILEDB_VERSION_PATCH": patch.value,
411+
"LIBTILEDB_VERSION_MAJOR": major,
412+
"LIBTILEDB_VERSION_MINOR": minor,
413+
"LIBTILEDB_VERSION_PATCH": patch,
399414
},
400415
)
401416

402-
if is_windows():
403-
from ctypes.wintypes import HMODULE
404-
405-
kernel32 = WinDLL("kernel32", use_last_error=True)
406-
kernel32.FreeLibrary.argtypes = [HMODULE]
407-
kernel32.FreeLibrary(libtiledbso._handle)
408-
409417

410418
class LazyCommandClass(dict):
411419
"""

0 commit comments

Comments
 (0)