Skip to content

Commit 256b586

Browse files
committed
add client 7 support
1 parent 2269413 commit 256b586

File tree

6 files changed

+50
-20
lines changed

6 files changed

+50
-20
lines changed

.github/workflows/python-package.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,11 @@ jobs:
3737
- name: Test with pytest
3838
run: |
3939
pytest --cov jupyter_console || pytest jupyter_console --lf
40-
- name: Check Manifest
40+
- name: Linting
4141
run: |
4242
check-manifest
43+
pip install mypy
44+
mypy .
4345
4446
check_release:
4547
runs-on: ubuntu-latest

docs/conf.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import os
1818
import shlex
1919
import shutil
20+
from typing import Dict
2021

2122
# If extensions (or modules to document with autodoc) are in another directory,
2223
# add these directories to sys.path here. If the directory is relative to the
@@ -74,7 +75,7 @@
7475
# built documents.
7576
#
7677

77-
version_ns = {}
78+
version_ns: Dict = {}
7879
version_py = os.path.join('..', 'jupyter_console', '_version.py')
7980
with open(version_py) as f:
8081
exec(compile(f.read(), version_py, 'exec'), version_ns)
@@ -229,7 +230,7 @@
229230

230231
# -- Options for LaTeX output ---------------------------------------------
231232

232-
latex_elements = {
233+
#latex_elements = {
233234
# The paper size ('letterpaper' or 'a4paper').
234235
#'papersize': 'letterpaper',
235236

@@ -241,7 +242,7 @@
241242

242243
# Latex figure (float) alignment
243244
#'figure_align': 'htbp',
244-
}
245+
#}
245246

246247
# Grouping the document tree into LaTeX files. List of tuples
247248
# (source start file, target name, title,

jupyter_console/app.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
#-----------------------------------------------------------------------------
6464

6565

66-
class ZMQTerminalIPythonApp(JupyterApp, JupyterConsoleApp):
66+
class ZMQTerminalIPythonApp(JupyterApp, JupyterConsoleApp): # type:ignore[misc]
6767
name = "jupyter-console"
6868
version = __version__
6969
"""Start a terminal frontend to the IPython zmq kernel."""
@@ -85,9 +85,9 @@ class ZMQTerminalIPythonApp(JupyterApp, JupyterConsoleApp):
8585
"""
8686
examples = _examples
8787

88-
classes = [ZMQTerminalInteractiveShell] + JupyterConsoleApp.classes
89-
flags = Dict(flags)
90-
aliases = Dict(aliases)
88+
classes = [ZMQTerminalInteractiveShell] + JupyterConsoleApp.classes # type:ignore[operator]
89+
flags = Dict(flags) # type:ignore[assignment]
90+
aliases = Dict(aliases) # type:ignore[assignment]
9191
frontend_aliases = Any(frontend_aliases)
9292
frontend_flags = Any(frontend_flags)
9393

jupyter_console/ptshell.py

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import sys
1414
from tempfile import TemporaryDirectory
1515
import time
16+
import typing as t
1617
from warnings import warn
1718

1819
from typing import Dict as DictType, Any as AnyType
@@ -30,6 +31,7 @@
3031
Instance,
3132
Any,
3233
)
34+
import inspect
3335
from traitlets.config import SingletonConfigurable
3436

3537
from .completer import ZMQCompleter
@@ -76,6 +78,30 @@
7678
from pygments.util import ClassNotFound
7779
from pygments.token import Token
7880

81+
from jupyter_core.utils import run_sync as _run_sync
82+
83+
84+
T = t.TypeVar("T")
85+
86+
87+
def run_sync(coro: t.Callable[..., t.Union[T, t.Awaitable[T]]]) -> t.Callable[..., T]:
88+
"""Wraps coroutine in a function that blocks until it has executed.
89+
90+
Parameters
91+
----------
92+
coro : coroutine-function
93+
The coroutine-function to be executed.
94+
95+
Returns
96+
-------
97+
result :
98+
Whatever the coroutine-function returns.
99+
"""
100+
if not inspect.iscoroutinefunction(coro):
101+
return t.cast(t.Callable[..., T], coro)
102+
return _run_sync(coro)
103+
104+
79105

80106
def ask_yes_no(prompt, default=None, interrupt=None):
81107
"""Asks a question and returns a boolean (y/n) answer.
@@ -314,7 +340,7 @@ class ZMQTerminalInteractiveShell(SingletonConfigurable):
314340
),
315341
default_value="multicolumn",
316342
).tag(config=True)
317-
343+
318344
prompt_includes_vi_mode = Bool(True,
319345
help="Display the current vi mode (when using vi editing mode)."
320346
).tag(config=True)
@@ -372,7 +398,7 @@ def vi_mode(self):
372398
and self.prompt_includes_vi_mode):
373399
return '['+str(self.pt_cli.app.vi_state.input_mode)[3:6]+'] '
374400
return ''
375-
401+
376402
def get_prompt_tokens(self, ec=None):
377403
if ec is None:
378404
ec = self.execution_count
@@ -705,8 +731,8 @@ def run_cell(self, cell, store_history=True):
705731
return
706732

