Skip to content

Prefer scandir-based gather for source-tree scanning#86

Open
RenanGBarreto wants to merge 1 commit into
mainfrom
feature/scandir-gather
Open

Prefer scandir-based gather for source-tree scanning#86
RenanGBarreto wants to merge 1 commit into
mainfrom
feature/scandir-gather

Conversation

@RenanGBarreto

Copy link
Copy Markdown
Contributor

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:

  • Adds mkpfs/gather.py with a fast os.scandir walker (does not follow directory symlinks).
  • scan_source_tree now uses gather_files_scandir and preserves the global sort behavior.
  • Unit tests validate parity with Path.rglob, ignored names, and non-ASCII name detection.

Local test run: all tests passed (383 passed, 1 skipped). Commit: c4e945b.

Copilot AI review requested due to automatic review settings July 7, 2026 14:17
@github-code-quality

Copy link
Copy Markdown

Code Coverage Overview

Languages: Python

Python / code-coverage/pytest

The overall coverage in the branch remains at 74%, unchanged from the branch.

Show a code coverage summary of the most impacted files.
File f4a64b3 c4e945b +/-
pfs.py 78% 78% 0%
gather.py 0% 86% +86%

Code Coverage is in Public Preview. Learn more and provide us with your feedback.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.py with gather_files_scandir() implemented via os.scandir (no directory-symlink following).
  • Updated mkpfs/pfs.py::scan_source_tree() to prefer gather_files_scandir() while keeping the existing global sort and validation logic.
  • Added tests/mkpfs/test_gather.py to validate scandir parity with Path.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 thread mkpfs/gather.py
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 thread mkpfs/gather.py
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())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants