Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update documentation about registering file save hooks #770

Merged
merged 1 commit into from
Apr 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions docs/source/developers/savehooks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,15 @@ A post-save hook to make a script equivalent whenever the notebook is saved

This could be a simple call to ``jupyter nbconvert --to script``, but spawning
the subprocess every time is quite slow.

.. note::
Assigning a new hook to e.g. ``c.FileContentsManager.pre_save_hook`` will override any existing one.

If you want to add new hooks and keep existing ones, you should use e.g.:

.. code-block:: python

contents_manager.register_pre_save_hook(script_pre_save)
contents_manager.register_post_save_hook(script_post_save)

Hooks will then be called in the order they were registered.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are now adding deprecation warnings for the old behavior, I would probably add this to the top of this document, and then put the current docs behind a "deprecated" note. Otherwise this looks good 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually only the run_pre_save_hook and run_post_save_hook methods are deprecated (which are usually not used by users), but assigning to e.g. contents_manager.pre_save_hook is not deprecated yet, so I think it is too early to discourage the old behavior in the documentation, don't you think?