Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR: Implement dedicated IPython consoles #4691

Merged
merged 15 commits into from
Jul 4, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
IPython console: Initial implementation of dedicated consoles
  • Loading branch information
ccordoba12 committed Jul 3, 2017
commit 0b7eb27bfd982ea41e9870bb6d03ee6aa70cfbbf
6 changes: 3 additions & 3 deletions spyder/plugins/editor.py
Original file line number Diff line number Diff line change
@@ -369,7 +369,7 @@ class Editor(SpyderPluginWidget):
DISABLE_ACTIONS_WHEN_HIDDEN = False # SpyderPluginWidget class attribute

# Signals
run_in_current_ipyclient = Signal(str, str, str, bool, bool, bool)
run_in_current_ipyclient = Signal(str, str, str, bool, bool, bool, bool)
exec_in_extconsole = Signal(str, bool)
redirect_stdio = Signal(bool)
open_dir = Signal(str)
@@ -2408,10 +2408,10 @@ def re_run_file(self):
(fname, wdir, args, interact, debug,
python, python_args, current, systerm,
post_mortem, clear_namespace) = self.__last_ec_exec
if current:
if not systerm:
self.run_in_current_ipyclient.emit(fname, wdir, args,
debug, post_mortem,
clear_namespace)
current, clear_namespace)
else:
self.main.open_external_console(fname, wdir, args, interact,
debug, python, python_args,
47 changes: 38 additions & 9 deletions spyder/plugins/ipythonconsole.py
Original file line number Diff line number Diff line change
@@ -799,8 +799,7 @@ def register_plugin(self):
self.editor.load(fname, lineno, word,
processevents=processevents))
self.editor.breakpoints_saved.connect(self.set_spyder_breakpoints)
self.editor.run_in_current_ipyclient.connect(
self.run_script_in_current_client)
self.editor.run_in_current_ipyclient.connect(self.run_script)
self.main.workingdirectory.set_current_console_wd.connect(
self.set_current_client_working_directory)
self.explorer.open_interpreter.connect(self.create_client_from_path)
@@ -830,11 +829,20 @@ def get_current_shellwidget(self):
if client is not None:
return client.shellwidget

def run_script_in_current_client(self, filename, wdir, args, debug,
post_mortem, clear_variables):
"""Run script in current client, if any"""
def run_script(self, filename, wdir, args, debug, post_mortem,
current_client, clear_variables):
"""Run script in current or dedicated client"""
norm = lambda text: remove_backslashes(to_text_string(text))
client = self.get_current_client()

# Select client to execute code on it
if current_client:
client = self.get_current_client()
else:
client = self.get_client_for_file(filename)
if client is None:
self.create_client_for_file(filename)
client = self.get_current_client()

if client is not None:
# Internal kernels, use runfile
if client.get_kernel() is not None:
@@ -854,7 +862,7 @@ def run_script_in_current_client(self, filename, wdir, args, debug,
line += "\"%s\"" % to_text_string(filename)
if args:
line += " %s" % norm(args)
self.execute_code(line, clear_variables)
self.execute_code(line, current_client, clear_variables)
self.visibility_changed(True)
self.raise_()
else:
@@ -871,14 +879,19 @@ def set_current_client_working_directory(self, directory):
directory = encoding.to_unicode_from_fs(directory)
shellwidget.set_cwd(directory)

def execute_code(self, lines, clear_variables=False):
def execute_code(self, lines, current_client, clear_variables=False):
"""Execute code instructions."""
sw = self.get_current_shellwidget()
if sw is not None:
if sw._reading:
pass
else:
if clear_variables:
if not current_client:
# Clear console and reset namespace for
# dedicated clients
sw.silent_execute('%clear')
sw.reset_namespace(force=True)
elif current_client and clear_variables:
sw.reset_namespace(force=True)
sw.execute(to_text_string(to_text_string(lines)))
self.activateWindow()
@@ -1246,6 +1259,22 @@ def create_client_from_path(self, path):
sw = self.get_current_shellwidget()
sw.set_cwd(path)

def create_client_for_file(self, filename):
"""Create a client to execute code related to a file."""
self.create_new_client()
client = self.get_current_client()
client.allow_rename = False
self.rename_client_tab(client, filename)

def get_client_for_file(self, filename):
"""Get client associated with a given file."""
client = None
for cl in self.get_clients():
if cl.given_name == filename:
client = cl
break
return client

#------ Public API (for kernels) ------------------------------------------
def ssh_tunnel(self, *args, **kwargs):
if os.name == 'nt':