Commits

Anonymous committed 6395875 Draft

pep8 (ignoring E501 --line length-- in tests)

  • Participants
  • Parent commits 0ec8888
  • Branches v0.5

Comments (0)

Files changed (2)

argparse_config.src/argparse_config/__init__.py

 
 __version__ = '0.5'
 
+
 def read_config_file(arg_parser, filename):
     config_parser = ConfigParser.SafeConfigParser(allow_no_value=True)
     config_parser.read([filename])
     read_config_parser(arg_parser, config_parser)
 
+
 def read_config_parser(arg_parser, config_parser):
     ReadConfig(config_parser=config_parser).walk_parser(arg_parser)
 
-def generate_config(arg_parser, parsed_args, section='default', only_non_defaults=False):
-    action = GenerateConfig(parsed_args, section, only_non_defaults=only_non_defaults)
+
+def generate_config(arg_parser, parsed_args, section='default',
+                    only_non_defaults=False):
+    action = GenerateConfig(parsed_args, section,
+                            only_non_defaults=only_non_defaults)
     action.walk_parser(arg_parser)
     return action.contents
 
+
 class ArgParserWalker(object):
-
     def start_section(self, section_name):
         raise NotImplementedError()
+
     def end_section(self):
         raise NotImplementedError()
+
     def process_parser_action(self, action, is_store_const=False):
         raise NotImplementedError()
 
                         self.end_section()
             self.end_section()
         except DefaultError as e:
-            arg_parser.error(u'[{section_name}] config option "{option_string}" must be {type_transformer}() value, got: {value}'.format(
-                section_name=e.section_name,
-                option_string = e.option_string,
-                type_transformer=e.type_transformer.__name__,
-                value=e.value
-            ))
+            arg_parser.error(
+                u'[{section_name}] config option "{option_string}" '
+                u'must be {type_transformer}() value, got: {value}'.format(
+                    section_name=e.section_name,
+                    option_string=e.option_string,
+                    type_transformer=e.type_transformer.__name__,
+                    value=e.value
+                ))
+
 
 class GenerateConfig(ArgParserWalker):
-
     def __init__(self, parsed_args, section, only_non_defaults=False):
         self.parsed_args = parsed_args
         self._contents = []
     def process_parser_action(self, action, is_store_const=False):
         if not self._in_section:
             return
-        # take the longest string, since that is likely the most informative
+            # take the longest string, likely the most informative
         action_name = list(action.option_strings)
         action_name.sort(key=lambda s: len(s), reverse=True)
         action_name = _convert_option_string(action_name[0])
             else:
                 self._contents.append(u'{action_name}: {default_value}'.format(
                     action_name=action_name,
-                    default_value=action_value, # and hope it prints the way we want it to...
+                    default_value=action_value,  # hope it prints as wanted...
                 ))
 
 
 class ReadConfig(ArgParserWalker):
-
     def __init__(self, config_parser=None):
         self.sections = []
         self.config_parser = config_parser
     def process_parser_action(self, action, is_store_const=False):
         for option_string in action.option_strings:
             option_string = _convert_option_string(option_string)
-            if self.config_parser.has_option(self.current_section, option_string):
+            if self.config_parser.has_option(self.current_section,
+                                             option_string):
                 if is_store_const:
                     action.default = action.const
                 else:
-                    value = self.config_parser.get(self.current_section, option_string)
-                    type_transformer = action.type if action.type is not None else lambda x:x
+                    value = self.config_parser.get(self.current_section,
+                                                   option_string)
+                    type_transformer = (action.type if action.type is not None
+                                        else lambda x: x)
                     try:
                         action.default = type_transformer(value)
                     except:
-                        raise DefaultError(self.current_section, option_string, value, type_transformer)
+                        raise DefaultError(self.current_section,
+                                           option_string,
+                                           value,
+                                           type_transformer)
                 action.required = False
 
+
 class DefaultError(Exception):
     def __init__(self, section_name, option_string, value, type_transformer):
         self.section_name = section_name
         self.value = value
         self.type_transformer = type_transformer
 
+
 def _convert_option_string(op_s):
     return op_s.lstrip('-').replace('-', '_')
-

argparse_config.src/argparse_config/tests/__init__.py

 
 __author__ = 'tikitu'
 
+
 def with_config_file():
     def decorator(f):
         @functools.wraps(f)
             config_parser = SafeConfigParser(allow_no_value=True)
             config_parser.readfp(StringIO(config_file))
             return f(self, config_parser)
+
         return wrapper
+
     return decorator
 
+
 class DefaultsTest(TestCase):
-
     @with_config_file()
     def test_types(self, config_parser):
-        '''
+        """
         [default]
         int_v: 1
         string_v: s
         false_bool_v:
         true_bool_v: 1
         float_v: 1.5
-        '''
+        """
 
         arg_parser = ArgumentParser()
         arg_parser.add_argument('--int-v', default=2, type=int)
         read_config_parser(arg_parser, config_parser)
 
         parsed_args = arg_parser.parse_args(['merge'])
-        self.assertEqual(parsed_args.repository, 'https://tikitu@bitbucket.org/tikitu/argparse_config')
+        self.assertEqual(parsed_args.repository,
+                         'https://tikitu@bitbucket.org/tikitu/argparse_config')
         self.assertEqual(parsed_args.tool, 'meld')
 
         parsed_args = arg_parser.parse_args(['commit'])
-        self.assertEqual(parsed_args.user, 'Tikitu de Jager <tikitu@logophile.org>')
+        self.assertEqual(parsed_args.user,
+                         'Tikitu de Jager <tikitu@logophile.org>')
 
     @with_config_file()
     def test_required(self, config_parser):
         parsed_args = arg_parser.parse_args([])
         self.assertTrue(parsed_args.verbose)
 
+
 class DefaultsOutputTest(TestCase):
-
     @with_config_file()
     def test_everything(self, config_parser):
         """
         flag:
         """.lstrip('\n')))
 
-
     @with_config_file()
     def test_everything(self, config_parser):
         """
         [default]
         flag
         """
+
         def check_round_trip(arg_parser):
             read_config_parser(arg_parser, config_parser)
             parsed_args = arg_parser.parse_args([])