Skip to content

Commit 1427053

Browse files
committed
Fix _resolve_path for local file URIs
1 parent 454eb3a commit 1427053

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

src/lightning/fabric/utilities/cloud_io.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,8 @@ def _resolve_path(path: _PATH) -> Union[str, Path]:
188188
189189
"""
190190
if _is_local_file_protocol(str(path)):
191-
return Path(path)
191+
_, urlpath = url_to_fs(str(path))
192+
return Path(urlpath)
192193
return str(path)
193194

194195

tests/tests_fabric/utilities/test_cloud_io.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,21 @@ def test_atomic_save_uses_write_for_local(tmp_path):
165165
def test_resolve_path_local_vs_remote(tmp_path):
166166
resolved = _resolve_path(str(tmp_path / "ckpt"))
167167
assert isinstance(resolved, Path)
168+
assert resolved == tmp_path / "ckpt"
169+
170+
# build the URI from tmp_path: a hardcoded "file:///tmp/..." is not absolute on Windows,
171+
# where fsspec would prepend the current drive (e.g. "D:/tmp/...")
172+
local_file = tmp_path / "test.txt"
173+
resolved_file_uri = _resolve_path(local_file.as_uri())
174+
assert isinstance(resolved_file_uri, Path)
175+
assert resolved_file_uri == local_file
176+
177+
# a hand-written drive-less URI: on Windows fsspec resolves it against the current
178+
# drive, matching os.path.abspath semantics; on POSIX it is returned unchanged
179+
resolved_literal = _resolve_path("file:///tmp/test.txt")
180+
assert isinstance(resolved_literal, Path)
181+
assert resolved_literal == Path(os.path.abspath("/tmp/test.txt"))
182+
168183
resolved = _resolve_path("gs://bucket/checkpoints/epoch=1.ckpt")
169184
assert resolved == "gs://bucket/checkpoints/epoch=1.ckpt"
170185
assert isinstance(resolved, str)

0 commit comments

Comments
 (0)