Skip to content

Commit 6f43a3f

Browse files
committed
Pass connection file when opening console
Before, we passed the kernel ID when calling `create_client_for_kernel()` in the IPython Console plugin. This worked, even though that function expected the connection file, because that function used `find_connection_file()` to fix the path to the connection file. After the refactor in PR spyder-ide/spyder#19062, the argument passed for the connection file is expected to be really the file path and no attempt to fix it is made, so now we have to really pass the connection file.
1 parent 3d4a3f2 commit 6f43a3f

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

spyder_notebook/notebookplugin.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""Notebook plugin."""
77

88
# Standard library imports
9+
import logging
910
import os.path as osp
1011

1112
# Spyder imports
@@ -20,6 +21,8 @@
2021
from spyder_notebook.widgets.main_widget import NotebookMainWidget
2122
from spyder_notebook.utils.localization import _
2223

24+
logger = logging.getLogger(__name__)
25+
2326

2427
class NotebookPlugin(SpyderDockablePlugin):
2528
"""Spyder Notebook plugin."""
@@ -94,10 +97,11 @@ def open_notebook(self, filenames=None):
9497
self.get_widget().open_notebook(filenames)
9598

9699
# ------ Private API ------------------------------------------------------
97-
def _open_console(self, kernel_id, tab_name):
100+
def _open_console(self, connection_file, tab_name):
98101
"""Open an IPython console as requested."""
102+
logger.info(f'Opening console with {connection_file=}')
99103
ipyconsole = self.get_plugin(Plugins.IPythonConsole)
100-
ipyconsole.create_client_for_kernel(kernel_id)
104+
ipyconsole.create_client_for_kernel(connection_file)
101105
ipyclient = ipyconsole.get_current_client()
102106
ipyclient.allow_rename = False
103107
ipyconsole.rename_client_tab(ipyclient, tab_name)

spyder_notebook/widgets/main_widget.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
# Licensed under the terms of the MIT License
55
# (see LICENSE.txt for details)
66

7+
# Standard library imports
8+
import os.path as osp
9+
710
# Third-party imports
11+
from jupyter_core.paths import jupyter_runtime_dir
812
from qtpy.QtCore import Signal
913
from qtpy.QtWidgets import QMessageBox, QVBoxLayout
1014

@@ -55,8 +59,8 @@ class NotebookMainWidget(PluginMainWidget):
5559
5660
Parameters
5761
-----------
58-
kernel_id: str
59-
Id of the kernel to open a console for.
62+
connection_file: str
63+
Name of the connection file for the kernel to open a console for.
6064
tab_name: str
6165
Tab name to set for the created console.
6266
"""
@@ -317,8 +321,10 @@ def open_console(self, client=None):
317321
)
318322
return
319323

324+
connection_file = f'kernel-{kernel_id}.json'
325+
connection_file = osp.join(jupyter_runtime_dir(), connection_file)
320326
self.sig_open_console_requested.emit(
321-
kernel_id,
327+
connection_file,
322328
client.get_short_name()
323329
)
324330

0 commit comments

Comments
 (0)