21
21
if SHLIB_SUFFIX is None :
22
22
if is_windows :
23
23
SHLIB_SUFFIX = ".dll"
24
- elif is_apple :
25
- SHLIB_SUFFIX = ".dylib"
26
24
else :
27
25
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"
28
30
29
31
30
32
def linked_libpython ():
@@ -157,7 +159,7 @@ def libpython_candidates(suffix=SHLIB_SUFFIX):
157
159
yield ctypes .util .find_library (library_name (basename ))
158
160
159
161
160
- def normalize_path (path , suffix = SHLIB_SUFFIX ):
162
+ def normalize_path (path , suffix = SHLIB_SUFFIX , is_apple = is_apple ):
161
163
"""
162
164
Normalize shared library `path` to a real path.
163
165
@@ -178,9 +180,31 @@ def normalize_path(path, suffix=SHLIB_SUFFIX):
178
180
return os .path .realpath (path )
179
181
if os .path .exists (path + suffix ):
180
182
return os .path .realpath (path + suffix )
183
+ if is_apple :
184
+ return normalize_path (_remove_suffix_apple (path ),
185
+ suffix = ".so" , is_apple = False )
181
186
return None
182
187
183
188
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
+
184
208
def finding_libpython ():
185
209
"""
186
210
Iterate over existing libpython paths.
0 commit comments