Skip to content

Commit

Permalink
Fix qtconsole issues
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbrochart committed Apr 8, 2021
1 parent aef30fe commit f655881
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 52 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
pip install --upgrade --upgrade-strategy eager --pre -e .[test] pytest-cov codecov 'coverage<5'
pip freeze
- name: Check types
run: mypy jupyter_client/manager.py jupyter_client/multikernelmanager.py jupyter_client/client.py jupyter_client/blocking/client.py jupyter_client/asynchronous/client.py jupyter_client/channels.py jupyter_client/session.py jupyter_client/adapter.py jupyter_client/connect.py jupyter_client/consoleapp.py jupyter_client/jsonutil.py jupyter_client/kernelapp.py jupyter_client/launcher.py
run: mypy jupyter_client/manager.py jupyter_client/multikernelmanager.py jupyter_client/client.py jupyter_client/blocking/client.py jupyter_client/asynchronous/client.py jupyter_client/channels.py jupyter_client/session.py jupyter_client/adapter.py jupyter_client/connect.py jupyter_client/consoleapp.py jupyter_client/jsonutil.py jupyter_client/kernelapp.py jupyter_client/launcher.py jupyter_client/threaded.py
- name: Run the tests
run: py.test --cov jupyter_client -v jupyter_client
- name: Code coverage
Expand Down
14 changes: 7 additions & 7 deletions jupyter_client/asynchronous/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ class AsyncKernelClient(KernelClient):
_recv_reply = KernelClient._async_recv_reply

# replies come on the shell channel
execute = reqrep(wrapped, KernelClient._execute)
history = reqrep(wrapped, KernelClient._history)
complete = reqrep(wrapped, KernelClient._complete)
inspect = reqrep(wrapped, KernelClient._inspect)
kernel_info = reqrep(wrapped, KernelClient._kernel_info)
comm_info = reqrep(wrapped, KernelClient._comm_info)
execute = reqrep(wrapped, KernelClient.execute)
history = reqrep(wrapped, KernelClient.history)
complete = reqrep(wrapped, KernelClient.complete)
inspect = reqrep(wrapped, KernelClient.inspect)
kernel_info = reqrep(wrapped, KernelClient.kernel_info)
comm_info = reqrep(wrapped, KernelClient.comm_info)

is_alive = KernelClient._async_is_alive
execute_interactive = KernelClient._async_execute_interactive

# replies come on the control channel
shutdown = reqrep(wrapped, KernelClient._shutdown, channel="control")
shutdown = reqrep(wrapped, KernelClient.shutdown, channel="control")
14 changes: 7 additions & 7 deletions jupyter_client/blocking/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ class BlockingKernelClient(KernelClient):
_recv_reply = run_sync(KernelClient._async_recv_reply)

# replies come on the shell channel
execute = reqrep(wrapped, KernelClient._execute)
history = reqrep(wrapped, KernelClient._history)
complete = reqrep(wrapped, KernelClient._complete)
inspect = reqrep(wrapped, KernelClient._inspect)
kernel_info = reqrep(wrapped, KernelClient._kernel_info)
comm_info = reqrep(wrapped, KernelClient._comm_info)
execute = reqrep(wrapped, KernelClient.execute)
history = reqrep(wrapped, KernelClient.history)
complete = reqrep(wrapped, KernelClient.complete)
inspect = reqrep(wrapped, KernelClient.inspect)
kernel_info = reqrep(wrapped, KernelClient.kernel_info)
comm_info = reqrep(wrapped, KernelClient.comm_info)

is_alive = run_sync(KernelClient._async_is_alive)
execute_interactive = run_sync(KernelClient._async_execute_interactive)

# replies come on the control channel
shutdown = reqrep(wrapped, KernelClient._shutdown, channel="control")
shutdown = reqrep(wrapped, KernelClient.shutdown, channel="control")
3 changes: 2 additions & 1 deletion jupyter_client/channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class HBChannel(Thread):

