Browse files

use cfg._merge instead of update in loader

update clobbers existing config sections

IPython.config tests are passing again
  • Loading branch information...
1 parent 8698e5e commit 542d6a8b17e27e69d1ce8afc92680ae2b9726b36 @minrk committed Aug 6, 2011
Showing with 11 additions and 5 deletions.
  1. +9 −3 IPython/config/loader.py
  2. +2 −2 IPython/config/tests/test_loader.py
View
12 IPython/config/loader.py
@@ -598,13 +598,19 @@ def _parse_args(self, args):
def _convert_to_config(self):
"""self.parsed_data->self.config"""
for k, v in vars(self.parsed_data).iteritems():
- self._exec_config_str(k, v)
+ exec "self.config.%s = v"%k in locals(), globals()
class KVArgParseConfigLoader(ArgParseConfigLoader):
"""A config loader that loads aliases and flags with argparse,
but will use KVLoader for the rest. This allows better parsing
of common args, such as `ipython -c 'print 5'`, but still gets
arbitrary config with `ipython --InteractiveShell.use_readline=False`"""
+
+ def _convert_to_config(self):
+ """self.parsed_data->self.config"""
+ for k, v in vars(self.parsed_data).iteritems():
+ self._exec_config_str(k, v)
+
def _add_arguments(self, aliases=None, flags=None):
self.alias_flags = {}
# print aliases, flags
@@ -651,10 +657,10 @@ def _convert_to_config(self):
self._exec_config_str(k, v)
for subc in subcs:
- self.config.update(subc)
+ self._load_flag(subc)
if self.extra_args:
sub_parser = KeyValueConfigLoader()
sub_parser.load_config(self.extra_args)
- self.config.update(sub_parser.config)
+ self.config._merge(sub_parser.config)
self.extra_args = sub_parser.extra_args
View
4 IPython/config/tests/test_loader.py
@@ -70,15 +70,15 @@ def test_basic(self):
self.assertEquals(config.D.C.value, 'hi there')
class MyLoader1(ArgParseConfigLoader):
- def _add_arguments(self):
+ def _add_arguments(self, aliases=None, flags=None):
p = self.parser
p.add_argument('-f', '--foo', dest='Global.foo', type=str)
p.add_argument('-b', dest='MyClass.bar', type=int)
p.add_argument('-n', dest='n', action='store_true')
p.add_argument('Global.bam', type=str)
class MyLoader2(ArgParseConfigLoader):
- def _add_arguments(self):
+ def _add_arguments(self, aliases=None, flags=None):
subparsers = self.parser.add_subparsers(dest='subparser_name')
subparser1 = subparsers.add_parser('1')
subparser1.add_argument('-x',dest='Global.x')

0 comments on commit 542d6a8

Please sign in to comment.