Skip to content

Commit

Permalink
Remove disable_sphinx_manipulation feature flag (#11841)
Browse files Browse the repository at this point in the history
This flag is enabled by default on .org and .com, so the other branches
are dead code now.
`append_conf` was renamed to `show_conf` since that's what it only does.
  • Loading branch information
stsewd authored Dec 11, 2024
1 parent 5a4c099 commit 1ebd4e5
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 460 deletions.
12 changes: 2 additions & 10 deletions readthedocs/doc_builder/backends/mkdocs.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,8 @@ def get_yaml_config(self):
mkdocs_path,
)

def append_conf(self):
"""
Call `cat mkdocs.yaml` only.
This behavior has changed. We used to parse the YAML file and append
some configs automatically, but we have been removing that magic from
our builders as much as we can.
This method will eventually removed completely.
"""
def show_conf(self):
"""Show the current ``mkdocs.yaml`` being used."""
# Write the mkdocs.yml to the build logs
self.run(
"cat",
Expand Down
179 changes: 5 additions & 174 deletions readthedocs/doc_builder/backends/sphinx.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,14 @@
from pathlib import Path

import structlog
from django.conf import settings
from django.template import loader as template_loader
from django.urls import reverse
from requests.exceptions import ConnectionError

from readthedocs.builds import utils as version_utils
from readthedocs.builds.models import APIVersion
from readthedocs.core.utils.filesystem import safe_open
from readthedocs.projects.constants import OLD_LANGUAGES_CODE_MAPPING, PUBLIC

from readthedocs.projects.constants import OLD_LANGUAGES_CODE_MAPPING
from readthedocs.projects.exceptions import ProjectConfigurationError, UserFileNotFound
from readthedocs.projects.models import Feature
from readthedocs.projects.templatetags.projects_tags import sort_version_aware

from ..base import BaseBuilder
from ..constants import PDF_RE
from ..environments import BuildCommand, DockerBuildCommand
from ..exceptions import BuildUserError
from ..signals import finalize_sphinx_context_data

log = structlog.get_logger(__name__)

Expand Down Expand Up @@ -115,142 +105,8 @@ def get_language(self, project):
language = project.language
return OLD_LANGUAGES_CODE_MAPPING.get(language, language)

def get_config_params(self):
"""Get configuration parameters to be rendered into the conf file."""
# TODO this should be handled better in the theme
conf_py_path = os.path.join(
os.path.sep,
os.path.dirname(
os.path.relpath(
self.config_file,
self.project_path,
),
),
"",
)
remote_version = self.version.commit_name

github_user, github_repo = version_utils.get_github_username_repo(
url=self.project.repo,
)
github_version_is_editable = self.version.type == "branch"
display_github = github_user is not None

(
bitbucket_user,
bitbucket_repo,
) = version_utils.get_bitbucket_username_repo( # noqa
url=self.project.repo,
)
bitbucket_version_is_editable = self.version.type == "branch"
display_bitbucket = bitbucket_user is not None

gitlab_user, gitlab_repo = version_utils.get_gitlab_username_repo(
url=self.project.repo,
)
gitlab_version_is_editable = self.version.type == "branch"
display_gitlab = gitlab_user is not None

versions = []
downloads = []
subproject_urls = []
try:
active_versions_data = self.api_client.project(
self.project.pk
).active_versions.get()["versions"]
versions = sort_version_aware(
[APIVersion(**version_data) for version_data in active_versions_data]
)
if not self.project.has_feature(Feature.ALL_VERSIONS_IN_HTML_CONTEXT):
versions = [v for v in versions if v.privacy_level == PUBLIC]
downloads = self.api_client.version(self.version.pk).get()["downloads"]
subproject_urls = [
(project["slug"], project["canonical_url"])
for project in self.api_client.project(self.project.pk)
.subprojects()
.get()["subprojects"]
]
except ConnectionError:
log.exception(
"Timeout while fetching versions/downloads/subproject_urls for Sphinx context.",
project_slug=self.project.slug,
version_slug=self.version.slug,
)

build_id = self.build_env.build.get("id")
build_url = None
if build_id:
build_url = reverse(
"builds_detail",
kwargs={
"project_slug": self.project.slug,
"build_pk": build_id,
},
)
protocol = "http" if settings.DEBUG else "https"
build_url = f"{protocol}://{settings.PRODUCTION_DOMAIN}{build_url}"

vcs_url = None
if self.version.is_external:
vcs_url = self.version.vcs_url

commit = self.project.vcs_repo(
version=self.version.slug,
environment=self.build_env,
).commit

data = {
"current_version": self.version.verbose_name,
"project": self.project,
"version": self.version,
"settings": settings,
"conf_py_path": conf_py_path,
"api_host": settings.PUBLIC_API_URL,
"commit": commit,
"versions": versions,
"downloads": downloads,
"subproject_urls": subproject_urls,
"build_url": build_url,
"vcs_url": vcs_url,
"proxied_static_path": self.project.proxied_static_path,
# GitHub
"github_user": github_user,
"github_repo": github_repo,
"github_version": remote_version,
"github_version_is_editable": github_version_is_editable,
"display_github": display_github,
# Bitbucket
"bitbucket_user": bitbucket_user,
"bitbucket_repo": bitbucket_repo,
"bitbucket_version": remote_version,
"bitbucket_version_is_editable": bitbucket_version_is_editable,
"display_bitbucket": display_bitbucket,
# GitLab
"gitlab_user": gitlab_user,
"gitlab_repo": gitlab_repo,
"gitlab_version": remote_version,
"gitlab_version_is_editable": gitlab_version_is_editable,
"display_gitlab": display_gitlab,
# Features
"docsearch_disabled": self.project.has_feature(
Feature.DISABLE_SERVER_SIDE_SEARCH
),
}

finalize_sphinx_context_data.send(
sender=self.__class__,
build_env=self.build_env,
data=data,
)

return data

def append_conf(self):
"""
Find a ``conf.py`` and appends default content.
The default content is rendered from ``doc_builder/conf.py.tmpl``.
"""
def show_conf(self):
"""Show the current ``conf.py`` being used."""
if self.config_file is None:
raise ProjectConfigurationError(ProjectConfigurationError.NOT_FOUND)

Expand All @@ -264,22 +120,6 @@ def append_conf(self):
},
)

