Viranshul-P opened a new pull request, #41619:
URL: https://github.com/apache/beam/pull/41619
Fixes #41618.
On Windows, `LocalFileSystem._list` joins listed paths with `os.path.join`,
so they use `\` (`data\a.txt`). `FileSystem.match_files` matches them against
the regex from `translate_pattern`, where a literal `/` in the pattern only
matches `/`. So a glob written with `/`, such as `data/*.txt` or
`C:/data/*.txt`, matched no files: `ReadFromText` raised "No files found", and
`ReadAllFromText` and `fileio.MatchFiles` returned an empty `PCollection`.
This PR overrides `match_files` in `LocalFileSystem`. When `os.path.altsep`
is set (Windows), the pattern and the listed paths are both compared with
`os.sep` only. The returned `FileMetadata` paths are unchanged. On other
platforms `os.path.altsep` is `None`, so the base implementation runs as
before, and other filesystems are not touched.
Tests (`apache_beam/io/localfilesystem_test.py`):
- `test_match_glob_with_forward_slashes`: real files matched with an
absolute and a relative `/` pattern.
- `test_match_files_treats_both_separators_alike_on_windows`: `match_files`
with Windows separators mocked, so the Windows branch also runs on Linux.
Both fail on master and pass with this change (Windows 11, Python 3.12).
`localfilesystem_test`, `filesystem_test`, `filesystems_test`,
`filebasedsource_test`, `filebasedsink_test`, `fileio_test`, `textio_test` and
`avroio_test` show no new failures. I also ran `ReadFromText`,
`ReadAllFromText`, `ReadFromCsv` and `fileio.MatchFiles` with `data/*.csv` on
Windows: all four find the files with the fix and none do on master. yapf
0.43.0 and ruff 0.15.7 report nothing.
This change was written with help from Claude Code; the commits carry a
`Generated-by` trailer.
------------------------
Thank you for your contribution! Follow this checklist to help us
incorporate your contribution quickly and easily:
- [x] Mention the appropriate issue in your description (for example:
`addresses #123` or `fixes #456`).
- [x] Update `CHANGES.md` with noteworthy changes.
- [ ] If this contribution is large, please file an Apache [Individual
Contributor License Agreement](https://www.apache.org/licenses/icla.pdf).
See the [Contributor Guide](https://beam.apache.org/contribute) for more
tips on [how to make review process
smoother](https://github.com/apache/beam/blob/master/CONTRIBUTING.md#make-the-reviewers-job-easier).
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]