Repository navigation
[Core] Fix test_runtime_env_working_dir failures on Windows - #66365
Conversation
Signed-off-by: hyungwoo.lee <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request improves the handling of 'file' protocol URIs by correctly decoding percent-encoded paths (such as those with spaces) using urlparse and url2pathname, and adds a test case to verify this behavior. However, the current implementation fails on Windows when the URI contains a drive letter (e.g., 'file://C:/path'), as urlparse interprets the drive letter as the netloc, which then gets discarded. A code suggestion has been provided to reconstruct the path correctly on Windows before passing it to url2pathname.
|
|
||
| if protocol == "file": | ||
| source_uri = source_uri[len("file://") :] | ||
| source_uri = url2pathname(urlparse(source_uri).path) |
There was a problem hiding this comment.
When source_uri is formatted as file://C:/path (which is common on Windows and explicitly constructed in some of Ray's tests like test_download_and_unpack_package_with_file_uri), urlparse parses C: as the netloc (host) and /path as the path.
Using urlparse(source_uri).path directly will discard the drive letter C:, resulting in /path (which url2pathname converts to \path). This makes the path drive-relative and will fail if the file is on a different drive or if the current working directory's drive changes.
To handle this robustly on Windows (including drive letters parsed as hostnames and UNC paths), we can reconstruct the path when netloc is present before passing it to url2pathname.
| source_uri = url2pathname(urlparse(source_uri).path) | |
| parsed = urlparse(source_uri) | |
| host = parsed.netloc | |
| path = parsed.path | |
| if host: | |
| if os.name == "nt" and len(host) == 2 and host[1] == ":": | |
| path = host + path | |
| else: | |
| path = f"//{host}{path}" | |
| source_uri = url2pathname(path) |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
Reviewed by Cursor Bugbot for commit 7575ce6. Configure here.
|
|
||
| if protocol == "file": | ||
| source_uri = source_uri[len("file://") :] | ||
| source_uri = url2pathname(urlparse(source_uri).path) |
There was a problem hiding this comment.
File URI drops Windows drive letter
Medium Severity
urlparse places a Windows drive letter in netloc for two-slash URIs such as file://D:/pkg.zip. Passing only .path to url2pathname drops that drive and yields a current-drive path, so download_remote_uri opens the wrong file. The previous slice kept the drive and succeeded; this is the form Windows users typically write when pointing working_dir or py_modules at a mapped share.
Reviewed by Cursor Bugbot for commit 7575ce6. Configure here.
Signed-off-by: hyungwoo.lee <[email protected]>
…ect#66365) ## Description `download_remote_uri` strips the `file://` scheme by slicing and passes the rest to `open()`. `Path.as_uri()` percent-encodes the path and on Windows emits `file:///C:/...`, so the slice becomes `/C:/...`, which causes `open()` to fail with `OSError: [Errno 22] Invalid argument`. This has been failing `test_lazy_reads[py_modules_tar_xz]` on every Windows postmerge run since ray-project#65742 added that case. ## Related issues Closes anyscale#1966, anyscale#1967 ## Additional information > Optional: Add implementation details, API changes, usage examples, screenshots, etc. ## Tests Added `TestFileProtocol::test_download_percent_encoded_file_uri`, which fails on Linux without the fix. --------- Signed-off-by: hyungwoo.lee <[email protected]>


Description
download_remote_uristrips thefile://scheme by slicing and passes the rest toopen().Path.as_uri()percent-encodes the path and on Windows emitsfile:///C:/..., so the slice becomes/C:/..., which causesopen()to fail withOSError: [Errno 22] Invalid argument. This has been failingtest_lazy_reads[py_modules_tar_xz]on every Windows postmerge run since #65742 added that case.Related issues
Closes anyscale#1966, anyscale#1967
Additional information
Tests
Added
TestFileProtocol::test_download_percent_encoded_file_uri, which fails on Linux without the fix.