Skip to content

Commit

Permalink
Initialize sphinx config using application instead of config
Browse files Browse the repository at this point in the history
Currently sphinx config is initialized using sphinx.config,
however in recent versions of Sphinx, plugin specific parameters
as man_pages for man builder has been moved to the extension
and is not initialized from sphinx.config but using sphinx.application.
This is making man_pages to be empty when using sphinx 1.5 and man
builder is not properly called.

This patch initializes sphinx config using sphinx.application which
works fine with both old and new Sphinx versions.

Closes-Bug: #1674795

Depends-On: I7bde8fc1f2a7db5bd73635aa197377bf5ac614d2
Change-Id: Ib7c1a6fe8fbb5acfcfcfac61d0b53f080ff2b1e4
  • Loading branch information
amoralej committed Mar 27, 2017
1 parent 6448d03 commit 2d7c004
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
17 changes: 4 additions & 13 deletions pbr/builddoc.py
Expand Up @@ -17,9 +17,7 @@
from distutils import log
import fnmatch
import os
import pkg_resources
import sys
import warnings

try:
import cStringIO
Expand All @@ -29,7 +27,6 @@
try:
from sphinx import apidoc
from sphinx import application
from sphinx import config
from sphinx import setup_command
except Exception as e:
# NOTE(dhellmann): During the installation of docutils, setuptools
Expand Down Expand Up @@ -134,16 +131,6 @@ def _sphinx_run(self):
confoverrides['release'] = self.release
if self.today:
confoverrides['today'] = self.today
sphinx_config = config.Config(self.config_dir, 'conf.py', {}, [])
sphinx_ver = pkg_resources.parse_version(
pkg_resources.get_distribution("sphinx").version)
if sphinx_ver > pkg_resources.parse_version('1.2.3'):
sphinx_config.init_values(warnings.warn)
else:
sphinx_config.init_values()
if self.builder == 'man' and len(
getattr(sphinx_config, 'man_pages', '')) == 0:
return
if self.sphinx_initialized:
confoverrides['suppress_warnings'] = [
'app.add_directive', 'app.add_role',
Expand All @@ -153,6 +140,10 @@ def _sphinx_run(self):
self.builder_target_dir, self.doctree_dir,
self.builder, confoverrides, status_stream,
freshenv=self.fresh_env, warningiserror=self.warning_is_error)
sphinx_config = app.config
if self.builder == 'man' and len(
getattr(sphinx_config, 'man_pages', '')) == 0:
return
self.sphinx_initialized = True

try:
Expand Down
6 changes: 5 additions & 1 deletion pbr/tests/test_setup.py
Expand Up @@ -224,6 +224,10 @@ def _fake_run_shell_command(cmd, **kwargs):
self.assertTrue(co_author in authors)


class _SphinxConfig(object):
man_pages = ['foo']


class BaseSphinxTest(base.BaseTestCase):

def setUp(self):
Expand All @@ -234,7 +238,7 @@ def setUp(self):
self.useFixture(fixtures.MonkeyPatch(
"sphinx.application.Sphinx.build", lambda *a, **kw: None))
self.useFixture(fixtures.MonkeyPatch(
"sphinx.config.Config.man_pages", ['foo']))
"sphinx.application.Sphinx.config", _SphinxConfig))
self.useFixture(fixtures.MonkeyPatch(
"sphinx.config.Config.init_values", lambda *a: None))
self.useFixture(fixtures.MonkeyPatch(
Expand Down

0 comments on commit 2d7c004

Please sign in to comment.