Skip to content

Commit e8be2d8

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 1607890 commit e8be2d8

2 files changed

Lines changed: 10 additions & 8 deletions

File tree

src/lightning/fabric/utilities/cloud_io.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414
"""Utilities related to data saving/loading."""
1515

16+
import contextlib
1617
import errno
1718
import io
1819
import logging
@@ -115,10 +116,8 @@ def _atomic_save(checkpoint: dict[str, Any], filepath: _PATH) -> None:
115116
os.fsync(f.fileno())
116117
os.replace(staging, target) # atomic on same filesystem
117118
except BaseException:
118-
try:
119+
with contextlib.suppress(FileNotFoundError):
119120
os.unlink(staging)
120-
except FileNotFoundError:
121-
pass
122121
raise
123122
# Best-effort: fsync the parent directory so the rename itself is durable.
124123
# Not supported on every platform (e.g. Windows) — failures are non-fatal because the

tests/tests_fabric/utilities/test_cloud_io.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ def test_atomic_save_local_stages_next_to_destination(tmp_path, monkeypatch):
164164
after, because a successful transaction cleans the staging file up on commit. Paths are
165165
resolved before comparison so this doesn't false-fail on macOS where /tmp is a symlink to
166166
/private/tmp.
167+
167168
"""
168169
sentinel_tmpdir = (tmp_path / "sentinel_tmpdir").resolve()
169170
dest_dir = (tmp_path / "destination").resolve()
@@ -194,9 +195,10 @@ def traced_mkstemp(*args, **kwargs):
194195
def test_atomic_save_local_cleans_up_staging_on_failure(tmp_path):
195196
"""If the rename fails, the staging file must not leak in the destination dir.
196197
197-
Patches os.replace to fail so we can observe what happens after a successful write but a
198-
failed rename — the destination should not exist and the destination dir should be empty
199-
(i.e. no staging file under any naming convention).
198+
Patches os.replace to fail so we can observe what happens after a successful write but a failed rename — the
199+
destination should not exist and the destination dir should be empty (i.e. no staging file under any naming
200+
convention).
201+
200202
"""
201203
filepath = tmp_path / "checkpoint.ckpt"
202204

@@ -230,8 +232,9 @@ def test_atomic_save_local_preserves_existing_on_failure(tmp_path):
230232
def test_atomic_save_local_missing_parent_raises(tmp_path):
231233
"""Parent directories are not auto-created — locks in current behavior.
232234
233-
Lightning's checkpoint code creates dirs upstream (ModelCheckpoint.setup); a future refactor
234-
silently creating them here would mask caller bugs.
235+
Lightning's checkpoint code creates dirs upstream (ModelCheckpoint.setup); a future refactor silently creating them
236+
here would mask caller bugs.
237+
235238
"""
236239
filepath = tmp_path / "missing" / "checkpoint.ckpt"
237240

0 commit comments

Comments
 (0)