Skip to content

Commit

Permalink
Fix another small bug in stripping kernel args
Browse files Browse the repository at this point in the history
Problem case: flags and aliases with the same name (e.g. existing)

would attempt removal twice, raising ValueError

closes gh-906
  • Loading branch information
minrk committed Oct 20, 2011
1 parent 87e2f91 commit bae849b
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions IPython/frontend/qt/console/qtconsoleapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,20 +327,23 @@ def parse_command_line(self, argv=None):
super(IPythonQtConsoleApp, self).parse_command_line(argv)
if argv is None:
argv = sys.argv[1:]

self.kernel_argv = list(argv) # copy
# kernel should inherit default config file from frontend
self.kernel_argv.append("--KernelApp.parent_appname='%s'"%self.name)
# Scrub frontend-specific flags
for a in argv:
if a.startswith('-') and a.lstrip('-') in qt_flags:
self.kernel_argv.remove(a)
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:
self.kernel_argv.remove(a)
swallow_next = False
continue
# last arg was an alias, remove the next one
# *unless* the last alias has a no-arg flag version, in which
# case, don't swallow the next arg if it's also a flag:
if not (was_flag and a.startswith('-')):
self.kernel_argv.remove(a)
continue
if a.startswith('-'):
split = a.lstrip('-').split('=')
alias = split[0]
Expand All @@ -349,6 +352,12 @@ def parse_command_line(self, argv=None):
if len(split) == 1:
# alias passed with arg via space
swallow_next = True
# could have been a flag that matches an alias, e.g. `existing`
# in which case, we might not swallow the next arg
was_flag = alias in qt_flags
elif alias in qt_flags:
# strip flag, but don't swallow next, as flags don't take args
self.kernel_argv.remove(a)

def init_connection_file(self):
"""find the connection file, and load the info if found.
Expand Down

0 comments on commit bae849b

Please sign in to comment.