Skip to content

Commit cdbefb1

Browse files
committed
More manual suffix handling for macOS
1 parent fe0cd97 commit cdbefb1

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

julia/find_libpython.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@
2121
if SHLIB_SUFFIX is None:
2222
if is_windows:
2323
SHLIB_SUFFIX = ".dll"
24-
elif is_apple:
25-
SHLIB_SUFFIX = ".dylib"
2624
else:
2725
SHLIB_SUFFIX = ".so"
26+
if is_apple:
27+
# sysconfig.get_config_var("SHLIB_SUFFIX") can be ".so" in macOS.
28+
# Let's not use the value from sysconfig.
29+
SHLIB_SUFFIX = ".dylib"
2830

2931

3032
def linked_libpython():
@@ -157,7 +159,7 @@ def libpython_candidates(suffix=SHLIB_SUFFIX):
157159
yield ctypes.util.find_library(library_name(basename))
158160

159161

160-
def normalize_path(path, suffix=SHLIB_SUFFIX):
162+
def normalize_path(path, suffix=SHLIB_SUFFIX, is_apple=is_apple):
161163
"""
162164
Normalize shared library `path` to a real path.
163165
@@ -178,9 +180,31 @@ def normalize_path(path, suffix=SHLIB_SUFFIX):
178180
return os.path.realpath(path)
179181
if os.path.exists(path + suffix):
180182
return os.path.realpath(path + suffix)
183+
if is_apple:
184+
return normalize_path(_remove_suffix_apple(path),
185+
suffix=".so", is_apple=False)
181186
return None
182187

183188

189+
def _remove_suffix_apple(path):
190+
"""
191+
Strip off .so or .dylib.
192+
193+
>>> _remove_suffix_apple("libpython.so")
194+
'libpython'
195+
>>> _remove_suffix_apple("libpython.dylib")
196+
'libpython'
197+
>>> _remove_suffix_apple("libpython3.7")
198+
'libpython3.7'
199+
"""
200+
if path.endswith(".dylib"):
201+
return path[:-len(".dylib")]
202+
if path.endswith(".so"):
203+
return path[:-len(".so")]
204+
return path
205+
206+
207+
184208
def finding_libpython():
185209
"""
186210
Iterate over existing libpython paths.

0 commit comments

Comments
 (0)