Rev 2606: Clean up old/unused global options in http://sourcefrog.net/bzr/check-options

Martin Pool mbp at sourcefrog.net
Wed Jul 11 05:15:49 BST 2007


At http://sourcefrog.net/bzr/check-options

------------------------------------------------------------
revno: 2606
revision-id: mbp at sourcefrog.net-20070711041548-n1om2ptyj2j01r6l
parent: mbp at sourcefrog.net-20070711034822-w0c7cnxnuo7naay5
committer: Martin Pool <mbp at sourcefrog.net>
branch nick: check-options
timestamp: Wed 2007-07-11 14:15:48 +1000
message:
  Clean up old/unused global options
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/commands.py             bzr.py-20050309040720-d10f4714595cf8c3
  bzrlib/option.py               option.py-20051014052914-661fb36e76e7362f
  bzrlib/tests/test_options.py   testoptions.py-20051014093702-96457cfc86319a8f
=== modified file 'NEWS'
--- a/NEWS	2007-07-10 01:37:27 +0000
+++ b/NEWS	2007-07-11 04:15:48 +0000
@@ -10,7 +10,11 @@
 
   LIBRARY API BREAKS:
 
-    * None yet ...
+    * Deprecated dictionary ``bzrlib.option.SHORT_OPTIONS`` removed.
+      Various globally-declared options removed.  Options are now required
+      to provide a help string and it must comply with the style guide
+      by being one or more sentences with an initial capital and final
+      period.  (Martin Pool)
 
   INTERNALS:
 

