Skip to content

Commit

Permalink
update flags&aliases for two-process apps
Browse files Browse the repository at this point in the history
swallow_args now appropriately removes only frontend-specific args,
and the apps parse front and backend args correctly
  • Loading branch information
minrk committed Dec 6, 2011
1 parent b8f41d5 commit 37a13a2
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 28 deletions.
2 changes: 0 additions & 2 deletions IPython/frontend/kernelmixinapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,6 @@ def swallow_args(self, aliases,flags, argv=None):
# Scrub frontend-specific flags
swallow_next = False
was_flag = False
# copy again, in case some aliases have the same name as a flag
# argv = list(self.kernel_argv)
for a in argv:
if swallow_next:
swallow_next = False
Expand Down
25 changes: 17 additions & 8 deletions IPython/frontend/qt/console/qtconsoleapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
from IPython.zmq.zmqshell import ZMQInteractiveShell

from IPython.frontend.kernelmixinapp import (
IPythonMixinConsoleApp, app_aliases, app_flags
IPythonMixinConsoleApp, app_aliases, app_flags, flags, aliases
)

#-----------------------------------------------------------------------------
Expand All @@ -72,8 +72,8 @@
# Aliases and Flags
#-----------------------------------------------------------------------------

# XXX: the app_flags should really be flags from the mixin
flags = dict(app_flags)
# start with copy of flags
flags = dict(flags)
qt_flags = {
'pure' : ({'IPythonQtConsoleApp' : {'pure' : True}},
"Use a pure Python kernel instead of an IPython kernel."),
Expand All @@ -85,10 +85,13 @@
"use a GUI widget for tab completion",
"use plaintext output for completion"
))
# and app_flags from the Console Mixin
qt_flags.update(app_flags)
# add frontend flags to the full set
flags.update(qt_flags)

aliases = dict(app_aliases)

# start with copy of front&backend aliases list
aliases = dict(aliases)
qt_aliases = dict(

style = 'IPythonWidget.syntax_style',
Expand All @@ -98,8 +101,17 @@
editor = 'IPythonWidget.editor',
paging = 'ConsoleWidget.paging',
)
# and app_aliases from the Console Mixin
qt_aliases.update(app_aliases)
# add frontend aliases to the full set
aliases.update(qt_aliases)

# get flags&aliases into sets, and remove a couple that
# shouldn't be scrubbed from backend flags:
qt_aliases = set(qt_aliases.keys())
qt_aliases.remove('colors')
qt_flags = set(qt_flags.keys())

#-----------------------------------------------------------------------------
# Classes
#-----------------------------------------------------------------------------
Expand Down Expand Up @@ -157,11 +169,8 @@ def _pure_changed(self, name, old, new):

def parse_command_line(self, argv=None):
super(IPythonQtConsoleApp, self).parse_command_line(argv)
IPythonMixinConsoleApp.parse_command_line(self,argv)
self.swallow_args(qt_aliases,qt_flags,argv=argv)




