diff --git a/readthedocs/doc_builder/backends/sphinx.py b/readthedocs/doc_builder/backends/sphinx.py index 5ed06c8f831..77646d75edf 100644 --- a/readthedocs/doc_builder/backends/sphinx.py +++ b/readthedocs/doc_builder/backends/sphinx.py @@ -13,6 +13,7 @@ import sys import zipfile from glob import glob +import shutil import six from django.conf import settings @@ -211,11 +212,33 @@ def build(self): class HtmlBuilder(BaseSphinx): type = 'sphinx' sphinx_build_dir = '_build/html' + ignore_patterns = ['_json'] def __init__(self, *args, **kwargs): super(HtmlBuilder, self).__init__(*args, **kwargs) self.sphinx_builder = 'readthedocs' + def move(self, **__): + super(HtmlBuilder, self).move() + # Copy json artifacts to its own directory + # to keep compatibility with the older builder. + json_path = os.path.abspath( + os.path.join(self.old_artifact_path, '_json') + ) + json_path_target = self.project.artifact_path( + version=self.version.slug, type_='sphinx_search' + ) + if os.path.exists(json_path): + if os.path.exists(json_path_target): + shutil.rmtree(json_path_target) + log.info('Copying json on the local filesystem') + shutil.copytree( + json_path, + json_path_target + ) + else: + log.warning('Not moving json, because the build dir is unknown.') + class HtmlDirBuilder(HtmlBuilder): type = 'sphinx_htmldir' @@ -233,13 +256,6 @@ def __init__(self, *args, **kwargs): self.sphinx_builder = 'readthedocssinglehtml' -class SearchBuilder(BaseSphinx): - type = 'sphinx_search' - sphinx_builder = 'json' - sphinx_build_dir = '_build/json' - ignore_patterns = ['_static'] - - class LocalMediaBuilder(BaseSphinx): type = 'sphinx_localmedia' sphinx_builder = 'readthedocssinglehtmllocalmedia' diff --git a/readthedocs/doc_builder/loader.py b/readthedocs/doc_builder/loader.py index 067f475c601..0edcaace778 100644 --- a/readthedocs/doc_builder/loader.py +++ b/readthedocs/doc_builder/loader.py @@ -20,7 +20,6 @@ # Other Sphinx Builders 'sphinx_pdf': sphinx.PdfBuilder, 'sphinx_epub': sphinx.EpubBuilder, - 'sphinx_search': sphinx.SearchBuilder, 'sphinx_singlehtmllocalmedia': sphinx.LocalMediaBuilder, # Other markup 'mkdocs': mkdocs.MkdocsHTML, diff --git a/readthedocs/projects/tasks.py b/readthedocs/projects/tasks.py index 8e063b255f7..c6bfc8f0502 100644 --- a/readthedocs/projects/tasks.py +++ b/readthedocs/projects/tasks.py @@ -638,7 +638,7 @@ def build_docs(self): version=self.version, max_lock_age=getattr(settings, 'REPO_LOCK_SECONDS', 30)): outcomes['html'] = self.build_docs_html() - outcomes['search'] = self.build_docs_search() + outcomes['search'] = False outcomes['localmedia'] = self.build_docs_localmedia() outcomes['pdf'] = self.build_docs_pdf() outcomes['epub'] = self.build_docs_epub() @@ -670,12 +670,6 @@ def build_docs_html(self): return success - def build_docs_search(self): - """Build search data with separate build.""" - if self.build_search and self.project.is_type_sphinx: - return self.build_docs_class('sphinx_search') - return False - def build_docs_localmedia(self): """Get local media files with separate build.""" if 'htmlzip' not in self.config.formats: @@ -774,8 +768,13 @@ def move_files(version_pk, hostname, html=False, localmedia=False, search=False, :type epub: bool """ version = Version.objects.get(pk=version_pk) - log.debug(LOG_TEMPLATE.format(project=version.project.slug, version=version.slug, - msg='Moving files')) + log.debug( + LOG_TEMPLATE.format( + project=version.project.slug, + version=version.slug, + msg='Moving files' + ) + ) if html: from_path = version.project.artifact_path( @@ -783,14 +782,17 @@ def move_files(version_pk, hostname, html=False, localmedia=False, search=False, target = version.project.rtd_build_path(version.slug) Syncer.copy(from_path, target, host=hostname) - if 'sphinx' in version.project.documentation_type: - if search: + if 'sphinx' in version.project.documentation_type: + # Sync the generated json artifacts for search from_path = version.project.artifact_path( - version=version.slug, type_='sphinx_search') + version=version.slug, type_='sphinx_search' + ) to_path = version.project.get_production_media_path( - type_='json', version_slug=version.slug, include_file=False) + type_='json', version_slug=version.slug, include_file=False + ) Syncer.copy(from_path, to_path, host=hostname) + if 'sphinx' in version.project.documentation_type: if localmedia: from_path = version.project.artifact_path( version=version.slug, type_='sphinx_localmedia') diff --git a/readthedocs/rtd_tests/tests/test_doc_builder.py b/readthedocs/rtd_tests/tests/test_doc_builder.py index cf3df311f79..fe3829cfdbe 100644 --- a/readthedocs/rtd_tests/tests/test_doc_builder.py +++ b/readthedocs/rtd_tests/tests/test_doc_builder.py @@ -15,7 +15,7 @@ from readthedocs.builds.models import Version from readthedocs.doc_builder.backends.mkdocs import BaseMkdocs, MkdocsHTML -from readthedocs.doc_builder.backends.sphinx import BaseSphinx, SearchBuilder +from readthedocs.doc_builder.backends.sphinx import BaseSphinx from readthedocs.projects.exceptions import ProjectConfigurationError from readthedocs.projects.models import Project @@ -76,45 +76,6 @@ def test_create_conf_py(self, conf_file, get_conf_py_path, _, get_config_params, self.assertEqual(gf.read(), ef.read()) -class SphinxSearchBuilderTest(TestCase): - - fixtures = ['test_data'] - - def setUp(self): - self.project = Project.objects.get(slug='pip') - self.version = self.project.versions.first() - - build_env = namedtuple('project', 'version') - build_env.project = self.project - build_env.version = self.version - - self.searchbuilder = SearchBuilder(build_env=build_env, python_env=None) - - def test_ignore_patterns(self): - src = tempfile.mkdtemp() - src_static = os.path.join(src, '_static/') - src_other = os.path.join(src, 'other/') - os.mkdir(src_static) - os.mkdir(src_other) - - dest = tempfile.mkdtemp() - dest_static = os.path.join(dest, '_static/') - dest_other = os.path.join(dest, 'other/') - - self.searchbuilder.old_artifact_path = src - self.searchbuilder.target = dest - - # There is a _static/ dir in src/ but not in dest/ - self.assertTrue(os.path.exists(src_static)) - self.assertFalse(os.path.exists(dest_static)) - - self.searchbuilder.move() - - # There is a dest/other/ but not a dest/_static - self.assertFalse(os.path.exists(dest_static)) - self.assertTrue(os.path.exists(dest_other)) - - class MkdocsBuilderTest(TestCase): def setUp(self):