##// END OF EJS Templates
use cfg._merge instead of update in loader...
MinRK -
Show More
@@ -598,13 +598,19 b' class ArgParseConfigLoader(CommandLineConfigLoader):'
598 def _convert_to_config(self):
598 def _convert_to_config(self):
599 """self.parsed_data->self.config"""
599 """self.parsed_data->self.config"""
600 for k, v in vars(self.parsed_data).iteritems():
600 for k, v in vars(self.parsed_data).iteritems():
601 self._exec_config_str(k, v)
601 exec "self.config.%s = v"%k in locals(), globals()
602
602
603 class KVArgParseConfigLoader(ArgParseConfigLoader):
603 class KVArgParseConfigLoader(ArgParseConfigLoader):
604 """A config loader that loads aliases and flags with argparse,
604 """A config loader that loads aliases and flags with argparse,
605 but will use KVLoader for the rest. This allows better parsing
605 but will use KVLoader for the rest. This allows better parsing
606 of common args, such as `ipython -c 'print 5'`, but still gets
606 of common args, such as `ipython -c 'print 5'`, but still gets
607 arbitrary config with `ipython --InteractiveShell.use_readline=False`"""
607 arbitrary config with `ipython --InteractiveShell.use_readline=False`"""
608
609 def _convert_to_config(self):
610 """self.parsed_data->self.config"""
611 for k, v in vars(self.parsed_data).iteritems():
612 self._exec_config_str(k, v)
613
608 def _add_arguments(self, aliases=None, flags=None):
614 def _add_arguments(self, aliases=None, flags=None):
609 self.alias_flags = {}
615 self.alias_flags = {}
610 # print aliases, flags
616 # print aliases, flags
@@ -651,10 +657,10 b' class KVArgParseConfigLoader(ArgParseConfigLoader):'
651 self._exec_config_str(k, v)
657 self._exec_config_str(k, v)
652
658
653 for subc in subcs:
659 for subc in subcs:
654 self.config.update(subc)
660 self._load_flag(subc)
655
661
656 if self.extra_args:
662 if self.extra_args:
657 sub_parser = KeyValueConfigLoader()
663 sub_parser = KeyValueConfigLoader()
658 sub_parser.load_config(self.extra_args)
664 sub_parser.load_config(self.extra_args)
659 self.config.update(sub_parser.config)
665 self.config._merge(sub_parser.config)
660 self.extra_args = sub_parser.extra_args
666 self.extra_args = sub_parser.extra_args
@@ -70,7 +70,7 b' class TestPyFileCL(TestCase):'
70 self.assertEquals(config.D.C.value, 'hi there')
70 self.assertEquals(config.D.C.value, 'hi there')
71
71
72 class MyLoader1(ArgParseConfigLoader):
72 class MyLoader1(ArgParseConfigLoader):
73 def _add_arguments(self):
73 def _add_arguments(self, aliases=None, flags=None):
74 p = self.parser
74 p = self.parser
75 p.add_argument('-f', '--foo', dest='Global.foo', type=str)
75 p.add_argument('-f', '--foo', dest='Global.foo', type=str)
76 p.add_argument('-b', dest='MyClass.bar', type=int)
76 p.add_argument('-b', dest='MyClass.bar', type=int)
@@ -78,7 +78,7 b' class MyLoader1(ArgParseConfigLoader):'
78 p.add_argument('Global.bam', type=str)
78 p.add_argument('Global.bam', type=str)
79
79
80 class MyLoader2(ArgParseConfigLoader):
80 class MyLoader2(ArgParseConfigLoader):
81 def _add_arguments(self):
81 def _add_arguments(self, aliases=None, flags=None):
82 subparsers = self.parser.add_subparsers(dest='subparser_name')
82 subparsers = self.parser.add_subparsers(dest='subparser_name')
83 subparser1 = subparsers.add_parser('1')
83 subparser1 = subparsers.add_parser('1')
84 subparser1.add_argument('-x',dest='Global.x')
84 subparser1.add_argument('-x',dest='Global.x')
General Comments 0
You need to be logged in to leave comments. Login now