Skip to content

Commit

Permalink
Pass connection file when opening console
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jitseniesen committed May 8, 2023
1 parent 012a09d commit e02f792
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
8 changes: 6 additions & 2 deletions spyder_notebook/notebookplugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"""Notebook plugin."""

# Standard library imports
import logging
import os.path as osp

# Spyder imports
Expand All @@ -20,6 +21,8 @@
from spyder_notebook.widgets.main_widget import NotebookMainWidget
from spyder_notebook.utils.localization import _

logger = logging.getLogger(__name__)


class NotebookPlugin(SpyderDockablePlugin):
"""Spyder Notebook plugin."""
Expand Down Expand Up @@ -94,10 +97,11 @@ def open_notebook(self, filenames=None):
self.get_widget().open_notebook(filenames)

# ------ Private API ------------------------------------------------------
def _open_console(self, kernel_id, tab_name):
def _open_console(self, connection_file, tab_name):
"""Open an IPython console as requested."""
logger.info(f'Opening console with {connection_file=}')
ipyconsole = self.get_plugin(Plugins.IPythonConsole)
ipyconsole.create_client_for_kernel(kernel_id)
ipyconsole.create_client_for_kernel(connection_file)
ipyclient = ipyconsole.get_current_client()
ipyclient.allow_rename = False
ipyconsole.rename_client_tab(ipyclient, tab_name)
Expand Down
12 changes: 9 additions & 3 deletions spyder_notebook/widgets/main_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
# Licensed under the terms of the MIT License
# (see LICENSE.txt for details)

# Standard library imports
import os.path as osp

# Third-party imports
from jupyter_core.paths import jupyter_runtime_dir
from qtpy.QtCore import Signal
from qtpy.QtWidgets import QMessageBox, QVBoxLayout

Expand Down Expand Up @@ -55,8 +59,8 @@ class NotebookMainWidget(PluginMainWidget):
Parameters
-----------
kernel_id: str
Id of the kernel to open a console for.
connection_file: str
Name of the connection file for the kernel to open a console for.
tab_name: str
Tab name to set for the created console.
"""
Expand Down Expand Up @@ -317,8 +321,10 @@ def open_console(self, client=None):
)
return

connection_file = f'kernel-{kernel_id}.json'
connection_file = osp.join(jupyter_runtime_dir(), connection_file)
self.sig_open_console_requested.emit(
kernel_id,
connection_file,
client.get_short_name()
)

Expand Down

0 comments on commit e02f792

Please sign in to comment.