fix(sources): skip non-regular files in scan_compiled_extensions#1004
fix(sources): skip non-regular files in scan_compiled_extensions#1004tiran merged 1 commit intopython-wheel-build:mainfrom
Conversation
📝 WalkthroughWalkthroughThe Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/fromager/sources.py (1)
868-871: Fix looks correct; consider adding test coverage for symlink edge case.The
is_file()check correctly handles symlinks to directories (returnsFalse) while still processing symlinks to regular files (follows symlink, returnsTrue). Broken symlinks are also safely skipped.The existing test in
tests/test_sources.py:304-314doesn't cover this scenario. A regression test with a symlinked directory would prevent this from breaking again.🧪 Suggested test addition
def test_scan_compiled_extensions_skips_symlinked_directory(tmp_path: pathlib.Path) -> None: """Ensure symlinks to directories don't cause IsADirectoryError.""" real_dir = tmp_path / "real_dir" real_dir.mkdir() (real_dir / "file.c").write_bytes(b"/* source */") symlink_dir = tmp_path / "symlink_dir" symlink_dir.symlink_to(real_dir) # Should not raise IsADirectoryError matches = sources.scan_compiled_extensions(tmp_path) assert pathlib.Path("symlink_dir") not in matches🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/fromager/sources.py` around lines 868 - 871, The scan_compiled_extensions loop currently guards against symlinked directories by checking filepath.is_file(), but there's no test ensuring this behavior; add a regression test for scan_compiled_extensions that creates a real directory with a file, creates a symlink to that directory, calls sources.scan_compiled_extensions on the parent tmp_path, and asserts that the symlinked directory name is not included in the returned matches (and that no IsADirectoryError is raised); reference the scan_compiled_extensions function and the filepath.is_file() check when locating where this behavior is handled.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/fromager/sources.py`:
- Around line 868-871: The scan_compiled_extensions loop currently guards
against symlinked directories by checking filepath.is_file(), but there's no
test ensuring this behavior; add a regression test for scan_compiled_extensions
that creates a real directory with a file, creates a symlink to that directory,
calls sources.scan_compiled_extensions on the parent tmp_path, and asserts that
the symlinked directory name is not included in the returned matches (and that
no IsADirectoryError is raised); reference the scan_compiled_extensions function
and the filepath.is_file() check when locating where this behavior is handled.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 5ff9a666-d708-4f26-adb8-add78418103c
📒 Files selected for processing (1)
src/fromager/sources.py
a2969b2 to
a1cac6f
Compare
pathlib.Path.walk() lists symlinks to directories as filenames rather than dirnames. This causes scan_compiled_extensions to attempt to open() them, resulting in IsADirectoryError. Add an is_file() check to skip non-regular files before attempting to read their contents. Closes: python-wheel-build#1001 Closes: python-wheel-build#1004 Co-Authored-By: Mike DePaulo <mikedep333@redhat.com> Co-Authored-By: Claude Opus 4.6 <claude@anthropic.com> Signed-off-by: pmattsso <pmattsso@redhat.com>
a1cac6f to
fb67992
Compare
|
@Mergifyio queue |
|
|
@Mergifyio rebase |
☑️ Nothing to do, the required conditions are not metDetails
|
|
Mergify rules are broken, see #1005. I'm going to approve and merge this PR manually. |
pathlib.Path.walk() lists symlinks to directories as filenames rather than dirnames. This causes scan_compiled_extensions to attempt to open() them, resulting in IsADirectoryError. Add an is_file() check to skip non-regular files before attempting to read their contents. Closes: python-wheel-build#1001 Closes: python-wheel-build#1004 Co-Authored-By: Mike DePaulo <mikedep333@redhat.com> Co-Authored-By: Claude Opus 4.6 <claude@anthropic.com> Signed-off-by: pmattsso <pmattsso@redhat.com>
pathlib.Path.walk() lists symlinks to directories as filenames rather than dirnames. This causes scan_compiled_extensions to attempt to open() them, resulting in IsADirectoryError. Add an is_file() check to skip non-regular files before attempting to read their contents. Closes: python-wheel-build#1001 Closes: python-wheel-build#1004 Co-Authored-By: Mike DePaulo <mikedep333@redhat.com> Co-Authored-By: Claude Opus 4.6 <claude@anthropic.com> Signed-off-by: pmattsso <pmattsso@redhat.com>
pathlib.Path.walk() lists symlinks to directories as filenames rather than dirnames. This causes scan_compiled_extensions to attempt to open() them, resulting in IsADirectoryError. Add an is_file() check to skip non-regular files before attempting to read their contents.
Closes: #1001
Closes: #1004
Pull Request Description
What
Why