Repository: readthedocs/readthedocs.org
Issue: Don't include searchbox in singlehtml builds

Search isn't supported in this kind of builders (search.html isn't included).

Building locally doesn't show the search box, but on rtd it's shown, because our builder is named `readthedocssinglehtml`

Themes check only for https://github.com/rtfd/sphinx_rtd_theme/blob/8c31a26a79702a0ffbb2ee153d4bb054d58087ac/sphinx_rtd_theme/searchbox.html#L1-L1

Should we patch the theme? (problem will still present in other themes) or should we change the way we call our builder or override the builders

Changed files:
readthedocs/projects/models.py, readthedocs/rtd_tests/tests/test_doc_builder.py, readthedocs/doc_builder/backends/sphinx.py

diff --git a/readthedocs/doc_builder/backends/sphinx.py b/readthedocs/doc_builder/backends/sphinx.py
index 20d43a076..4f49e5dd8 100644
--- a/readthedocs/doc_builder/backends/sphinx.py
+++ b/readthedocs/doc_builder/backends/sphinx.py
@@ -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()
@@ -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):
@@ -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):
diff --git a/readthedocs/projects/models.py b/readthedocs/projects/models.py
index ed5c1163b..282a0af3f 100644
--- a/readthedocs/projects/models.py
+++ b/readthedocs/projects/models.py
@@ -1594,6 +1594,7 @@ class Feature(models.Model):
     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')),
@@ -1691,6 +1692,10 @@ class Feature(models.Model):
             SPHINX_PARALLEL,
             _('Use "-j auto" when calling sphinx-build'),
         ),
+        (
+            USE_SPHINX_BUILDERS,
+            _('Use regular sphinx builders instead of custom RTD builders'),
+        )
     )
 
     projects = models.ManyToManyField(
diff --git a/readthedocs/rtd_tests/tests/test_doc_builder.py b/readthedocs/rtd_tests/tests/test_doc_builder.py
index 05da75898..106a48fb0 100644
--- a/readthedocs/rtd_tests/tests/test_doc_builder.py
+++ b/readthedocs/rtd_tests/tests/test_doc_builder.py
@@ -13,12 +13,14 @@ from unittest.mock import patch
 
 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):
@@ -216,6 +218,61 @@ class SphinxBuilderTest(TestCase):
         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):