Skip to content

Commit f7dc7e9

Browse files
committed
Enabling absolute checkpoint dir
Sometimes, we don't want the checkpoints to be saved into our working directory. Instead, we may want to recreate the project structure inside a separate folder (e.g.: /home/{user}/.cache) like some software are doing.
1 parent 1cb4116 commit f7dc7e9

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

jupyter_server/services/contents/filecheckpoints.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ class FileCheckpoints(FileManagerMixin, Checkpoints):
3434
config=True,
3535
help="""The directory name in which to keep file checkpoints
3636
37-
This is a path relative to the file's own directory.
37+
This path can either be relative or absolute.
38+
If it is a relative path, the checkpoint will be saved to the file's own directory.
3839
3940
By default, it is .ipynb_checkpoints
4041
""",
@@ -110,7 +111,10 @@ def checkpoint_path(self, checkpoint_id, path):
110111
basename, ext = os.path.splitext(name)
111112
filename = f"{basename}-{checkpoint_id}{ext}"
112113
os_path = self._get_os_path(path=parent)
113-
cp_dir = os.path.join(os_path, self.checkpoint_dir)
114+
if os.path.isabs(self.checkpoint_dir):
115+
cp_dir = os.path.join(self.checkpoint_dir, parent)
116+
else:
117+
cp_dir = os.path.join(os_path, self.checkpoint_dir)
114118
with self.perm_to_403():
115119
ensure_dir_exists(cp_dir)
116120
cp_path = os.path.join(cp_dir, filename)

0 commit comments

Comments
 (0)