diff options
author | Stephen Finucane <sfinucan@redhat.com> | 2018-03-28 13:12:33 +0100 |
---|---|---|
committer | Stephen Finucane <sfinucan@redhat.com> | 2018-04-16 17:07:45 +0100 |
commit | 0e70c4c0d877b07c7e037c3f817591b66baf8ff1 (patch) | |
tree | 3f459c33dbdc78e2c7166d8b9bb5b303a57cde84 | |
parent | 84655714b656c8296bfd70aeb5daf5996e1f5add (diff) | |
download | oslo-config-0e70c4c0d877b07c7e037c3f817591b66baf8ff1.tar.gz |
sphinxext: Use 'sphinx.util.logging'
This resolves a deprecation warning. It also allows us to stop passing
around the 'app' variable just to enable logging.
Change-Id: I7b7e29ae6dec086373bbaeb2ebaae5ed7e9628b1
-rw-r--r-- | oslo_config/sphinxext.py | 26 | ||||
-rw-r--r-- | oslo_config/tests/test_sphinxext.py | 27 |
2 files changed, 10 insertions, 43 deletions
diff --git a/oslo_config/sphinxext.py b/oslo_config/sphinxext.py index 4351793..6c9efc7 100644 --- a/oslo_config/sphinxext.py +++ b/oslo_config/sphinxext.py @@ -13,8 +13,9 @@ from docutils import nodes from docutils.parsers import rst from docutils.parsers.rst import directives - from docutils.statemachine import ViewList +import oslo_i18n +import six from sphinx import addnodes from sphinx.directives import ObjectDescription from sphinx.domains import Domain @@ -26,9 +27,8 @@ from sphinx.util.nodes import nested_parse_with_titles from oslo_config import cfg from oslo_config import generator -import oslo_i18n -import six +LOG = logging.getLogger(__name__) def _list_table(headers, data, title='', columns=None): @@ -205,9 +205,9 @@ def _format_group(namespace, group_name, group_obj): yield '' -def _format_group_opts(app, namespace, group_name, group_obj, opt_list): +def _format_group_opts(namespace, group_name, group_obj, opt_list): group_name = group_name or 'DEFAULT' - app.debug('[oslo.config] %s %s' % (namespace, group_name)) + LOG.debug('%s %s', namespace, group_name) for line in _format_group(namespace, group_name, group_obj): yield line @@ -217,7 +217,7 @@ def _format_group_opts(app, namespace, group_name, group_obj, opt_list): yield line -def _format_option_help(app, namespaces, split_namespaces): +def _format_option_help(namespaces, split_namespaces): """Generate a series of lines of restructuredtext. Format the option help as restructuredtext and return it as a list @@ -236,7 +236,6 @@ def _format_option_help(app, namespaces, split_namespaces): if group_name is None: group_name = 'DEFAULT' lines = _format_group_opts( - app=app, namespace=namespace, group_name=group_name, group_obj=group, @@ -263,7 +262,6 @@ def _format_option_help(app, namespaces, split_namespaces): by_section.setdefault(group_name, []).extend(group_opts) for group_name, group_opts in sorted(by_section.items()): lines = _format_group_opts( - app=app, namespace=None, group_name=group_name, group_obj=group_objs.get(group_name), @@ -283,14 +281,11 @@ class ShowOptionsDirective(rst.Directive): has_content = True def run(self): - env = self.state.document.settings.env - app = env.app - split_namespaces = 'split-namespaces' in self.options config_file = self.options.get('config-file') if config_file: - app.info('loading config file %s' % config_file) + LOG.info('loading config file %s', config_file) conf = cfg.ConfigOpts() conf.register_opts(generator._generator_opts) conf( @@ -307,7 +302,7 @@ class ShowOptionsDirective(rst.Directive): result = ViewList() source_name = '<' + __name__ + '>' - for line in _format_option_help(app, namespaces, split_namespaces): + for line in _format_option_help(namespaces, split_namespaces): result.append(line, source_name) node = nodes.section() @@ -368,7 +363,6 @@ class ConfigGroup(rst.Directive): def run(self): env = self.state.document.settings.env - app = env.app group_name = self.arguments[0] namespace = self.options.get('namespace') @@ -377,7 +371,7 @@ class ConfigGroup(rst.Directive): # Store the current group for use later in option directives env.temp_data['oslo.config:group'] = group_name - app.debug('oslo.config group %s' % group_name) + LOG.debug('oslo.config group %s' % group_name) # Store the location where this group is being defined # for use when resolving cross-references later. @@ -422,7 +416,7 @@ class ConfigOption(ObjectDescription): def handle_signature(self, sig, signode): """Transform an option description into RST nodes.""" optname = sig - self.env.app.debug('oslo.config option %s' % optname) + LOG.debug('oslo.config option %s', optname) # Insert a node into the output showing the option name signode += addnodes.desc_name(optname, optname) signode['allnames'] = [optname] diff --git a/oslo_config/tests/test_sphinxext.py b/oslo_config/tests/test_sphinxext.py index 5a89e8a..b35af71 100644 --- a/oslo_config/tests/test_sphinxext.py +++ b/oslo_config/tests/test_sphinxext.py @@ -24,7 +24,6 @@ class FormatGroupTest(base.BaseTestCase): def test_none_in_default(self): # option with None group placed in DEFAULT results = '\n'.join(list(sphinxext._format_group_opts( - app=mock.Mock(), namespace=None, group_name=None, group_obj=None, @@ -46,7 +45,6 @@ class FormatGroupTest(base.BaseTestCase): def test_with_default_value(self): results = '\n'.join(list(sphinxext._format_group_opts( - app=mock.Mock(), namespace=None, group_name=None, group_obj=None, @@ -69,7 +67,6 @@ class FormatGroupTest(base.BaseTestCase): def test_with_min(self): results = '\n'.join(list(sphinxext._format_group_opts( - app=mock.Mock(), namespace=None, group_name=None, group_obj=None, @@ -90,7 +87,6 @@ class FormatGroupTest(base.BaseTestCase): def test_with_min_0(self): results = '\n'.join(list(sphinxext._format_group_opts( - app=mock.Mock(), namespace=None, group_name=None, group_obj=None, @@ -111,7 +107,6 @@ class FormatGroupTest(base.BaseTestCase): def test_with_max(self): results = '\n'.join(list(sphinxext._format_group_opts( - app=mock.Mock(), namespace=None, group_name=None, group_obj=None, @@ -132,7 +127,6 @@ class FormatGroupTest(base.BaseTestCase): def test_with_max_0(self): results = '\n'.join(list(sphinxext._format_group_opts( - app=mock.Mock(), namespace=None, group_name=None, group_obj=None, @@ -153,7 +147,6 @@ class FormatGroupTest(base.BaseTestCase): def test_with_choices(self): results = '\n'.join(list(sphinxext._format_group_opts( - app=mock.Mock(), namespace=None, group_name=None, group_obj=None, @@ -174,7 +167,6 @@ class FormatGroupTest(base.BaseTestCase): def test_with_choices_with_descriptions(self): results = '\n'.join(list(sphinxext._format_group_opts( - app=mock.Mock(), namespace=None, group_name=None, group_obj=None, @@ -219,7 +211,6 @@ class FormatGroupTest(base.BaseTestCase): def test_group_obj_without_help(self): # option with None group placed in DEFAULT results = '\n'.join(list(sphinxext._format_group_opts( - app=mock.Mock(), namespace=None, group_name='group', group_obj=cfg.OptGroup('group'), @@ -237,7 +228,6 @@ class FormatGroupTest(base.BaseTestCase): def test_group_obj_with_help(self): # option with None group placed in DEFAULT results = '\n'.join(list(sphinxext._format_group_opts( - app=mock.Mock(), namespace=None, group_name='group', group_obj=cfg.OptGroup('group', help='group help'), @@ -256,7 +246,6 @@ class FormatGroupTest(base.BaseTestCase): def test_deprecated_opts_without_deprecated_group(self): results = '\n'.join(list(sphinxext._format_group_opts( - app=mock.Mock(), namespace=None, group_name=None, group_obj=None, @@ -285,7 +274,6 @@ class FormatGroupTest(base.BaseTestCase): def test_deprecated_opts_with_deprecated_group(self): results = '\n'.join(list(sphinxext._format_group_opts( - app=mock.Mock(), namespace=None, group_name=None, group_obj=None, @@ -315,7 +303,6 @@ class FormatGroupTest(base.BaseTestCase): def test_deprecated_for_removal(self): results = '\n'.join(list(sphinxext._format_group_opts( - app=mock.Mock(), namespace=None, group_name=None, group_obj=None, @@ -333,7 +320,6 @@ class FormatGroupTest(base.BaseTestCase): def test_mutable(self): results = '\n'.join(list(sphinxext._format_group_opts( - app=mock.Mock(), namespace=None, group_name=None, group_obj=None, @@ -354,7 +340,6 @@ class FormatGroupTest(base.BaseTestCase): def test_not_mutable(self): results = '\n'.join(list(sphinxext._format_group_opts( - app=mock.Mock(), namespace=None, group_name=None, group_obj=None, @@ -374,7 +359,6 @@ class FormatGroupTest(base.BaseTestCase): def test_advanced(self): results = '\n'.join(list(sphinxext._format_group_opts( - app=mock.Mock(), namespace=None, group_name=None, group_obj=None, @@ -397,7 +381,6 @@ class FormatGroupTest(base.BaseTestCase): def test_not_advanced(self): results = '\n'.join(list(sphinxext._format_group_opts( - app=mock.Mock(), namespace=None, group_name=None, group_obj=None, @@ -426,18 +409,15 @@ class FormatOptionHelpTest(base.BaseTestCase): ('namespace2', [(None, ['opt2'])]), ] list(sphinxext._format_option_help( - app=None, namespaces=['namespace1', 'namespace2'], split_namespaces=True)) _format_group_opts.assert_any_call( - app=None, namespace='namespace1', group_name='DEFAULT', group_obj=None, opt_list=['opt1'], ) _format_group_opts.assert_any_call( - app=None, namespace='namespace2', group_name='DEFAULT', group_obj=None, @@ -452,11 +432,9 @@ class FormatOptionHelpTest(base.BaseTestCase): ('namespace2', [(None, ['opt2'])]), ] list(sphinxext._format_option_help( - app=None, namespaces=['namespace1', 'namespace2'], split_namespaces=False)) _format_group_opts.assert_called_once_with( - app=None, namespace=None, group_name='DEFAULT', group_obj=None, @@ -473,11 +451,9 @@ class FormatOptionHelpTest(base.BaseTestCase): ('namespace2', [('grp1', ['opt2'])]), ] list(sphinxext._format_option_help( - app=None, namespaces=['namespace1', 'namespace2'], split_namespaces=False)) _format_group_opts.assert_any_call( - app=None, namespace=None, group_name='grp1', group_obj=grp_obj, @@ -494,19 +470,16 @@ class FormatOptionHelpTest(base.BaseTestCase): ('namespace2', [('grp1', ['opt2'])]), ] list(sphinxext._format_option_help( - app=None, namespaces=['namespace1', 'namespace2'], split_namespaces=True)) print(_format_group_opts.call_args_list) _format_group_opts.assert_any_call( - app=None, namespace='namespace1', group_name='grp1', group_obj=grp_obj, opt_list=['opt1'], ) _format_group_opts.assert_any_call( - app=None, namespace='namespace2', group_name='grp1', group_obj=None, |