707733
# flush stale replies, which could have been ignored, due to missed heartbeats
708-
while self.client.shell_channel.msg_ready():
709-
self.client.shell_channel.get_msg()
734+
while run_sync(self.client.shell_channel.msg_ready)():
735+
run_sync(self.client.shell_channel.get_msg)()
710736
# execute takes 'hidden', which is the inverse of store_hist
711737
msg_id = self.client.execute(cell, not store_history)
712738

@@ -740,7 +766,7 @@ def run_cell(self, cell, store_history=True):
740766

741767
def handle_execute_reply(self, msg_id, timeout=None):
742768
kwargs = {"timeout": timeout}
743-
msg = self.client.shell_channel.get_msg(**kwargs)
769+
msg = run_sync(self.client.shell_channel.get_msg)(**kwargs)
744770
if msg["parent_header"].get("msg_id", None) == msg_id:
745771

746772
self.handle_iopub(msg_id)
@@ -780,7 +806,7 @@ def handle_is_complete_reply(self, msg_id, timeout=None):
780806
msg = None
781807
try:
782808
kwargs = {"timeout": timeout}
783-
msg = self.client.shell_channel.get_msg(**kwargs)
809+
msg = run_sync(self.client.shell_channel.get_msg)(**kwargs)
784810
except Empty:
785811
warn('The kernel did not respond to an is_complete_request. '
786812
'Setting `use_kernel_is_complete` to False.')
@@ -849,8 +875,8 @@ def handle_iopub(self, msg_id=''):
849875
850876
It only displays output that is caused by this session.
851877
"""
852-
while self.client.iopub_channel.msg_ready():
853-
sub_msg = self.client.iopub_channel.get_msg()
878+
while run_sync(self.client.iopub_channel.msg_ready)():
879+
sub_msg = run_sync(self.client.iopub_channel.get_msg)()
854880
msg_type = sub_msg['header']['msg_type']
855881

856882
# Update execution_count in case it changed in another session
@@ -1003,7 +1029,7 @@ def handle_image_callable(self, data, mime):
10031029
def handle_input_request(self, msg_id, timeout=0.1):
10041030
""" Method to capture raw_input
10051031
"""
1006-
req = self.client.stdin_channel.get_msg(timeout=timeout)
1032+
req = run_sync(self.client.stdin_channel.get_msg)(timeout=timeout)
10071033
# in case any iopub came while we were waiting:
10081034
self.handle_iopub(msg_id)
10091035
if msg_id == req["parent_header"].get("msg_id"):
@@ -1032,6 +1058,6 @@ def double_int(sig, frame):
10321058

10331059
# only send stdin reply if there *was not* another request
10341060
# or execution finished while we were reading.
1035-
if not (self.client.stdin_channel.msg_ready() or
1036-
self.client.shell_channel.msg_ready()):
1061+
if not (run_sync(self.client.stdin_channel.msg_ready)() or
1062+
run_sync(self.client.shell_channel.msg_ready)()):
10371063
self.client.input(raw_data)

jupyter_console/tests/test_console.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
def test_console_starts():
2222
"""test that `jupyter console` starts a terminal"""
2323
p, pexpect, t = start_console()
24+
import pdb; pdb.set_trace()
2425
p.sendline("5")
2526
p.expect([r"Out\[\d+\]: 5", pexpect.EOF], timeout=t)
2627
p.expect([r"In \[\d+\]", pexpect.EOF], timeout=t)

mypy.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[mypy]
2-
python_version = 3.7
2+
python_version = 3.8
33
ignore_missing_imports = True
44
follow_imports = silent

0 commit comments

Comments
 (0)