Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move search artifacts in html step #4213

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions readthedocs/doc_builder/backends/sphinx.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import sys
import zipfile
from glob import glob
import shutil

import six
from django.conf import settings
Expand Down Expand Up @@ -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'
Expand All @@ -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'
Expand Down
1 change: 0 additions & 1 deletion readthedocs/doc_builder/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
28 changes: 15 additions & 13 deletions readthedocs/projects/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -774,23 +768,31 @@ 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(
version=version.slug, type_=version.project.documentation_type)
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')
Expand Down
41 changes: 1 addition & 40 deletions readthedocs/rtd_tests/tests/test_doc_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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):
Expand Down