Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #7141 from readthedocs/davidfischer/feature-flag-u…
…se-stock-builders

Add feature flag to use the stock Sphinx builders
  • Loading branch information
davidfischer committed Jun 3, 2020
2 parents 61e5944 + c5488eb commit 6b32b39
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 1 deletion.
6 changes: 6 additions & 0 deletions readthedocs/doc_builder/backends/sphinx.py
Expand Up @@ -316,6 +316,8 @@ class HtmlBuilder(BaseSphinx):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.sphinx_builder = 'readthedocs'
if self.project.has_feature(Feature.USE_SPHINX_BUILDERS):
self.sphinx_builder = 'html'

def move(self, **__):
super().move()
Expand Down Expand Up @@ -346,6 +348,8 @@ class HtmlDirBuilder(HtmlBuilder):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.sphinx_builder = 'readthedocsdirhtml'
if self.project.has_feature(Feature.USE_SPHINX_BUILDERS):
self.sphinx_builder = 'dirhtml'


class SingleHtmlBuilder(HtmlBuilder):
Expand All @@ -354,6 +358,8 @@ class SingleHtmlBuilder(HtmlBuilder):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.sphinx_builder = 'readthedocssinglehtml'
if self.project.has_feature(Feature.USE_SPHINX_BUILDERS):
self.sphinx_builder = 'singlehtml'


class LocalMediaBuilder(BaseSphinx):
Expand Down
5 changes: 5 additions & 0 deletions readthedocs/projects/models.py
Expand Up @@ -1594,6 +1594,7 @@ def add_features(sender, **kwargs):
VCS_REMOTE_LISTING = 'vcs_remote_listing'
STORE_PAGEVIEWS = 'store_pageviews'
SPHINX_PARALLEL = 'sphinx_parallel'
USE_SPHINX_BUILDERS = 'use_sphinx_builders'

FEATURES = (
(USE_SPHINX_LATEST, _('Use latest version of Sphinx')),
Expand Down Expand Up @@ -1691,6 +1692,10 @@ def add_features(sender, **kwargs):
SPHINX_PARALLEL,
_('Use "-j auto" when calling sphinx-build'),
),
(
USE_SPHINX_BUILDERS,
_('Use regular sphinx builders instead of custom RTD builders'),
)
)

projects = models.ManyToManyField(
Expand Down
59 changes: 58 additions & 1 deletion readthedocs/rtd_tests/tests/test_doc_builder.py
Expand Up @@ -13,12 +13,14 @@

from readthedocs.builds.models import Version
from readthedocs.doc_builder.backends.mkdocs import MkdocsHTML, yaml_load_safely
from readthedocs.doc_builder.backends.sphinx import BaseSphinx
from readthedocs.doc_builder.backends.sphinx import BaseSphinx, HtmlBuilder, HtmlDirBuilder, SingleHtmlBuilder
from readthedocs.doc_builder.config import load_yaml_config
from readthedocs.doc_builder.exceptions import MkDocsYAMLParseError
from readthedocs.doc_builder.python_environments import Virtualenv
from readthedocs.projects.constants import PRIVATE, PROTECTED, PUBLIC
from readthedocs.projects.exceptions import ProjectConfigurationError
from readthedocs.projects.models import Feature, Project
from readthedocs.rtd_tests.tests.test_config_integration import create_load


class SphinxBuilderTest(TestCase):
Expand Down Expand Up @@ -216,6 +218,61 @@ def test_multiple_conf_py(
with pytest.raises(ProjectConfigurationError):
base_sphinx.append_conf()

@mock.patch('readthedocs.doc_builder.config.load_config')
def test_use_sphinx_builders(self, load_config):
feature = get(
Feature,
feature_id=Feature.USE_SPHINX_BUILDERS,
)

config_data = {'version': 2, 'sphinx': {'configuration': 'docs/conf.py'}}
load_config.side_effect = create_load(config_data)
config = load_yaml_config(self.version)

python_env = Virtualenv(
version=self.version,
build_env=self.build_env,
config=config,
)
builder = HtmlBuilder(
build_env=self.build_env,
python_env=python_env,
)
self.assertEqual(builder.sphinx_builder, 'readthedocs')

builder = HtmlDirBuilder(
build_env=self.build_env,
python_env=python_env,
)
self.assertEqual(builder.sphinx_builder, 'readthedocsdirhtml')

builder = SingleHtmlBuilder(
build_env=self.build_env,
python_env=python_env,
)
self.assertEqual(builder.sphinx_builder, 'readthedocssinglehtml')

# Add the feature to use the regular builders
feature.projects.add(self.project)

builder = HtmlBuilder(
build_env=self.build_env,
python_env=python_env,
)
self.assertEqual(builder.sphinx_builder, 'html')

builder = HtmlDirBuilder(
build_env=self.build_env,
python_env=python_env,
)
self.assertEqual(builder.sphinx_builder, 'dirhtml')

builder = SingleHtmlBuilder(
build_env=self.build_env,
python_env=python_env,
)
self.assertEqual(builder.sphinx_builder, 'singlehtml')


@override_settings(PRODUCTION_DOMAIN='readthedocs.org')
class MkdocsBuilderTest(TestCase):
Expand Down

0 comments on commit 6b32b39

Please sign in to comment.