if not self.project.has_feature(Feature.DISABLE_SPHINX_MANIPULATION):
# Allow symlinks, but only the ones that resolve inside the base directory.
# NOTE: if something goes wrong,
# `safe_open` raises an exception that's clearly communicated to the user.
outfile = safe_open(
self.config_file, "a", allow_symlinks=True, base_path=self.project_path
)

# Append config to project conf file
tmpl = template_loader.get_template("doc_builder/conf.py.tmpl")
rendered = tmpl.render(self.get_config_params())

with outfile:
outfile.write("\n")
outfile.write(rendered)

# Print the contents of conf.py in order to make the rendered
# configfile visible in the build logs
self.run(
Expand Down Expand Up @@ -357,18 +197,9 @@ def __init__(self, *args, **kwargs):


class LocalMediaBuilder(BaseSphinx):
sphinx_builder = "readthedocssinglehtmllocalmedia"
sphinx_builder = "singlehtml"
relative_output_dir = "htmlzip"

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

# The builder `readthedocssinglehtmllocalmedia` is defined by our
# `readthedocs-sphinx-ext` extension that we are not installing
# anymore; so we want to use the default Sphinx `singlehtml` builder
if self.project.has_feature(Feature.DISABLE_SPHINX_MANIPULATION):
self.sphinx_builder = "singlehtml"

def _post_build(self):
"""Internal post build to create the ZIP file from the HTML output."""
target_file = os.path.join(
Expand Down
4 changes: 2 additions & 2 deletions readthedocs/doc_builder/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ def get_final_doctype(self):
"""Some builders may have a different doctype at build time."""
return self.config.doctype

def append_conf(self):
"""Set custom configurations for this builder."""
def show_conf(self):
"""Show the configuration used for this builder."""

def build(self):
"""Do the actual building of the documentation."""
Expand Down
8 changes: 3 additions & 5 deletions readthedocs/doc_builder/director.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
from readthedocs.doc_builder.python_environments import Conda, Virtualenv
from readthedocs.projects.constants import BUILD_COMMANDS_OUTPUT_PATH_HTML
from readthedocs.projects.exceptions import RepositoryError
from readthedocs.projects.models import Feature
from readthedocs.projects.signals import after_build, before_build, before_vcs
from readthedocs.storage import build_tools_storage

Expand Down Expand Up @@ -196,9 +195,8 @@ def build(self):
self.run_build_job("post_build")
self.store_readthedocs_build_yaml()

if self.data.project.has_feature(Feature.DISABLE_SPHINX_MANIPULATION):
# Mark this version to inject the new js client when serving it via El Proxito
self.data.version.addons = True
# Mark this version to inject the new js client when serving it via El Proxito.
self.data.version.addons = True

after_build.send(
sender=self.data.version,
Expand Down Expand Up @@ -647,7 +645,7 @@ def build_docs_class(self, builder_class):
)

if builder_class == self.data.config.doctype:
builder.append_conf()
builder.show_conf()
self.data.version.documentation_type = builder.get_final_doctype()

success = builder.build()
Expand Down
7 changes: 0 additions & 7 deletions readthedocs/doc_builder/python_environments.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,6 @@ def _install_latest_requirements(self, pip_install_cmd):
else:
requirements.append("sphinx")

# Install ``readthedocs-sphinx-ext`` only on old projects
if not self.project.has_feature(Feature.DISABLE_SPHINX_MANIPULATION):
requirements.append("readthedocs-sphinx-ext")

cmd = copy.copy(pip_install_cmd)
cmd.extend(requirements)
self.build_env.run(
Expand Down Expand Up @@ -356,9 +352,6 @@ def _get_core_requirements(self):
if self.config.doctype == "mkdocs":
pip_requirements.append("mkdocs")
else:
if not self.project.has_feature(Feature.DISABLE_SPHINX_MANIPULATION):
pip_requirements.append("readthedocs-sphinx-ext")

conda_requirements.extend(["sphinx"])

return pip_requirements, conda_requirements
Expand Down
5 changes: 0 additions & 5 deletions readthedocs/doc_builder/signals.py

This file was deleted.

Loading

0 comments on commit 1ebd4e5

Please sign in to comment.