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
Add feature to build json with html in the same build #4229
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
absolute_import, division, print_function, unicode_literals) | ||
|
||
import codecs | ||
import shutil | ||
import logging | ||
import os | ||
import sys | ||
|
@@ -23,6 +24,7 @@ | |
from readthedocs.projects.exceptions import ProjectConfigurationError | ||
from readthedocs.projects.utils import safe_write | ||
from readthedocs.restapi.client import api | ||
from readthedocs.projects.models import Feature | ||
|
||
from ..base import BaseBuilder, restoring_chdir | ||
from ..constants import PDF_RE, SPHINX_STATIC_DIR, SPHINX_TEMPLATE_DIR | ||
|
@@ -132,6 +134,11 @@ def get_config_params(self): | |
'gitlab_version': remote_version, | ||
'gitlab_version_is_editable': gitlab_version_is_editable, | ||
'display_gitlab': display_gitlab, | ||
|
||
# Features | ||
'generate_json_artifacts': self.project.has_feature( | ||
Feature.BUILD_JSON_ARTIFACTS_WITH_HTML | ||
), | ||
} | ||
|
||
finalize_sphinx_context_data.send( | ||
|
@@ -216,6 +223,30 @@ def __init__(self, *args, **kwargs): | |
super(HtmlBuilder, self).__init__(*args, **kwargs) | ||
self.sphinx_builder = 'readthedocs' | ||
|
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As the original SearchBuilder isn't executed, we need a move the assets to the other location, I'm not sure if here is the best place, but I feel like it belongs here (since the json output now comes from the html build) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems as good a place as any. |
||
# 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' | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1015,13 +1015,16 @@ 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' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if the name is the best |
||
|
||
FEATURES = ( | ||
(USE_SPHINX_LATEST, _('Use latest version of Sphinx')), | ||
(USE_SETUPTOOLS_LATEST, _('Use latest version of setuptools')), | ||
(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')), | ||
) | ||
|
||
projects = models.ManyToManyField( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is injected in the configuration file