Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Quentin Peter committed Sep 19, 2023
1 parent d4efe98 commit d819951
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 24 deletions.
9 changes: 5 additions & 4 deletions spyder/plugins/ipythonconsole/widgets/main_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -1454,10 +1454,11 @@ def create_new_client(self, give_focus=True, filename='', special=None,
str_id='A')

# Find what kind of kernel we want
if self.get_conf('pylab/autoload'):
special = "pylab"
elif self.get_conf('symbolic_math'):
special = "sympy"
if special is None:
if self.get_conf('pylab/autoload'):
special = "pylab"
elif self.get_conf('symbolic_math'):
special = "sympy"

client = ClientWidget(
self,
Expand Down
38 changes: 18 additions & 20 deletions spyder/plugins/ipythonconsole/widgets/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def spyder_kernel_ready(self):
"""
if self.kernel_handler is None:
return False
return (
return (self.is_kernel_configured and
self.kernel_handler.connection_state ==
KernelConnectionState.SpyderKernelReady)

Expand Down Expand Up @@ -304,7 +304,8 @@ def handle_kernel_is_ready(self):
self.kernel_handler.connection_state ==
KernelConnectionState.SpyderKernelReady
):
self.setup_spyder_kernel()
self.kernel_connect_sig()
self.send_spyder_kernel_configuration()

def _started_channels(self):
"""Make a history request"""
Expand Down Expand Up @@ -393,9 +394,9 @@ def is_external_kernel(self):
if self.kernel_handler is None:
return False
return self.kernel_handler.kernel_spec_dict is None

def setup_spyder_kernel(self):
"""Setup spyder kernel"""
def kernel_connect_sig(self):
"""Connect signals for kernel."""
if not self._init_kernel_setup:
# Only do this setup once
self._init_kernel_setup = True
Expand All @@ -417,21 +418,9 @@ def setup_spyder_kernel(self):
for request_id, handler in self.kernel_comm_handlers.items():
self.kernel_handler.kernel_comm.register_call_handler(
request_id, handler)

# Setup to do after restart
# Check for fault and send config
self.kernel_handler.poll_fault_text()

self.send_spyder_kernel_configuration()

run_lines = self.get_conf('startup/run_lines')
if run_lines:
self.execute(run_lines, hidden=True)

if self.get_conf('startup/use_run_file'):
run_file = self.get_conf('startup/run_file')
if run_file:
self.execute(f"exec(open({run_file}))", hidden=True)
else:
# kernel might have restarted
self.kernel_handler.poll_fault_text()

def send_spyder_kernel_configuration(self):
"""Send kernel configuration to spyder kernel."""
Expand Down Expand Up @@ -470,6 +459,15 @@ def send_spyder_kernel_configuration(self):
callback=self.kernel_configure_callback
).set_configuration(self._kernel_configuration)

run_lines = self.get_conf('startup/run_lines')
if run_lines:
self.execute(run_lines, hidden=True)

if self.get_conf('startup/use_run_file'):
run_file = self.get_conf('startup/run_file')
if run_file:
self.execute(f"exec(open({run_file}))", hidden=True)

self.is_kernel_configured = True

def set_kernel_configuration(self, key, value):
Expand Down

0 comments on commit d819951

Please sign in to comment.