diff --git a/readthedocs/doc_builder/backends/sphinx.py b/readthedocs/doc_builder/backends/sphinx.py index 8a4323fc3ae..d73010ec495 100644 --- a/readthedocs/doc_builder/backends/sphinx.py +++ b/readthedocs/doc_builder/backends/sphinx.py @@ -139,6 +139,9 @@ def get_config_params(self): '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 + ), } finalize_sphinx_context_data.send( diff --git a/readthedocs/doc_builder/templates/doc_builder/conf.py.tmpl b/readthedocs/doc_builder/templates/doc_builder/conf.py.tmpl index d6eb89ecaa8..1eff1d4a69a 100644 --- a/readthedocs/doc_builder/templates/doc_builder/conf.py.tmpl +++ b/readthedocs/doc_builder/templates/doc_builder/conf.py.tmpl @@ -128,7 +128,13 @@ context = { {% block extra_context %}{% endblock %} if 'html_context' in globals(): + {% if dont_overwrite_sphinx_context %} + for key in context: + if key not in html_context: + html_context[key] = context[key] + {% else %} html_context.update(context) + {% endif %} else: html_context = context diff --git a/readthedocs/projects/models.py b/readthedocs/projects/models.py index 61155948021..1d278b1f8ba 100644 --- a/readthedocs/projects/models.py +++ b/readthedocs/projects/models.py @@ -1021,6 +1021,7 @@ def add_features(sender, **kwargs): 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' FEATURES = ( (USE_SPHINX_LATEST, _('Use latest version of Sphinx')), @@ -1030,6 +1031,8 @@ def add_features(sender, **kwargs): (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',)), ) projects = models.ManyToManyField(