-
Notifications
You must be signed in to change notification settings - Fork 950
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
Replace ipykernel dependency by the comm dependency #3811
Merged
SylvainCorlay
merged 4 commits into
jupyter-widgets:main
from
martinRenou:add_comm_dependency
Jul 28, 2023
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# compatibility shim for ipykernel < 6.18 | ||
import sys | ||
from IPython import get_ipython | ||
import comm | ||
|
||
|
||
def requires_ipykernel_shim(): | ||
if "ipykernel" in sys.modules: | ||
import ipykernel | ||
|
||
version = ipykernel.version_info | ||
return version < (6, 18) | ||
else: | ||
return False | ||
|
||
|
||
def get_comm_manager(): | ||
if requires_ipykernel_shim(): | ||
ip = get_ipython() | ||
|
||
if ip is not None and getattr(ip, "kernel", None) is not None: | ||
return get_ipython().kernel.comm_manager | ||
else: | ||
return comm.get_comm_manager() | ||
|
||
|
||
def create_comm(*args, **kwargs): | ||
if requires_ipykernel_shim(): | ||
from ipykernel.comm import Comm | ||
|
||
return Comm(*args, **kwargs) | ||
else: | ||
return comm.create_comm(*args, **kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd really like to get rid of this some day.
That way we can remove the nasty patches of ipykernel.comm in xeus-python.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do you want to get rid of this? in xeus-python you don't need to fix this right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's say a library imports ipykernel and we import it before ipywidgets, then we end up in this block, breaking xeus-python. So xeus-python needs to patch this import.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
only for old ipykernels right? Do you think that will still happen?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like this piece of code to basically stay around forever, so we better get it right! :)
We can also skip this if we can detect xeus-python, or some other condition to make this more robust? Do you make use of a 'fake' ipykernel module in xeus-python?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only for old ipykernel yes.
Let's talk again about it in ten years? 😄
Yeah we mock the ipykernel module https://github.com/jupyter-xeus/xeus-python/blob/main/src/xinterpreter.cpp#L77 . We should keep this mock in xeus-python for supporting old ipywidgets anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy to discuss this in ten years from now :)