Skip to content

Commit 9c6517d

Browse files
aaronchallkevin-bates
authored andcommitted
Fill in Checkpoints section
(I think it needs more complete examples like ContentsManager has regarding what is returned by these methods.)
1 parent 0ce8def commit 9c6517d

File tree

1 file changed

+51
-1
lines changed

1 file changed

+51
-1
lines changed

docs/source/extending/contents.rst

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,62 @@ methods:
191191
ContentsManager.dir_exists
192192
ContentsManager.is_hidden
193193

194+
You may be required to specify a Checkpoints object, as the default one,
195+
``FileCheckpoints``, could be incompatible with your custom
196+
ContentsManager.
194197

195198
Customizing Checkpoints
196199
-----------------------
200+
.. currentmodule:: notebook.services.contents.checkpoints
201+
202+
Customized Checkpoint definitions allows behavior to be
203+
altered and extended.
204+
205+
The ``Checkpoints`` and ``GenericCheckpointsMixin`` classes
206+
(from :mod:`notebook.services.contents.checkpoints`)
207+
have reusable code and are intended to be used together,
208+
but require the following methods to be implemented.
209+
210+
.. autosummary::
211+
Checkpoints.rename_checkpoint
212+
Checkpoints.list_checkpoints
213+
Checkpoints.delete_checkpoint
214+
GenericCheckpointsMixin.create_file_checkpoint
215+
GenericCheckpointsMixin.create_notebook_checkpoint
216+
GenericCheckpointsMixin.get_file_checkpoint
217+
GenericCheckpointsMixin.get_notebook_checkpoint
218+
219+
No-op example
220+
~~~~~~~~~~~~~
197221

198-
TODO:
222+
Here is an example of a no-op checkpoints object - note the mixin
223+
comes first. The docstrings indicate what each method should do or
224+
return for a more complete implementation.
225+
226+
.. code-block:: python
199227
228+
class NoOpCheckpoints(GenericCheckpointsMixin, Checkpoints):
229+
"""requires the following methods:"""
230+
def create_file_checkpoint(self, content, format, path):
231+
""" -> checkpoint model"""
232+
def create_notebook_checkpoint(self, nb, path):
233+
""" -> checkpoint model"""
234+
def get_file_checkpoint(self, checkpoint_id, path):
235+
""" -> {'type': 'file', 'content': <str>, 'format': {'text', 'base64'}}"""
236+
def get_notebook_checkpoint(self, checkpoint_id, path):
237+
""" -> {'type': 'notebook', 'content': <output of nbformat.read>}"""
238+
def delete_checkpoint(self, checkpoint_id, path):
239+
"""deletes a checkpoint for a file"""
240+
def list_checkpoints(self, path):
241+
"""returns a list of checkpoint models for a given file,
242+
default just does one per file
243+
"""
244+
return []
245+
def rename_checkpoint(self, checkpoint_id, old_path, new_path):
246+
"""renames checkpoint from old path to new path"""
247+
248+
See ``GenericFileCheckpoints`` in :mod:`notebook.services.contents.filecheckpoints`
249+
for a more complete example.
200250

201251
Testing
202252
-------

0 commit comments

Comments
 (0)