← Back to team overview

configglue team mailing list archive

[Merge] lp:~ricardokirkner/configglue/refactor-options-stringoption into lp:configglue

 

Ricardo Kirkner has proposed merging lp:~ricardokirkner/configglue/refactor-options-stringoption into lp:configglue with lp:~ricardokirkner/configglue/refactor-options-pep8 as a prerequisite.

Requested reviews:
  Configglue developers (configglue)

For more details, see:
https://code.launchpad.net/~ricardokirkner/configglue/refactor-options-stringoption/+merge/64434
-- 
https://code.launchpad.net/~ricardokirkner/configglue/refactor-options-stringoption/+merge/64434
Your team Configglue developers is requested to review the proposed merge of lp:~ricardokirkner/configglue/refactor-options-stringoption into lp:configglue.
=== modified file 'configglue/inischema/glue.py'
--- configglue/inischema/glue.py	2011-06-13 18:45:53 +0000
+++ configglue/inischema/glue.py	2011-06-13 18:45:53 +0000
@@ -32,7 +32,7 @@
     IntConfigOption,
     LinesConfigOption,
     Schema,
-    StringConfigOption,
+    StringOption,
 )
 
 
@@ -58,7 +58,7 @@
     p.readfp(fd)
     p.parse_all()
 
-    parser2option = {'unicode': StringConfigOption,
+    parser2option = {'unicode': StringOption,
                      'int': IntConfigOption,
                      'bool': BoolConfigOption,
                      'lines': LinesConfigOption}
@@ -93,9 +93,9 @@
             if option_action is not None:
                 attrs['action'] = option_action
 
-            klass = parser2option.get(parser, StringConfigOption)
+            klass = parser2option.get(parser, StringOption)
             if parser == 'lines':
-                instance = klass(item=StringConfigOption(), **attrs)
+                instance = klass(item=StringOption(), **attrs)
             else:
                 instance = klass(**attrs)
             setattr(section, option_name, instance)

=== modified file 'configglue/pyschema/schema.py'
--- configglue/pyschema/schema.py	2011-06-13 18:45:53 +0000
+++ configglue/pyschema/schema.py	2011-06-13 18:45:53 +0000
@@ -17,6 +17,7 @@
 
 from copy import deepcopy
 from inspect import getmembers
+from warnings import warn
 
 
 __all__ = [
@@ -28,6 +29,7 @@
     'LinesConfigOption',
     'Schema',
     'StringConfigOption',
+    'StringOption',
     'TupleConfigOption',
 ]
 
@@ -69,7 +71,7 @@
     """
 
     def __init__(self):
-        self.includes = LinesConfigOption(item=StringConfigOption())
+        self.includes = LinesConfigOption(item=StringOption())
         self._sections = {}
         # add section and options to the schema
         for name, item in get_config_objects(self.__class__):
@@ -387,7 +389,7 @@
         return isinstance(value, list)
 
 
-class StringConfigOption(ConfigOption):
+class StringOption(ConfigOption):
     """A ConfigOption that is parsed into a string.
 
     If null==True, a value of 'None' will be parsed in to None instead of
@@ -398,7 +400,7 @@
     def __init__(self, name='', raw=False, default=NO_DEFAULT, fatal=False,
         null=False, help='', action='store'):
         self.null = null
-        super(StringConfigOption, self).__init__(name=name, raw=raw,
+        super(StringOption, self).__init__(name=name, raw=raw,
             default=default, fatal=fatal, help=help, action=action)
 
     def _get_default(self):
@@ -490,7 +492,7 @@
         if spec is None:
             spec = {}
         if item is None:
-            item = StringConfigOption()
+            item = StringOption()
         self.spec = spec
         self.strict = strict
         self.item = item
@@ -575,3 +577,17 @@
                 sections.extend(extra)
 
         return sections
+
+#
+# deprecated
+#
+
+class DeprecatedOption(type):
+    def __init__(cls, name, bases, attrs):
+        warn('{0} is deprecated; use {1} instead.'.format(
+            name, bases[0].__name__), DeprecationWarning)
+        type.__init__(cls, name, bases, attrs)
+
+
+class StringConfigOption(StringOption):
+    __metaclass__ = DeprecatedOption

=== modified file 'doc/howto/custom-schema-options.rst'
--- doc/howto/custom-schema-options.rst	2011-04-21 02:42:18 +0000
+++ doc/howto/custom-schema-options.rst	2011-06-13 18:45:53 +0000
@@ -83,5 +83,5 @@
 .. note::
     Note that the dictionary values are strings because we didn't specify an
     item type for the ``UpperCaseDictConfigOption``, and so it defaulted to
-    :class:`~configglue.pyschema.schema.StringConfigOption`.
+    :class:`~configglue.pyschema.schema.StringOption`.
 

=== modified file 'doc/ref/schemas/options.rst'
--- doc/ref/schemas/options.rst	2011-05-02 15:17:01 +0000
+++ doc/ref/schemas/options.rst	2011-06-13 18:45:53 +0000
@@ -139,14 +139,14 @@
     If ``True``, duplicate elements will be removed from the parsed
     value.
 
-``StringConfigOption``
+``StringOption``
 ----------------------
 
-.. class:: StringConfigOption([null=False, **attributes])
+.. class:: StringOption([null=False, **attributes])
 
 A string.
 
-.. attribute:: StringConfigOption.null
+.. attribute:: StringOption.null
 
     *Optional*.
 

=== modified file 'doc/topics/config-file.rst'
--- doc/topics/config-file.rst	2011-05-22 17:27:39 +0000
+++ doc/topics/config-file.rst	2011-06-13 18:45:53 +0000
@@ -24,7 +24,7 @@
 
     class MySchema(pyschema.Schema):
         class my_section(pyschema.ConfigSection):
-            my_option = pyschema.StringConfigOption()
+            my_option = pyschema.StringOption()
 
 ======================
 Special considerations

=== modified file 'doc/topics/schemas.rst'
--- doc/topics/schemas.rst	2011-05-22 17:27:39 +0000
+++ doc/topics/schemas.rst	2011-06-13 18:45:53 +0000
@@ -25,18 +25,18 @@
     from configglue import pyschema
 
     class DatabaseConnection(pyschema.Schema):
-        host = pyschema.StringConfigOption(
+        host = pyschema.StringOption(
             default='localhost',
             help='Host where the database engine is listening on')
         port = pyschema.IntConfigOption(
             default=5432,
             help='Port where the database engine is listening on')
-        dbname = pyschema.StringConfigOption(
+        dbname = pyschema.StringOption(
             fatal=True,
             help='Name of the database to connect to')
-        user = pyschema.StringConfigOption(
+        user = pyschema.StringOption(
             help='Username to use for the connection')
-        password = pyschema.StringConfigOption(
+        password = pyschema.StringOption(
             help='Password to use fot the connection')
 
 ``host``, ``port``, ``dbname``, ``user`` and ``password`` are options_ of the

=== modified file 'tests/pyschema/test_parser.py'
--- tests/pyschema/test_parser.py	2011-06-13 18:45:53 +0000
+++ tests/pyschema/test_parser.py	2011-06-13 18:45:53 +0000
@@ -48,7 +48,7 @@
     IntConfigOption,
     LinesConfigOption,
     Schema,
-    StringConfigOption,
+    StringOption,
     TupleConfigOption,
 )
 
@@ -56,7 +56,7 @@
 class TestIncludes(unittest.TestCase):
     def setUp(self):
         class MySchema(Schema):
-            foo = StringConfigOption()
+            foo = StringOption()
         self.schema = MySchema()
         fd, self.name = tempfile.mkstemp(suffix='.cfg')
         os.write(fd, '[__main__]\nfoo=bar\n')
@@ -178,7 +178,7 @@
 class TestInterpolation(unittest.TestCase):
     def test_basic_interpolate(self):
         class MySchema(Schema):
-            foo = StringConfigOption()
+            foo = StringOption()
             bar = BoolConfigOption()
         config = StringIO('[__main__]\nbar=%(foo)s\nfoo=True')
         parser = SchemaConfigParser(MySchema())
@@ -188,7 +188,7 @@
 
     def test_interpolate_missing_option(self):
         class MySchema(Schema):
-            foo = StringConfigOption()
+            foo = StringOption()
             bar = BoolConfigOption()
 
         section = '__main__'
@@ -201,7 +201,7 @@
 
     def test_interpolate_too_deep(self):
         class MySchema(Schema):
-            foo = StringConfigOption()
+            foo = StringOption()
             bar = BoolConfigOption()
 
         section = '__main__'
@@ -214,7 +214,7 @@
 
     def test_interpolate_incomplete_format(self):
         class MySchema(Schema):
-            foo = StringConfigOption()
+            foo = StringOption()
             bar = BoolConfigOption()
 
         section = '__main__'
@@ -255,7 +255,7 @@
 
     def test_get_interpolation_keys_string(self):
         class MySchema(Schema):
-            foo = StringConfigOption()
+            foo = StringOption()
         config = StringIO("[__main__]\nfoo=%(bar)s")
         expected = ('%(bar)s', set(['bar']))
 
@@ -299,7 +299,7 @@
 
     def test_get_interpolation_keys_lines(self):
         class MySchema(Schema):
-            foo = LinesConfigOption(item=StringConfigOption())
+            foo = LinesConfigOption(item=StringOption())
         config = StringIO("[__main__]\nfoo=%(bar)s\n    %(baz)s")
         expected = ('%(bar)s\n%(baz)s', set(['bar', 'baz']))
 
@@ -379,7 +379,7 @@
 
     def test_get_with_raw_value(self):
         class MySchema(Schema):
-            foo = StringConfigOption(raw=True)
+            foo = StringOption(raw=True)
         config = StringIO('[__main__]\nfoo=blah%(asd)##$@@dddf2kjhkjs')
         expected_value = 'blah%(asd)##$@@dddf2kjhkjs'
 
@@ -410,7 +410,7 @@
 class TestSchemaConfigParser(unittest.TestCase):
     def setUp(self):
         class MySchema(Schema):
-            foo = StringConfigOption()
+            foo = StringOption()
         self.schema = MySchema()
         self.parser = SchemaConfigParser(self.schema)
         self.config = StringIO("[__main__]\nfoo = bar")
@@ -451,10 +451,10 @@
 
     def test_items_interpolate(self):
         class MySchema(Schema):
-            foo = StringConfigOption()
+            foo = StringOption()
 
             class baz(ConfigSection):
-                bar = StringConfigOption()
+                bar = StringOption()
 
         parser = SchemaConfigParser(MySchema())
         config = StringIO('[__main__]\nfoo=%(bar)s\n[baz]\nbar=42')
@@ -519,7 +519,7 @@
     def test_parse_option(self):
         class MyOtherSchema(Schema):
             class foo(ConfigSection):
-                bar = StringConfigOption()
+                bar = StringOption()
 
         expected_value = 'baz'
         config = StringIO("[foo]\nbar = baz")
@@ -538,7 +538,7 @@
 
             class bar(ConfigSection):
                 baz = IntConfigOption()
-                bla = StringConfigOption(default='hello')
+                bla = StringOption(default='hello')
 
         schema = MySchema()
         config = StringIO("[bar]\nbaz=123")
@@ -764,7 +764,7 @@
 
     def test_write(self):
         class MySchema(Schema):
-            foo = StringConfigOption()
+            foo = StringOption()
 
             class DEFAULTSECT(ConfigSection):
                 pass
@@ -827,8 +827,8 @@
             return files, folder
 
         class MySchema(Schema):
-            foo = StringConfigOption()
-            bar = StringConfigOption()
+            foo = StringOption()
+            bar = StringOption()
 
         self.parser = SchemaConfigParser(MySchema())
 
@@ -856,7 +856,7 @@
 class TestParserIsValid(unittest.TestCase):
     def setUp(self):
         class MySchema(Schema):
-            foo = StringConfigOption()
+            foo = StringOption()
         self.schema = MySchema()
         self.parser = SchemaConfigParser(self.schema)
         self.config = StringIO("[__main__]\nfoo = bar")

=== modified file 'tests/pyschema/test_schema.py'
--- tests/pyschema/test_schema.py	2011-06-13 18:45:53 +0000
+++ tests/pyschema/test_schema.py	2011-06-13 18:45:53 +0000
@@ -29,6 +29,7 @@
     LinesConfigOption,
     Schema,
     StringConfigOption,
+    StringOption,
     TupleConfigOption,
     get_config_objects,
 )
@@ -151,7 +152,7 @@
     def test_equal(self):
         opt1 = IntConfigOption(name='opt1')
         opt2 = IntConfigOption(name='opt2')
-        opt3 = StringConfigOption(name='opt1')
+        opt3 = StringOption(name='opt1')
         self.assertEqual(opt1, opt1)
         self.assertNotEqual(opt1, opt2)
         self.assertNotEqual(opt1, opt3)
@@ -253,15 +254,17 @@
         self.assertEqual(foo_option_names, set(['bar']))
 
 
-class TestStringConfigOption(unittest.TestCase):
+class TestStringOption(unittest.TestCase):
+    cls = StringOption
+
     def setUp(self):
-        self.opt = StringConfigOption()
+        self.opt = self.cls()
 
     def test_init_no_args(self):
         self.assertFalse(self.opt.null)
 
     def test_init_null(self):
-        opt = StringConfigOption(null=True)
+        opt = self.cls(null=True)
         self.assertTrue(opt.null)
 
     def test_parse_ascii_string(self):
@@ -273,7 +276,7 @@
         self.assertEqual(value, '')
 
     def test_parse_null_string(self):
-        opt = StringConfigOption(null=True)
+        opt = self.cls(null=True)
         value = opt.parse(None)
         self.assertEqual(value, None)
 
@@ -282,8 +285,7 @@
         self.assertEqual(value, 'None')
 
     def test_parse_nonascii_string(self):
-        foo = StringConfigOption()
-        value = foo.parse('foóbâr')
+        value = self.opt.parse('foóbâr')
         self.assertEqual(value, 'foóbâr')
 
     def test_parse_int(self):
@@ -295,20 +297,21 @@
         self.assertEqual(value, 'False')
 
     def test_default(self):
-        opt = StringConfigOption()
-        self.assertEqual(opt.default, '')
+        self.assertEqual(self.opt.default, '')
 
     def test_default_null(self):
-        opt = StringConfigOption(null=True)
+        opt = self.cls(null=True)
         self.assertEqual(opt.default, None)
 
     def test_validate_string(self):
-        opt = StringConfigOption()
-        self.assertEqual(opt.validate(''), True)
+        self.assertEqual(self.opt.validate(''), True)
 
     def test_validate_nonstring(self):
-        opt = StringConfigOption()
-        self.assertEqual(opt.validate(0), False)
+        self.assertEqual(self.opt.validate(0), False)
+
+
+class TestStringConfigOption(TestStringOption):
+    cls = StringConfigOption
 
 
 class TestIntConfigOption(unittest.TestCase):
@@ -441,7 +444,7 @@
 
     def test_remove_duplicates(self):
         class MySchema(Schema):
-            foo = LinesConfigOption(item=StringConfigOption(),
+            foo = LinesConfigOption(item=StringOption(),
                                     remove_duplicates=True)
 
         schema = MySchema()
@@ -564,7 +567,7 @@
     def test_parse_dict(self):
         class MySchema(Schema):
             foo = DictConfigOption(spec={
-                'bar': StringConfigOption(),
+                'bar': StringOption(),
                 'baz': IntConfigOption(),
                 'bla': BoolConfigOption(),
             })
@@ -588,7 +591,7 @@
     def test_parse_raw(self):
         class MySchema(Schema):
             foo = DictConfigOption(spec={
-                'bar': StringConfigOption(),
+                'bar': StringOption(),
                 'baz': IntConfigOption(),
                 'bla': BoolConfigOption(),
             })
@@ -716,7 +719,7 @@
         class MySchema(Schema):
             foo = LinesConfigOption(item=DictConfigOption(
                 spec={
-                    'bar': StringConfigOption(),
+                    'bar': StringOption(),
                     'baz': IntConfigOption(),
                     'bla': BoolConfigOption(),
                 }))
@@ -746,11 +749,11 @@
 
 class TestDictWithDicts(unittest.TestCase):
     def test_parse_dict_with_dicts(self):
-        innerspec = {'bar': StringConfigOption(),
+        innerspec = {'bar': StringOption(),
                      'baz': IntConfigOption(),
                      'bla': BoolConfigOption(),
                     }
-        spec = {'name': StringConfigOption(),
+        spec = {'name': StringOption(),
                 'size': IntConfigOption(),
                 'options': DictConfigOption(spec=innerspec)}
 

=== modified file 'tests/pyschema/test_schemaconfig.py'
--- tests/pyschema/test_schemaconfig.py	2011-06-13 18:45:53 +0000
+++ tests/pyschema/test_schemaconfig.py	2011-06-13 18:45:53 +0000
@@ -32,7 +32,7 @@
     ConfigSection,
     IntConfigOption,
     Schema,
-    StringConfigOption,
+    StringOption,
 )
 
 
@@ -193,7 +193,7 @@
 
     def test_parser_set_with_encoding(self):
         class MySchema(Schema):
-            foo = StringConfigOption()
+            foo = StringOption()
 
         parser = SchemaConfigParser(MySchema())
         op, options, args = schemaconfigglue(


Follow ups