From 950fbf52eb3204879fe278613d68ee0bc33a58c7 Mon Sep 17 00:00:00 2001 From: Lumir Balhar Date: Aug 31 2021 14:55:11 +0000 Subject: Fix compatibility with jupyter-client 7 --- diff --git a/0c7aca07d45ff009327599f6985c6a8ebbd98987.patch b/0c7aca07d45ff009327599f6985c6a8ebbd98987.patch new file mode 100644 index 0000000..ee958ed --- /dev/null +++ b/0c7aca07d45ff009327599f6985c6a8ebbd98987.patch @@ -0,0 +1,84 @@ +From 0c7aca07d45ff009327599f6985c6a8ebbd98987 Mon Sep 17 00:00:00 2001 +From: David Brochart +Date: Tue, 1 Jun 2021 09:41:11 +0200 +Subject: [PATCH] Wrap jupyter_client's async functions with run_sync + +--- + .github/workflows/python-package.yml | 1 + + jupyter_console/ptshell.py | 16 +++++++++------- + 2 files changed, 10 insertions(+), 7 deletions(-) + +diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml +index eb8048e..fd5fcd0 100644 +--- a/.github/workflows/python-package.yml ++++ b/.github/workflows/python-package.yml +@@ -29,6 +29,7 @@ jobs: + pip install pytest pytest-cov + pip install . + python -m ipykernel.kernelspec --user ++ pip install https://github.com/jupyter/jupyter_client/archive/master.zip + - name: Test with pytest + run: | + pytest --cov jupyter_console +diff --git a/jupyter_console/ptshell.py b/jupyter_console/ptshell.py +index a9daeed..d6dc1e7 100644 +--- a/jupyter_console/ptshell.py ++++ b/jupyter_console/ptshell.py +@@ -76,6 +76,8 @@ + from pygments.util import ClassNotFound + from pygments.token import Token + ++from jupyter_client.utils import run_sync ++ + + def ask_yes_no(prompt, default=None, interrupt=None): + """Asks a question and returns a boolean (y/n) answer. +@@ -705,8 +707,8 @@ def run_cell(self, cell, store_history=True): + return + + # flush stale replies, which could have been ignored, due to missed heartbeats +- while self.client.shell_channel.msg_ready(): +- self.client.shell_channel.get_msg() ++ while run_sync(self.client.shell_channel.msg_ready)(): ++ run_sync(self.client.shell_channel.get_msg)() + # execute takes 'hidden', which is the inverse of store_hist + msg_id = self.client.execute(cell, not store_history) + +@@ -739,7 +741,7 @@ def run_cell(self, cell, store_history=True): + #----------------- + + def handle_execute_reply(self, msg_id, timeout=None): +- msg = self.client.shell_channel.get_msg(block=False, timeout=timeout) ++ msg = run_sync(self.client.shell_channel.get_msg)(block=False, timeout=timeout) + if msg["parent_header"].get("msg_id", None) == msg_id: + + self.handle_iopub(msg_id) +@@ -778,7 +780,7 @@ def handle_is_complete_reply(self, msg_id, timeout=None): + ## Get the is_complete response: + msg = None + try: +- msg = self.client.shell_channel.get_msg(block=True, timeout=timeout) ++ msg = run_sync(self.client.shell_channel.get_msg)(block=True, timeout=timeout) + except Empty: + warn('The kernel did not respond to an is_complete_request. ' + 'Setting `use_kernel_is_complete` to False.') +@@ -849,8 +851,8 @@ def handle_iopub(self, msg_id=''): + + It only displays output that is caused by this session. + """ +- while self.client.iopub_channel.msg_ready(): +- sub_msg = self.client.iopub_channel.get_msg() ++ while run_sync(self.client.iopub_channel.msg_ready)(): ++ sub_msg = run_sync(self.client.iopub_channel.get_msg)() + msg_type = sub_msg['header']['msg_type'] + + # Update execution_count in case it changed in another session +@@ -1003,7 +1005,7 @@ def handle_image_callable(self, data, mime): + def handle_input_request(self, msg_id, timeout=0.1): + """ Method to capture raw_input + """ +- req = self.client.stdin_channel.get_msg(timeout=timeout) ++ req = run_sync(self.client.stdin_channel.get_msg)(timeout=timeout) + # in case any iopub came while we were waiting: + self.handle_iopub(msg_id) + if msg_id == req["parent_header"].get("msg_id"): diff --git a/84a4c63f7c2b700357f5e5f730209dc4fc897c24.patch b/84a4c63f7c2b700357f5e5f730209dc4fc897c24.patch new file mode 100644 index 0000000..56263c2 --- /dev/null +++ b/84a4c63f7c2b700357f5e5f730209dc4fc897c24.patch @@ -0,0 +1,69 @@ +From 84a4c63f7c2b700357f5e5f730209dc4fc897c24 Mon Sep 17 00:00:00 2001 +From: David Brochart +Date: Wed, 2 Jun 2021 09:45:47 +0200 +Subject: [PATCH] Use run_sync only from jupyter_client 7.0+ + +--- + jupyter_console/completer.py | 12 +++++++++++- + jupyter_console/ptshell.py | 13 ++++++++++--- + 2 files changed, 21 insertions(+), 4 deletions(-) + +diff --git a/jupyter_console/completer.py b/jupyter_console/completer.py +index d0b7b9a..4b845e3 100644 +--- a/jupyter_console/completer.py ++++ b/jupyter_console/completer.py +@@ -7,6 +7,16 @@ + from traitlets.config import Configurable + from traitlets import Float + ++import jupyter_client ++ ++ ++# jupyter_client 7.0+ has async channel methods that we expect to be sync here ++if jupyter_client._version.version_info[0] >= 7: ++ from jupyter_client.utils import run_sync ++else: ++ run_sync = lambda x: x ++ ++ + class ZMQCompleter(Configurable): + """Client-side completion machinery. + +@@ -31,7 +41,7 @@ def complete_request(self, code, cursor_pos): + cursor_pos=cursor_pos, + ) + +- msg = self.client.shell_channel.get_msg(timeout=self.timeout) ++ msg = run_sync(self.client.shell_channel.get_msg)(timeout=self.timeout) + if msg['parent_header']['msg_id'] == msg_id: + return msg['content'] + +diff --git a/jupyter_console/ptshell.py b/jupyter_console/ptshell.py +index d6dc1e7..4608992 100644 +--- a/jupyter_console/ptshell.py ++++ b/jupyter_console/ptshell.py +@@ -76,7 +76,14 @@ + from pygments.util import ClassNotFound + from pygments.token import Token + +-from jupyter_client.utils import run_sync ++import jupyter_client ++ ++ ++# jupyter_client 7.0+ has async channel methods that we expect to be sync here ++if jupyter_client._version.version_info[0] >= 7: ++ from jupyter_client.utils import run_sync ++else: ++ run_sync = lambda x: x + + + def ask_yes_no(prompt, default=None, interrupt=None): +@@ -1034,6 +1041,6 @@ def double_int(sig, frame): + + # only send stdin reply if there *was not* another request + # or execution finished while we were reading. +- if not (self.client.stdin_channel.msg_ready() or +- self.client.shell_channel.msg_ready()): ++ if not (run_sync(self.client.stdin_channel.msg_ready)() or ++ run_sync(self.client.shell_channel.msg_ready)()): + self.client.input(raw_data) diff --git a/python-jupyter-console.spec b/python-jupyter-console.spec index 6c3df4f..83a7661 100644 --- a/python-jupyter-console.spec +++ b/python-jupyter-console.spec @@ -3,7 +3,7 @@ Name: python-%{srcname} Version: 6.4.0 -Release: 4%{?dist} +Release: 5%{?dist} Summary: Jupyter terminal console License: BSD @@ -15,6 +15,11 @@ Source0: %pypi_source %{srcname_} # Not backwards compatible with all older Pythons, downstream only for now Patch1: python3.10.patch +# Compatibility with jupyter-client 7 +# Patches from https://github.com/jupyter/jupyter_console/pull/244/ +Patch2: https://github.com/jupyter/jupyter_console/commit/0c7aca07d45ff009327599f6985c6a8ebbd98987.patch +Patch3: https://github.com/jupyter/jupyter_console/commit/84a4c63f7c2b700357f5e5f730209dc4fc897c24.patch + BuildArch: noarch BuildRequires: python3-devel @@ -99,6 +104,9 @@ echo 'exit()' | jupyter-console --simple-prompt %changelog +* Tue Aug 31 2021 Lumír Balhar - 0.6.4-5 +- Fix compatibility with jupyter-client 7 + * Fri Jul 23 2021 Fedora Release Engineering - 6.4.0-4 - Rebuilt for https://fedoraproject.org/wiki/Fedora_35_Mass_Rebuild