@@ -140,27 +140,55 @@ def _search_library_names(
140140 if abi_flags :
141141 lib_names .append (f"{ prefix } python{ version } { abi_flags } { shlib_suffix } " )
142142
143+ # Also search for the abi3 libraries.
144+ abi3_lib_names = [f"{ prefix } python{ sys .version_info .major } { shlib_suffix } " ]
145+ for x in lib_names :
146+ if version in x :
147+ abi3_lib_names .append (x .replace (version , f"{ sys .version_info .major } " ))
148+
149+ lib_names .extend (abi3_lib_names )
143150 return list (dict .fromkeys (k for k in lib_names if k ))
144151
145152
146- def _do_library_search (
147- * ,
148- search_directories : list [str ],
149- libnames : list [str ],
150- ) -> tuple [dict [str , None ], dict [str , None ], dict [str , None ]]:
151- """Finds existing libnames in search_directories, returning the found libraries."""
153+ def _get_python_library_info (base_executable ) -> dict [str , Any ]:
154+ """Returns a dictionary with the static and dynamic python libraries."""
155+ config_vars = sysconfig .get_config_vars ()
156+
157+ # VERSION is X.Y in Linux/macOS and XY in Windows. This is used to
158+ # construct library paths such as python3.12, so ensure it exists.
159+ version = config_vars .get ("VERSION" )
160+ if not version :
161+ if _IS_WINDOWS :
162+ version = f"{ sys .version_info .major } { sys .version_info .minor } "
163+ else :
164+ version = f"{ sys .version_info .major } .{ sys .version_info .minor } "
165+
166+ # sys.abiflags may not exist, but it still may be set in the config.
167+ abi_flags = _get_abi_flags (config_vars .get )
168+ shlib_suffix = _get_shlib_suffix (config_vars .get )
169+ search_directories = _search_directories (config_vars .get , base_executable )
170+ search_libnames = _search_library_names (
171+ config_vars .get , version , abi_flags , shlib_suffix
172+ )
152173 static_libraries : dict [str , None ] = {}
153174 dynamic_libraries : dict [str , None ] = {}
154175 interface_libraries : dict [str , None ] = {}
176+ abi_dynamic_libraries : dict [str , None ] = {}
177+ abi_interface_libraries : dict [str , None ] = {}
178+
155179 for root_dir in search_directories :
156- for libname in libnames :
180+ for libname in search_libnames :
157181 # Check whether the library exists.
182+ full_abi = version in libname
158183 composed_path = os .path .join (root_dir , libname )
159184 if os .path .exists (composed_path ) or os .path .isdir (composed_path ):
160- if libname .endswith (".a" ):
161- static_libraries [composed_path ] = None
162- else :
163- dynamic_libraries [composed_path ] = None
185+ if full_abi :
186+ if libname .endswith (".a" ):
187+ static_libraries [composed_path ] = None
188+ else :
189+ dynamic_libraries [composed_path ] = None
190+ elif not libname .endswith (".a" ):
191+ abi_dynamic_libraries [composed_path ] = None
164192
165193 interface_path = None
166194 if libname .endswith (".dll" ):
@@ -180,47 +208,10 @@ def _do_library_search(
180208
181209 # Check whether an interface library exists.
182210 if interface_path and os .path .exists (interface_path ):
183- interface_libraries [interface_path ] = None
184- return static_libraries , dynamic_libraries , interface_libraries
185-
186-
187- def _get_python_library_info (base_executable ) -> dict [str , Any ]:
188- """Returns a dictionary with the static and dynamic python libraries."""
189- config_vars = sysconfig .get_config_vars ()
190-
191- # VERSION is X.Y in Linux/macOS and XY in Windows. This is used to
192- # construct library paths such as python3.12, so ensure it exists.
193- version = config_vars .get ("VERSION" )
194- if not version :
195- if _IS_WINDOWS :
196- version = f"{ sys .version_info .major } { sys .version_info .minor } "
197- else :
198- version = f"{ sys .version_info .major } .{ sys .version_info .minor } "
199-
200- # sys.abiflags may not exist, but it still may be set in the config.
201- abi_flags = _get_abi_flags (config_vars .get )
202- shlib_suffix = _get_shlib_suffix (config_vars .get )
203- search_directories = _search_directories (config_vars .get , base_executable )
204- search_libnames = _search_library_names (
205- config_vars .get , version , abi_flags , shlib_suffix
206- )
207-
208- # Search for the python libraries for the current python interpreter.
209- static_libraries , dynamic_libraries , interface_libraries = _do_library_search (
210- search_directories = search_directories ,
211- libnames = search_libnames ,
212- )
213-
214- # Search for major version abi libraries which must be dynamic.
215- abi_search_libnames = [
216- s .replace (version , f"{ sys .version_info .major } " )
217- for s in search_libnames
218- if version in s
219- ]
220- _ , abi_dynamic_libraries , abi_interface_libraries = _do_library_search (
221- search_directories = search_directories ,
222- libnames = abi_search_libnames ,
223- )
211+ if full_abi :
212+ interface_libraries [interface_path ] = None
213+ else :
214+ abi_interface_libraries [interface_path ] = None
224215
225216 # Additional DLLs are needed on Windows to link properly.
226217 dlls = []
0 commit comments