def new_frontend_master(self):
""" Create and return new frontend attached to new kernel, launched on localhost.
Expand Down
12 changes: 7 additions & 5 deletions IPython/frontend/terminal/ipapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ def make_report(self,traceback):
#-----------------------------------------------------------------------------
flags = dict(base_flags)
flags.update(shell_flags)
addflag = lambda *args: flags.update(boolean_flag(*args))
frontend_flags = {}
addflag = lambda *args: frontend_flags.update(boolean_flag(*args))
addflag('autoedit-syntax', 'TerminalInteractiveShell.autoedit_syntax',
'Turn on auto editing of files with syntax errors.',
'Turn off auto editing of files with syntax errors.'
Expand Down Expand Up @@ -146,7 +147,7 @@ def make_report(self,traceback):
classic_config.InteractiveShell.colors = 'NoColor'
classic_config.InteractiveShell.xmode = 'Plain'

flags['classic']=(
frontend_flags['classic']=(
classic_config,
"Gives IPython a similar feel to the classic Python prompt."
)
Expand All @@ -156,21 +157,22 @@ def make_report(self,traceback):
# help="Start logging to the default log file (./ipython_log.py).")
#
# # quick is harder to implement
flags['quick']=(
frontend_flags['quick']=(
{'TerminalIPythonApp' : {'quick' : True}},
"Enable quick startup with no config files."
)

flags['i'] = (
frontend_flags['i'] = (
{'TerminalIPythonApp' : {'force_interact' : True}},
"""If running code from the command line, become interactive afterwards.
Note: can also be given simply as '-i.'"""
)
flags['pylab'] = (
frontend_flags['pylab'] = (
{'TerminalIPythonApp' : {'pylab' : 'auto'}},
"""Pre-load matplotlib and numpy for interactive use with
the default matplotlib backend."""
)
flags.update(frontend_flags)

aliases = dict(base_aliases)
aliases.update(shell_aliases)
Expand Down
39 changes: 26 additions & 13 deletions IPython/frontend/zmqterminal/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import sys
import time

from IPython.frontend.terminal.ipapp import TerminalIPythonApp
from IPython.frontend.terminal.ipapp import TerminalIPythonApp, frontend_flags as term_flags

from IPython.utils.traitlets import (
Dict, List, Unicode, Int, CaselessStrEnum, CBool, Any
Expand All @@ -26,7 +26,7 @@
from IPython.zmq.session import Session, default_secure
from IPython.zmq.zmqshell import ZMQInteractiveShell
from IPython.frontend.kernelmixinapp import (
IPythonMixinConsoleApp, app_aliases, app_flags
IPythonMixinConsoleApp, app_aliases, app_flags, aliases, app_aliases, flags
)

from IPython.frontend.zmqterminal.interactiveshell import ZMQTerminalInteractiveShell
Expand All @@ -44,26 +44,39 @@
# Flags and Aliases
#-----------------------------------------------------------------------------

# XXX: the app_flags should really be flags from the mixin
flags = dict(app_flags)
frontend_flags = { }
# copy flags from mixin:
flags = dict(flags)
# start with mixin frontend flags:
frontend_flags = dict(app_flags)
# add TerminalIPApp flags:
frontend_flags.update(term_flags)
# pylab is not frontend-specific in two-process IPython
frontend_flags.pop('pylab')
# disable quick startup, as it won't propagate to the kernel anyway
frontend_flags.pop('quick')
# update full dict with frontend flags:
flags.update(frontend_flags)

frontend_flags = frontend_flags.keys()

aliases = dict(app_aliases)
# copy flags from mixin
aliases = dict(aliases)
# start with mixin frontend flags
frontend_aliases = dict(app_aliases)
# load updated frontend flags into full dict
aliases.update(frontend_aliases)

frontend_aliases = dict()
# get flags&aliases into sets, and remove a couple that
# shouldn't be scrubbed from backend flags:
frontend_aliases = set(frontend_aliases.keys())
frontend_flags = set(frontend_flags.keys())

aliases.update(frontend_aliases)

#-----------------------------------------------------------------------------
# Classes
#-----------------------------------------------------------------------------


class ZMQTerminalIPythonApp(TerminalIPythonApp, IPythonMixinConsoleApp):
name = "ipython console"
name = "ipython-console"
"""Start a terminal frontend to the IPython zmq kernel."""

description = """
Expand All @@ -83,13 +96,13 @@ class ZMQTerminalIPythonApp(TerminalIPythonApp, IPythonMixinConsoleApp):
"""
examples = _examples

classes = List([IPKernelApp, ZMQTerminalInteractiveShell])
classes = List([IPKernelApp, ZMQTerminalInteractiveShell, Session])
flags = Dict(flags)
aliases = Dict(aliases)
subcommands = Dict()

def parse_command_line(self, argv=None):
super(ZMQTerminalIPythonApp, self).parse_command_line(argv)
IPythonMixinConsoleApp.parse_command_line(self,argv)
self.swallow_args(frontend_aliases,frontend_flags,argv=argv)

def init_shell(self):
Expand Down

0 comments on commit 37a13a2

Please sign in to comment.