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

Handle importstring pre/post save hooks #754

Merged
merged 1 commit into from
Mar 25, 2022
Merged

Conversation

dleen
Copy link
Contributor

@dleen dleen commented Mar 24, 2022

Try access the name attribute on the function form of the hook, and
if it doesn't exist then use the string as the name.

Closes #753

@welcome
Copy link

welcome bot commented Mar 24, 2022

Thanks for submitting your first pull request! You are awesome! 🤗

If you haven't done so already, check out Jupyter's Code of Conduct. Also, please make sure you followed the pull request template, as this will help us review your contribution more quickly.
welcome
You can meet the other Jovyans by joining our Discourse forum. There is also a intro thread there where you can stop by and say Hi! 👋

Welcome to the Jupyter community! 🎉

@codecov-commenter
Copy link

codecov-commenter commented Mar 24, 2022

Codecov Report

Merging #754 (123d47c) into main (cd1b1b8) will decrease coverage by 0.11%.
The diff coverage is 0.00%.

@@            Coverage Diff             @@
##             main     #754      +/-   ##
==========================================
- Coverage   70.68%   70.56%   -0.12%     
==========================================
  Files          62       62              
  Lines        7620     7620              
  Branches     1218     1215       -3     
==========================================
- Hits         5386     5377       -9     
- Misses       1860     1864       +4     
- Partials      374      379       +5     
Impacted Files Coverage Δ
jupyter_server/services/contents/manager.py 83.65% <0.00%> (+1.46%) ⬆️
jupyter_server/base/zmqhandlers.py 52.91% <0.00%> (-4.24%) ⬇️
jupyter_server/services/kernels/kernelmanager.py 80.63% <0.00%> (-1.91%) ⬇️
jupyter_server/services/contents/filemanager.py 72.46% <0.00%> (-0.81%) ⬇️
jupyter_server/services/kernels/handlers.py 58.86% <0.00%> (-0.22%) ⬇️
jupyter_server/serverapp.py 65.16% <0.00%> (-0.19%) ⬇️
jupyter_server/utils.py 62.20% <0.00%> (+2.87%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cd1b1b8...123d47c. Read the comment docs.

@davidbrochart
Copy link
Contributor

Thanks @dleen for opening this PR.
I think the problem here is that the hook passed on the command line with:

--FileContentsManager.pre_save_hook='mymodule.foo_function'

is being validated as a new hook, but is also treated as an already existing hook, which it isn't because otherwise it would have been validated and converted to a callable.
Because we know that a validated hook is a callable and not a string anymore, I think a better solution would be to replace this line:

        if self.pre_save_hook is not None:

with:

        if callable(self.pre_save_hook):

Only treat a hook as a replacement if the existing hook is callable. Otherwise
treat it as a new hook.

Closes jupyter-server#753
@dleen
Copy link
Contributor Author

dleen commented Mar 24, 2022

Yep that solution makes more sense!

@blink1073
Copy link
Contributor

Kicking CI

@blink1073 blink1073 closed this Mar 24, 2022
@blink1073 blink1073 reopened this Mar 24, 2022
@blink1073
Copy link
Contributor

Thanks! The minimum version check is being handled in #756

@blink1073 blink1073 merged commit 9177f11 into jupyter-server:main Mar 25, 2022
@welcome
Copy link

welcome bot commented Mar 25, 2022

Congrats on your first merged pull request in this project! 🎉
congrats
Thank you for contributing, we are very proud of you! ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Passing pre_save_hook as importstring
5 participants