=== modified file 'bzrlib/commands.py'
--- a/bzrlib/commands.py	2007-07-04 01:39:50 +0000
+++ b/bzrlib/commands.py	2007-07-11 04:15:48 +0000
@@ -332,7 +332,7 @@
 
         Maps from long option name to option object."""
         r = dict()
-        r['help'] = option.Option.OPTIONS['help']
+        r['help'] = option._help_option
         for o in self.takes_options:
             if isinstance(o, basestring):
                 o = option.Option.OPTIONS[o]

=== modified file 'bzrlib/option.py'
--- a/bzrlib/option.py	2007-07-11 03:48:22 +0000
+++ b/bzrlib/option.py	2007-07-11 04:15:48 +0000
@@ -152,13 +152,6 @@
     def short_name(self):
         if self._short_name:
             return self._short_name
-        else:
-            # remove this when SHORT_OPTIONS is removed
-            # XXX: This is accessing a DeprecatedDict, so we call the super 
-            # method to avoid warnings
-            for (k, v) in dict.iteritems(Option.SHORT_OPTIONS):
-                if v == self:
-                    return k
 
     def set_short_name(self, short_name):
         self._short_name = short_name
@@ -374,24 +367,14 @@
 _merge_type_registry.register_lazy('weave', 'bzrlib.merge', 'WeaveMerger',
                                    "Weave-based merge")
 
-_global_option('all')
 _global_option('overwrite', help='Ignore differences between branches and '
                'overwrite unconditionally.')
-_global_option('basis', type=str)
-_global_option('bound')
 _global_option('diff-options', type=str)
-_global_option('help',
-               help='Show help message.',
-               short_name='h')
-_global_option('file', type=unicode, short_name='F')
 _global_option('force')
 _global_option('format', type=unicode)
-_global_option('forward')
 _global_option('message', type=unicode,
                short_name='m')
 _global_option('no-recurse')
-_global_option('profile',
-               help='Show performance profiling information.')
 _global_option('revision',
                type=_parse_revision_str,
                short_name='r',
@@ -401,28 +384,16 @@
 _global_option('timezone',
                type=str,
                help='Display timezone as local, original, or utc.')
-_global_option('unbound')
 _global_option('verbose',
                help='Display more information.',
                short_name='v')
-_global_option('version')
-_global_option('email')
-_global_option('update')
 _global_registry_option('log-format', "Use specified log format.",
                         log.log_formatter_registry, value_switches=True,
                         title='Log format')
-_global_option('long',
-        help='Use detailed log format.  Same as --log-format long.',
-        short_name='l')
-_global_option('short',
-        help='Use moderately short log format. Same as --log-format short.')
-_global_option('line', help='Use log format with one line per revision. Same as --log-format line.')
 _global_option('root', type=str)
 _global_registry_option('merge-type', 'Select a particular merge algorithm.',
                         _merge_type_registry, value_switches=True,
                         title='Merge algorithm')
-_global_option('pattern', type=str)
-_global_option('quiet', short_name='q')
 _global_option('remember', help='Remember the specified location as a'
                ' default.')
 _global_option('reprocess', help='Reprocess to reduce spurious conflicts.')
@@ -431,20 +402,6 @@
                help="Show what would be done, but don't actually do anything.")
 _global_option('name-from-revision', help='The path name in the old tree.')
 
-
-# prior to 0.14 these were always globally registered; the old dict is
-# available for plugins that use it but it should not be used.
-Option.SHORT_OPTIONS = symbol_versioning.DeprecatedDict(
-    symbol_versioning.zero_fourteen,
-    'SHORT_OPTIONS',
-    {
-        'F': Option.OPTIONS['file'],
-        'h': Option.OPTIONS['help'],
-        'm': Option.OPTIONS['message'],
-        'r': Option.OPTIONS['revision'],
-        'v': Option.OPTIONS['verbose'],
-        'l': Option.OPTIONS['long'],
-        'q': Option.OPTIONS['quiet'],
-    },
-    'Set the short option name when constructing the Option.',
-    )
+_help_option = Option('help',
+                      help='Show help message.',
+                      short_name='h')

=== modified file 'bzrlib/tests/test_options.py'
--- a/bzrlib/tests/test_options.py	2007-07-11 03:48:22 +0000
+++ b/bzrlib/tests/test_options.py	2007-07-11 04:15:48 +0000
@@ -74,45 +74,11 @@
         out, err = self.run_bzr('help -r', retcode=3)
         self.assertContainsRe(err, r'no such option')
 
-    def test_get_short_name(self):
-        file_opt = option.Option.OPTIONS['file']
-        self.assertEquals(file_opt.short_name(), 'F')
-        force_opt = option.Option.OPTIONS['force']
-        self.assertEquals(force_opt.short_name(), None)
-
     def test_set_short_name(self):
         o = option.Option('wiggle')
         o.set_short_name('w')
         self.assertEqual(o.short_name(), 'w')
 
-    def test_old_short_names(self):
-        # test the deprecated method for getting and setting short option
-        # names
-        expected_warning = (
-            "access to SHORT_OPTIONS was deprecated in version 0.14."
-            " Set the short option name when constructing the Option.",
-            DeprecationWarning, 2)
-        _warnings = []
-        def capture_warning(message, category, stacklevel=None):
-            _warnings.append((message, category, stacklevel))
-        old_warning_method = symbol_versioning.warn
-        try:
-            # an example of the kind of thing plugins might want to do through
-            # the old interface - make a new option and then give it a short
-            # name.
-            symbol_versioning.set_warning_method(capture_warning)
-            example_opt = option.Option('example', help='example option')
-            option.Option.SHORT_OPTIONS['w'] = example_opt
-            self.assertEqual(example_opt.short_name(), 'w')
-            self.assertEqual([expected_warning], _warnings)
-            # now check that it can actually be parsed with the registered
-            # value
-            opts, args = parse([example_opt], ['-w', 'foo'])
-            self.assertEqual(opts.example, True)
-            self.assertEqual(args, ['foo'])
-        finally:
-            symbol_versioning.set_warning_method(old_warning_method)
-
     def test_allow_dash(self):
         """Test that we can pass a plain '-' as an argument."""
         self.assertEqual(




More information about the bazaar-commits mailing list