From 542d6a8b17e27e69d1ce8afc92680ae2b9726b36 2011-08-17 19:56:57 From: MinRK Date: 2011-08-17 19:56:57 Subject: [PATCH] use cfg._merge instead of update in loader update clobbers existing config sections IPython.config tests are passing again --- diff --git a/IPython/config/loader.py b/IPython/config/loader.py index 3e80fb6..1e1620e 100644 --- a/IPython/config/loader.py +++ b/IPython/config/loader.py @@ -598,13 +598,19 @@ class ArgParseConfigLoader(CommandLineConfigLoader): 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 @@ class KVArgParseConfigLoader(ArgParseConfigLoader): 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 diff --git a/IPython/config/tests/test_loader.py b/IPython/config/tests/test_loader.py index e40c585..c01ef13 100755 --- a/IPython/config/tests/test_loader.py +++ b/IPython/config/tests/test_loader.py @@ -70,7 +70,7 @@ class TestPyFileCL(TestCase): 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) @@ -78,7 +78,7 @@ class MyLoader1(ArgParseConfigLoader): 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')