def __init__(
self,
context: zmq.asyncio.Context,
context: zmq.asyncio.Context = None,
session: t.Optional[Session] = None,
address: t.Union[t.Tuple[str, int], str] = "",
):
Expand Down Expand Up @@ -100,6 +100,7 @@ def _create_socket(self) -> None:
# close previous socket, before opening a new one
self.poller.unregister(self.socket)
self.socket.close()
assert self.context is not None
self.socket = self.context.socket(zmq.REQ)
self.socket.linger = 1000
self.socket.connect(self.address)
Expand Down
18 changes: 9 additions & 9 deletions jupyter_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ async def _async_wait_for_ready(self, timeout: t.Optional[float] = None) -> None

# Wait for kernel info reply on shell channel
while True:
self._kernel_info()
self.kernel_info()
try:
msg = await self.shell_channel.get_msg(timeout=1)
except Empty:
Expand Down Expand Up @@ -463,7 +463,7 @@ async def _async_execute_interactive(
allow_stdin = self.allow_stdin
if allow_stdin and not self.stdin_channel.is_alive():
raise RuntimeError("stdin channel must be running to allow input")
msg_id = self._execute(
msg_id = self.execute(
code,
silent=silent,
store_history=store_history,
Expand Down Expand Up @@ -541,7 +541,7 @@ async def _async_execute_interactive(
return await self._async_recv_reply(msg_id, timeout=timeout)

# Methods to send specific messages on channels
def _execute(
def execute(
self,
code: str,
silent: bool = False,
Expand Down Expand Up @@ -608,7 +608,7 @@ def _execute(
self.shell_channel.send(msg)
return msg["header"]["msg_id"]

def _complete(self, code: str, cursor_pos: t.Optional[int] = None) -> str:
def complete(self, code: str, cursor_pos: t.Optional[int] = None) -> str:
"""Tab complete text in the kernel's namespace.
Parameters
Expand All @@ -631,7 +631,7 @@ def _complete(self, code: str, cursor_pos: t.Optional[int] = None) -> str:
self.shell_channel.send(msg)
return msg["header"]["msg_id"]

def _inspect(self, code: str, cursor_pos: t.Optional[int] = None, detail_level: int = 0) -> str:
def inspect(self, code: str, cursor_pos: t.Optional[int] = None, detail_level: int = 0) -> str:
"""Get metadata information about an object in the kernel's namespace.
It is up to the kernel to determine the appropriate object to inspect.
Expand Down Expand Up @@ -662,7 +662,7 @@ def _inspect(self, code: str, cursor_pos: t.Optional[int] = None, detail_level:
self.shell_channel.send(msg)
return msg["header"]["msg_id"]

def _history(
def history(
self,
raw: bool = True,
output: bool = False,
Expand Down Expand Up @@ -708,7 +708,7 @@ def _history(
self.shell_channel.send(msg)
return msg["header"]["msg_id"]

def _kernel_info(self) -> str:
def kernel_info(self) -> str:
"""Request kernel info
Returns
Expand All @@ -719,7 +719,7 @@ def _kernel_info(self) -> str:
self.shell_channel.send(msg)
return msg["header"]["msg_id"]

def _comm_info(self, target_name: t.Optional[str] = None) -> str:
def comm_info(self, target_name: t.Optional[str] = None) -> str:
"""Request comm info
Returns
Expand Down Expand Up @@ -760,7 +760,7 @@ def input(self, string: str) -> None:
msg = self.session.msg("input_reply", content)
self.stdin_channel.send(msg)

def _shutdown(self, restart: bool = False) -> str:
def shutdown(self, restart: bool = False) -> str:
"""Request an immediate kernel shutdown on the control channel.
Upon receipt of the (empty) reply, client code can safely assume that
Expand Down
6 changes: 3 additions & 3 deletions jupyter_client/ssh/tunnel.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@

SSHException = paramiko.ssh_exception.SSHException
except ImportError:
paramiko = None
paramiko = None # type: ignore

class SSHException(Exception):
class SSHException(Exception): # type: ignore
pass


else:
from .forward import forward_tunnel

try:
import pexpect
import pexpect # type: ignore
except ImportError:
pexpect = None

Expand Down
Loading

0 comments on commit f655881

Please sign in to comment.