Skip to content

Commit 0a74acf

Browse files
committed
fix(pathfinder): glob fallback prefers newest lib<name>.so* (#1732)
1 parent 7b00098 commit 0a74acf

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

cuda_pathfinder/cuda/pathfinder/_dynamic_libs/search_platform.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,16 @@ def _find_so_in_rel_dirs(
4343
for rel_dir in rel_dirs:
4444
sub_dir = tuple(rel_dir.split(os.path.sep))
4545
for abs_dir in find_sub_dirs_all_sitepackages(sub_dir):
46+
# Exact unversioned match first; fall back to versioned names because some
47+
# distros only ship lib<name>.so.<major> (e.g. conda libcupti). Only one match
48+
# is expected in practice. Sort in reverse so the newest-sorting name wins if
49+
# multiple coexist, matching the newest-first bias elsewhere in pathfinder
50+
# (see LinuxSearchPlatform.find_in_lib_dir and load_dl_linux._candidate_sonames).
51+
# Issue #1732 tracks the deferred question of raising on true ambiguity.
4652
so_name = os.path.join(abs_dir, so_basename)
4753
if os.path.isfile(so_name):
4854
return so_name
49-
for so_name in sorted(glob.glob(os.path.join(abs_dir, file_wild))):
55+
for so_name in sorted(glob.glob(os.path.join(abs_dir, file_wild)), reverse=True):
5056
if os.path.isfile(so_name):
5157
return so_name
5258
sub_dirs_searched.append(sub_dir)
@@ -150,7 +156,8 @@ def find_in_lib_dir(
150156
file_wild = lib_searched_for + "*"
151157
# Only one match is expected, but to ensure deterministic behavior in unexpected
152158
# situations, and to be internally consistent, we sort in reverse order with the
153-
# intent to return the newest version first.
159+
# intent to return the newest version first. Issue #1732 tracks the deferred
160+
# question of raising on true ambiguity.
154161
for so_name in sorted(glob.glob(os.path.join(lib_dir, file_wild)), reverse=True):
155162
if os.path.isfile(so_name):
156163
return so_name

0 commit comments

Comments
 (0)