From c9e054c3ae34a9eba3e7b147b75ef29a746e598e 2010-08-13 21:44:32 From: Brian Granger Date: 2010-08-13 21:44:32 Subject: [PATCH] Moved a few things back to InteractiveShell. The following attributes were still needed in the base InteractiveShell class. * autoindent. This is used in runlines. * separate_in, separate_out, separate_out2 are used in prompt management. Eventually these things should be refactored and moved to the frontends, just not yet. --- diff --git a/IPython/config/default/ipython_config.py b/IPython/config/default/ipython_config.py index 67098c7..5a6c2eb 100644 --- a/IPython/config/default/ipython_config.py +++ b/IPython/config/default/ipython_config.py @@ -49,7 +49,7 @@ c = get_config() # c.TerminalInteractiveShell.autoedit_syntax = False -# c.TerminalInteractiveShell.autoindent = True +# c.InteractiveShell.autoindent = True # c.InteractiveShell.automagic = False @@ -116,9 +116,9 @@ c = get_config() # c.TerminalInteractiveShell.screen_length = 0 -# c.TerminalInteractiveShell.separate_in = '\n' -# c.TerminalInteractiveShell.separate_out = '' -# c.TerminalInteractiveShell.separate_out2 = '' +# c.InteractiveShell.separate_in = '\n' +# c.InteractiveShell.separate_out = '' +# c.InteractiveShell.separate_out2 = '' # c.InteractiveShell.system_header = "IPython system call: " diff --git a/IPython/config/profile/ipython_config_pysh.py b/IPython/config/profile/ipython_config_pysh.py index 437f202..ba20354 100644 --- a/IPython/config/profile/ipython_config_pysh.py +++ b/IPython/config/profile/ipython_config_pysh.py @@ -10,9 +10,9 @@ c.InteractiveShell.prompt_out = '<\#> ' c.InteractiveShell.prompts_pad_left = True -c.TerminalInteractiveShell.separate_in = '' -c.TerminalInteractiveShell.separate_out = '' -c.TerminalInteractiveShell.separate_out2 = '' +c.InteractiveShell.separate_in = '' +c.InteractiveShell.separate_out = '' +c.InteractiveShell.separate_out2 = '' c.PrefilterManager.multi_line_specials = True diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py index e585e35..4f859bf 100644 --- a/IPython/core/interactiveshell.py +++ b/IPython/core/interactiveshell.py @@ -131,6 +131,18 @@ def get_default_colors(): return 'Linux' +class SeparateStr(Str): + """A Str subclass to validate separate_in, separate_out, etc. + + This is a Str based trait that converts '0'->'' and '\\n'->'\n'. + """ + + def validate(self, obj, value): + if value == '0': value = '' + value = value.replace('\\n','\n') + return super(SeparateStr, self).validate(obj, value) + + #----------------------------------------------------------------------------- # Main IPython class #----------------------------------------------------------------------------- @@ -140,6 +152,9 @@ class InteractiveShell(Configurable, Magic): """An enhanced, interactive shell for Python.""" autocall = Enum((0,1,2), default_value=1, config=True) + # TODO: remove all autoindent logic and put into frontends. + # We can't do this yet because even runlines uses the autoindent. + autoindent = CBool(True, config=True) automagic = CBool(True, config=True) cache_size = Int(1000, config=True) color_info = CBool(True, config=True) @@ -187,6 +202,11 @@ class InteractiveShell(Configurable, Magic): '"\C-u": unix-line-discard', ], allow_none=False, config=True) + # TODO: this part of prompt management should be moved to the frontends. + # Use custom TraitTypes that convert '0'->'' and '\\n'->'\n' + separate_in = SeparateStr('\n', config=True) + separate_out = SeparateStr('', config=True) + separate_out2 = SeparateStr('', config=True) system_header = Str('IPython system call: ', config=True) system_verbose = CBool(False, config=True) wildcards_case_sensitive = CBool(True, config=True) diff --git a/IPython/frontend/terminal/interactiveshell.py b/IPython/frontend/terminal/interactiveshell.py index 5bf2770..ec10d8c 100644 --- a/IPython/frontend/terminal/interactiveshell.py +++ b/IPython/frontend/terminal/interactiveshell.py @@ -55,18 +55,6 @@ def get_default_editor(): raw_input_original = raw_input -class SeparateStr(Str): - """A Str subclass to validate separate_in, separate_out, etc. - - This is a Str based trait that converts '0'->'' and '\\n'->'\n'. - """ - - def validate(self, obj, value): - if value == '0': value = '' - value = value.replace('\\n','\n') - return super(SeparateStr, self).validate(obj, value) - - #----------------------------------------------------------------------------- # Main class #----------------------------------------------------------------------------- @@ -75,7 +63,6 @@ class SeparateStr(Str): class TerminalInteractiveShell(InteractiveShell): autoedit_syntax = CBool(False, config=True) - autoindent = CBool(True, config=True) banner = Str('') banner1 = Str(default_banner, config=True) banner2 = Str('', config=True) @@ -93,11 +80,6 @@ class TerminalInteractiveShell(InteractiveShell): pager = Str('less', config=True) screen_length = Int(0, config=True) - - # Use custom TraitTypes that convert '0'->'' and '\\n'->'\n' - separate_in = SeparateStr('\n', config=True) - separate_out = SeparateStr('', config=True) - separate_out2 = SeparateStr('', config=True) term_title = CBool(False, config=True) def __init__(self, config=None, ipython_dir=None, user_ns=None, diff --git a/IPython/frontend/terminal/ipapp.py b/IPython/frontend/terminal/ipapp.py index 6f93507..d52052a 100755 --- a/IPython/frontend/terminal/ipapp.py +++ b/IPython/frontend/terminal/ipapp.py @@ -85,10 +85,10 @@ class IPAppConfigLoader(BaseAppConfigLoader): The default is '1'.""", metavar='InteractiveShell.autocall') paa('--autoindent', - action='store_true', dest='TerminalInteractiveShell.autoindent', + action='store_true', dest='InteractiveShell.autoindent', help='Turn on autoindenting.') paa('--no-autoindent', - action='store_false', dest='TerminalInteractiveShell.autoindent', + action='store_false', dest='InteractiveShell.autoindent', help='Turn off autoindenting.') paa('--automagic', action='store_true', dest='InteractiveShell.automagic', @@ -241,17 +241,17 @@ class IPAppConfigLoader(BaseAppConfigLoader): default.""", metavar='TerminalInteractiveShell.screen_length') paa('--separate-in','-si', - type=str, dest='TerminalInteractiveShell.separate_in', + type=str, dest='InteractiveShell.separate_in', help="Separator before input prompts. Default '\\n'.", - metavar='TerminalInteractiveShell.separate_in') + metavar='InteractiveShell.separate_in') paa('--separate-out','-so', - type=str, dest='TerminalInteractiveShell.separate_out', + type=str, dest='InteractiveShell.separate_out', help="Separator before output prompts. Default 0 (nothing).", - metavar='TerminalInteractiveShell.separate_out') + metavar='InteractiveShell.separate_out') paa('--separate-out2','-so2', - type=str, dest='TerminalInteractiveShell.separate_out2', + type=str, dest='InteractiveShell.separate_out2', help="Separator after output prompts. Default 0 (nonight).", - metavar='TerminalInteractiveShell.separate_out2') + metavar='InteractiveShell.separate_out2') paa('--no-sep', action='store_true', dest='Global.nosep', help="Eliminate all spacing between prompts.") @@ -448,17 +448,17 @@ class IPythonApp(Application): config.InteractiveShell.prompt_in1 = '>>> ' config.InteractiveShell.prompt_in2 = '... ' config.InteractiveShell.prompt_out = '' - config.TerminalInteractiveShell.separate_in = \ - config.TerminalInteractiveShell.separate_out = \ - config.TerminalInteractiveShell.separate_out2 = '' + config.InteractiveShell.separate_in = \ + config.InteractiveShell.separate_out = \ + config.InteractiveShell.separate_out2 = '' config.InteractiveShell.colors = 'NoColor' config.InteractiveShell.xmode = 'Plain' if hasattr(config.Global, 'nosep'): if config.Global.nosep: - config.TerminalInteractiveShell.separate_in = \ - config.TerminalInteractiveShell.separate_out = \ - config.TerminalInteractiveShell.separate_out2 = '' + config.InteractiveShell.separate_in = \ + config.InteractiveShell.separate_out = \ + config.InteractiveShell.separate_out2 = '' # if there is code of files to run from the cmd line, don't interact # unless the -i flag (Global.force_interact) is true. diff --git a/IPython/zmq/ipkernel.py b/IPython/zmq/ipkernel.py index e206923..a9b09cf 100755 --- a/IPython/zmq/ipkernel.py +++ b/IPython/zmq/ipkernel.py @@ -267,8 +267,8 @@ def main(): print >>sys.__stdout__, "REQ Channel on port", req_port # Redirect input streams and set a display hook. - sys.stdout = OutStream(session, pub_socket, u'stdout') - sys.stderr = OutStream(session, pub_socket, u'stderr') + # sys.stdout = OutStream(session, pub_socket, u'stdout') + # sys.stderr = OutStream(session, pub_socket, u'stderr') sys.displayhook = DisplayHook(session, pub_socket) # Create the kernel.