Skip to content

Filter directories from shared library glob results#4094

Merged
ScottTodd merged 2 commits intomainfrom
copilot/fix-get-module-shared-libraries
Mar 20, 2026
Merged

Filter directories from shared library glob results#4094
ScottTodd merged 2 commits intomainfrom
copilot/fix-get-module-shared-libraries

Conversation

Copy link
Contributor

Copilot AI commented Mar 20, 2026

path.glob("**/*.so.*") and similar patterns can match directories, not just files, causing unexpected behavior in get_module_shared_libraries.

Changes

  • build_tools/packaging/python/templates/rocm/src/rocm_sdk/tests/utils.py: Replace list(path.glob(...)) with list comprehensions filtered by p.is_file() for all three patterns (.so.*, .so, .dll).
# Before
so_paths = list(path.glob("**/*.so.*")) + list(path.glob("**/*.so"))

# After
so_paths = [p for p in path.glob("**/*.so.*") if p.is_file()] + [
    p for p in path.glob("**/*.so") if p.is_file()
]
Original prompt

Problem

The get_module_shared_libraries function in build_tools/packaging/python/templates/rocm/src/rocm_sdk/tests/utils.py (lines 40-47) currently uses glob patterns that can match directories ending with .so.*, not just files. This causes issues when directories happen to match these patterns.

File Location

def get_module_shared_libraries(mod) -> list[Path]:
path = Path(mod.__file__).parent
if is_windows:
so_paths = list(path.glob("**/*.dll"))
else:
so_paths = list(path.glob("**/*.so.*")) + list(path.glob("**/*.so"))
return so_paths

Current Code

def get_module_shared_libraries(mod) -> list[Path]:
    path = Path(mod.__file__).parent
    if is_windows:
        so_paths = list(path.glob("**/*.dll"))
    else:
        so_paths = list(path.glob("**/*.so.*")) + list(path.glob("**/*.so"))

    return so_paths

Solution

Add filtering to ensure only files are included in so_paths, excluding any directories that might match the glob patterns:

def get_module_shared_libraries(mod) -> list[Path]:
    path = Path(mod.__file__).parent
    if is_windows:
        so_paths = [p for p in path.glob("**/*.dll") if p.is_file()]
    else:
        so_paths = [p for p in path.glob("**/*.so.*") if p.is_file()] + [
            p for p in path.glob("**/*.so") if p.is_file()
        ]

    return so_paths

This ensures that only actual shared library files are returned, not directories with matching names.

The following is the prior conversation context from the user's chat exploration (may be truncated):

User: so_paths can include directories here that end with .so.*, we need to exclude those

Assistant: I'll examine the code at that URL to understand the issue with so_paths including directories.

Assistant: I can see the issue! In the get_module_shared_libraries function, lines 40-47, the glob pattern **/*.so.* can match directories that end with .so. followed by something (like version numbers). These directory matches should be excluded since we only want actual shared library files.

The function should filter out directories and only return files. Here's what needs to be fixed:

Current code (lines 40-47):

def get_module_shared_libraries(mod) -> list[Path]:
    path = Path(mod.__file__).parent
    if is_windows:
        so_paths = list(path.glob("**/*.dll"))
    else:
        so_paths = list(path.glob("**/*.so.*")) + list(path.glob("**/*.so"))

    return so_paths

Suggested fix:

def get_module_shared_libraries(mod) -> list[Path]:
    path = Path(mod.__file__).parent
    if is_windows:
        so_paths = [p for p in path.glob("**/*.dll") if p.is_file()]
    else:
        so_paths = [p for p in path.glob("**/*.so.*") if p.is_file()] + [
            p for p in path.glob("**/*.so") if p.is_file()
        ]

    return so_paths

This adds a filter using p.is_file() to ensure only actual files are included, excluding any directories that might match the pattern.

Would you like me to create a pull request to fix this issue?

User: Yes, please create a PR

Assistant: We're waiting for your response to the tool call dialog to continue.

This pull request was created from Copilot chat.


⚡ Quickly spin up Copilot coding agent tasks from anywhere on your macOS or Windows machine with Raycast.

Co-authored-by: jayhawk-commits <145489236+jayhawk-commits@users.noreply.github.com>
Agent-Logs-Url: https://github.com/ROCm/TheRock/sessions/d48ab527-8176-4ba0-8c43-cbb408934710
Copilot AI changed the title [WIP] Fix get_module_shared_libraries to exclude directories Filter directories from shared library glob results Mar 20, 2026
Copilot AI requested a review from jayhawk-commits March 20, 2026 23:11
@ScottTodd
Copy link
Member

I triggered some python package builds using artifacts from the rocm-systems submodule update (#3984) that first started showing the test failures from #3999

gfx94X: https://github.com/ROCm/TheRock/actions/runs/23366236318
gfx1151: https://github.com/ROCm/TheRock/actions/runs/23366263964

Once those builds complete (8-15 minutes) we can also trigger https://github.com/ROCm/TheRock/actions/workflows/test_rocm_wheels.yml to run rocm-sdk test (or download and test locally)

@ScottTodd
Copy link
Member

Test run: https://github.com/ROCm/TheRock/actions/runs/23366544519/job/67981590817

Triggered with inputs matching the CI run that failed, but using the workflow run id from the build run triggered earlier: https://github.com/ROCm/TheRock/actions/runs/23223625075/job/67610796675#step:1:17

    amdgpu_family: gfx1151
    test_runs_on: linux-gfx1151-gpu-rocm
    package_index_url_base: 
-   package_find_links_url: https://therock-ci-artifacts.s3.amazonaws.com/23223625075-linux/python/gfx1151/index.html
+   package_find_links_url: https://therock-ci-artifacts.s3.amazonaws.com/23366263964-linux/python/gfx1151/index.html
    python_version: 3.12
    rocm_version: 7.13.0.dev0+6b5c0600b79528b949881f1856deda28c5ec438a

Success:

----------------------------------------------------------------------
Ran 26 tests in 10.168s
OK

@ScottTodd ScottTodd marked this pull request as ready for review March 20, 2026 23:35
@ScottTodd ScottTodd merged commit 9a38f01 into main Mar 20, 2026
18 checks passed
@ScottTodd ScottTodd deleted the copilot/fix-get-module-shared-libraries branch March 20, 2026 23:36
@github-project-automation github-project-automation bot moved this from TODO to Done in TheRock Triage Mar 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants