Prefer scandir-based gather for source-tree scanning#86
Open
RenanGBarreto wants to merge 1 commit into
Open
Conversation
…ther helper and tests
Code Coverage OverviewLanguages: Python Python / code-coverage/pytestThe overall coverage in the branch remains at 74%, unchanged from the branch. Show a code coverage summary of the most impacted files.
Code Coverage is in Public Preview. Learn more and provide us with your feedback. |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds a new scandir-based file gathering helper and switches scan_source_tree() to use it by default, aiming to speed up source-tree scanning while preserving existing ignore filtering, ASCII-only filename validation, and deterministic ordering.
Changes:
- Added
mkpfs/gather.pywithgather_files_scandir()implemented viaos.scandir(no directory-symlink following). - Updated
mkpfs/pfs.py::scan_source_tree()to prefergather_files_scandir()while keeping the existing global sort and validation logic. - Added
tests/mkpfs/test_gather.pyto validate scandir parity withPath.rglob, ignored-name filtering, and non-ASCII name detection.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| tests/mkpfs/test_gather.py | Adds unit tests covering scandir parity, ignored names, and non-ASCII detection. |
| mkpfs/pfs.py | Switches scan_source_tree discovery to the scandir gatherer while preserving global sort and validation. |
| mkpfs/gather.py | Introduces scandir-based traversal helper intended to be faster than Path.rglob. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+36
to
+41
| try: | ||
| with os.scandir(dir_path) as it: | ||
| entries = list(it) | ||
| except PermissionError: | ||
| # Mirror conservative behavior: skip directories we cannot access. | ||
| continue |
Comment on lines
+43
to
+45
| # Deterministic per-directory ordering to reduce nondeterminism while | ||
| # keeping traversal fast. The final global sort is left to the caller. | ||
| entries.sort(key=lambda e: e.name.lower()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR introduces a scandir-based source-tree gather implementation (mkpfs/gather.py) and prefers it by default in scan_source_tree. It preserves existing semantics (ignored-name filtering, ASCII filename checks, deterministic global ordering) and adds unit tests (tests/mkpfs/test_gather.py).
Key points:
Local test run: all tests passed (383 passed, 1 skipped). Commit: c4e945b.