Skip to content

Commit

Permalink
Merge pull request #4554 from rtfd/humitos/search/remove-builder-json…
Browse files Browse the repository at this point in the history
…-feature

Build JSON artifacts in HTML builder
  • Loading branch information
humitos authored Aug 22, 2018
2 parents 883b383 + d914cf8 commit cab4363
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 94 deletions.
47 changes: 18 additions & 29 deletions readthedocs/doc_builder/backends/sphinx.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,6 @@ def get_config_params(self):
'display_gitlab': display_gitlab,

# Features
'generate_json_artifacts': self.project.has_feature(
Feature.BUILD_JSON_ARTIFACTS_WITH_HTML
),
'dont_overwrite_sphinx_context': self.project.has_feature(
Feature.DONT_OVERWRITE_SPHINX_CONTEXT
),
Expand Down Expand Up @@ -228,27 +225,26 @@ def __init__(self, *args, **kwargs):

def move(self, **__):
super(HtmlBuilder, self).move()
if self.project.has_feature(Feature.BUILD_JSON_ARTIFACTS_WITH_HTML):
# 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')
# 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
)
json_path_target = self.project.artifact_path(
version=self.version.slug, type_='sphinx_search'
else:
log.warning(
'Not moving json because the build dir is unknown.'
)
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):
Expand All @@ -267,13 +263,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
3 changes: 0 additions & 3 deletions readthedocs/doc_builder/templates/doc_builder/conf.py.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,3 @@ if 'extensions' in globals():
extensions.insert(0, "readthedocs_ext.readthedocs")
else:
extensions = ["readthedocs_ext.readthedocs"]

# Build the json artifacts with the html build step
rtd_generate_json_artifacts = {{ generate_json_artifacts }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.13 on 2018-08-22 09:19
from __future__ import unicode_literals

from django.db import migrations


FEATURE_ID = 'build_json_artifacts_with_html'


def forward_add_feature(apps, schema_editor):
Feature = apps.get_model('projects', 'Feature')
try:
Feature.objects.get(feature_id=FEATURE_ID).delete()
except Feature.DoesNotExist:
pass


def reverse_add_feature(apps, schema_editor):
Feature = apps.get_model('projects', 'Feature')
Feature.objects.create(feature_id=FEATURE_ID)


class Migration(migrations.Migration):

dependencies = [
('projects', '0026_ad-free-option'),
]

operations = [
migrations.RunPython(forward_add_feature, reverse_add_feature),
]
3 changes: 0 additions & 3 deletions readthedocs/projects/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,6 @@ def add_features(sender, **kwargs):
ALLOW_DEPRECATED_WEBHOOKS = 'allow_deprecated_webhooks'
PIP_ALWAYS_UPGRADE = 'pip_always_upgrade'
SKIP_SUBMODULES = 'skip_submodules'
BUILD_JSON_ARTIFACTS_WITH_HTML = 'build_json_artifacts_with_html'
DONT_OVERWRITE_SPHINX_CONTEXT = 'dont_overwrite_sphinx_context'
ALLOW_V2_CONFIG_FILE = 'allow_v2_config_file'

Expand All @@ -1050,8 +1049,6 @@ def add_features(sender, **kwargs):
(ALLOW_DEPRECATED_WEBHOOKS, _('Allow deprecated webhook views')),
(PIP_ALWAYS_UPGRADE, _('Always run pip install --upgrade')),
(SKIP_SUBMODULES, _('Skip git submodule checkout')),
(BUILD_JSON_ARTIFACTS_WITH_HTML, _(
'Build the json artifacts with the html build step')),
(DONT_OVERWRITE_SPHINX_CONTEXT, _(
'Do not overwrite context vars in conf.py with Read the Docs context',)),
(ALLOW_V2_CONFIG_FILE, _(
Expand Down
18 changes: 0 additions & 18 deletions readthedocs/projects/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,6 @@ 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['localmedia'] = self.build_docs_localmedia()
outcomes['pdf'] = self.build_docs_pdf()
outcomes['epub'] = self.build_docs_epub()
Expand Down Expand Up @@ -714,23 +713,6 @@ def build_docs_html(self):

return success

def build_docs_search(self):
"""
Build search data with separate build.
Unless the project has the feature to allow building the JSON search
artifacts in the html build step.
"""
build_json_in_html_builder = self.project.has_feature(
Feature.BUILD_JSON_ARTIFACTS_WITH_HTML,
)
if self.build_search and build_json_in_html_builder:
# Already built in the html step
return True
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
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 @@ -16,7 +16,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 @@ -77,45 +77,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))


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

Expand Down

0 comments on commit cab4363

Please sign in to comment.