Skip to content

Commit 032eb9b

Browse files
committed
rthooks: revise the findlibs run-time hook
WIP
1 parent 8923b13 commit 032eb9b

1 file changed

Lines changed: 24 additions & 7 deletions

File tree

_pyinstaller_hooks_contrib/rthooks/pyi_rth_findlibs.py

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@
1515
# the build system. This happens because we (try not to) modify `DYLD_LIBRARY_PATH`, and the original `findlibs.find()`
1616
# implementation gives precedence to environment variables and several fixed/hard-coded locations, and uses
1717
# `ctypes.util.find_library` as the final fallback...
18+
#
19+
# NOTE: the above issues have been largely resolved by contemporary versions of findlibs (i.e., >= 0.1.0), which also
20+
# seem to have added support for package-bundled libraries.
1821
def _pyi_rthook():
1922
import sys
2023
import os
21-
import ctypes.util
2224

2325
# findlibs v0.1.0 broke compatibility with python < 3.10; due to incompatible typing annotation, attempting to
2426
# import the package raises `TypeError: unsupported operand type(s) for |: 'type' and 'NoneType'`. Gracefully
@@ -30,26 +32,41 @@ def _pyi_rthook():
3032
return
3133

3234
_orig_find = getattr(findlibs, 'find', None)
35+
if _orig_find is None:
36+
return
3337

3438
def _pyi_find(lib_name, *args, **kwargs):
35-
extension = findlibs.EXTENSIONS.get(sys.platform, ".so")
39+
# Try to resolve using the original implementation. With contemporary versions of findlibs, this will most
40+
# likely do the right thing (i.e., find the package-bundled copy). With older versions (i.e., < 0.1.0), it
41+
# might end up resolving a system copy instead...
42+
orig_lib = _orig_find(lib_name, *args, **kwargs)
43+
print(f"findlibs-rthook: orig_lib={orig_lib}", file=sys.stderr)
44+
return orig_lib # TODO
3645

37-
# First check sys._MEIPASS
46+
"""
47+
if lib is not None:
48+
# Check that the
49+
return
50+
51+
# Check in top-level application directory
52+
extension = findlibs.EXTENSIONS.get(sys.platform, ".so")
3853
fullname = os.path.join(sys._MEIPASS, "lib{}{}".format(lib_name, extension))
3954
if os.path.isfile(fullname):
4055
return fullname
4156
4257
# Fall back to `ctypes.util.find_library` (to give it precedence over hard-coded paths from original
43-
# implementation).
44-
lib = ctypes.util.find_library(lib_name)
45-
if lib is not None:
46-
return lib
58+
# implementation). Applicable only to findlibs < 0.1.0; in co
59+
if needs_override:
60+
lib = ctypes.util.find_library(lib_name)
61+
if lib is not None:
62+
return lib
4763
4864
# Finally, fall back to original implementation
4965
if _orig_find is not None:
5066
return _orig_find(lib_name, *args, **kwargs)
5167
5268
return None
69+
"""
5370

5471
findlibs.find = _pyi_find
5572

0 commit comments

Comments
 (0)