Skip to content

Commit 1ebd4e5

Browse files
authored
Remove disable_sphinx_manipulation feature flag (#11841)
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.
1 parent 5a4c099 commit 1ebd4e5

File tree

11 files changed

+23
-460
lines changed

11 files changed

+23
-460
lines changed

readthedocs/doc_builder/backends/mkdocs.py

+2-10
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,8 @@ def get_yaml_config(self):
7777
mkdocs_path,
7878
)
7979

80-
def append_conf(self):
81-
"""
82-
Call `cat mkdocs.yaml` only.
83-
84-
This behavior has changed. We used to parse the YAML file and append
85-
some configs automatically, but we have been removing that magic from
86-
our builders as much as we can.
87-
88-
This method will eventually removed completely.
89-
"""
80+
def show_conf(self):
81+
"""Show the current ``mkdocs.yaml`` being used."""
9082
# Write the mkdocs.yml to the build logs
9183
self.run(
9284
"cat",

readthedocs/doc_builder/backends/sphinx.py

+5-174
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,14 @@
1010
from pathlib import Path
1111

1212
import structlog
13-
from django.conf import settings
14-
from django.template import loader as template_loader
15-
from django.urls import reverse
16-
from requests.exceptions import ConnectionError
17-
18-
from readthedocs.builds import utils as version_utils
19-
from readthedocs.builds.models import APIVersion
20-
from readthedocs.core.utils.filesystem import safe_open
21-
from readthedocs.projects.constants import OLD_LANGUAGES_CODE_MAPPING, PUBLIC
13+
14+
from readthedocs.projects.constants import OLD_LANGUAGES_CODE_MAPPING
2215
from readthedocs.projects.exceptions import ProjectConfigurationError, UserFileNotFound
23-
from readthedocs.projects.models import Feature
24-
from readthedocs.projects.templatetags.projects_tags import sort_version_aware
2516

2617
from ..base import BaseBuilder
2718
from ..constants import PDF_RE
2819
from ..environments import BuildCommand, DockerBuildCommand
2920
from ..exceptions import BuildUserError
30-
from ..signals import finalize_sphinx_context_data
3121

3222
log = structlog.get_logger(__name__)
3323

@@ -115,142 +105,8 @@ def get_language(self, project):
115105
language = project.language
116106
return OLD_LANGUAGES_CODE_MAPPING.get(language, language)
117107

118-
def get_config_params(self):
119-
"""Get configuration parameters to be rendered into the conf file."""
120-
# TODO this should be handled better in the theme
121-
conf_py_path = os.path.join(
122-
os.path.sep,
123-
os.path.dirname(
124-
os.path.relpath(
125-
self.config_file,
126-
self.project_path,
127-
),
128-
),
129-
"",
130-
)
131-
remote_version = self.version.commit_name
132-
133-
github_user, github_repo = version_utils.get_github_username_repo(
134-
url=self.project.repo,
135-
)
136-
github_version_is_editable = self.version.type == "branch"
137-
display_github = github_user is not None
138-
139-
(
140-
bitbucket_user,
141-
bitbucket_repo,
142-
) = version_utils.get_bitbucket_username_repo( # noqa
143-
url=self.project.repo,
144-
)
145-
bitbucket_version_is_editable = self.version.type == "branch"
146-
display_bitbucket = bitbucket_user is not None
147-
148-
gitlab_user, gitlab_repo = version_utils.get_gitlab_username_repo(
149-
url=self.project.repo,
150-
)
151-
gitlab_version_is_editable = self.version.type == "branch"
152-
display_gitlab = gitlab_user is not None
153-
154-
versions = []
155-
downloads = []
156-
subproject_urls = []
157-
try:
158-
active_versions_data = self.api_client.project(
159-
self.project.pk
160-
).active_versions.get()["versions"]
161-
versions = sort_version_aware(
162-
[APIVersion(**version_data) for version_data in active_versions_data]
163-
)
164-
if not self.project.has_feature(Feature.ALL_VERSIONS_IN_HTML_CONTEXT):
165-
versions = [v for v in versions if v.privacy_level == PUBLIC]
166-
downloads = self.api_client.version(self.version.pk).get()["downloads"]
167-
subproject_urls = [
168-
(project["slug"], project["canonical_url"])
169-
for project in self.api_client.project(self.project.pk)
170-
.subprojects()
171-
.get()["subprojects"]
172-
]
173-
except ConnectionError:
174-
log.exception(
175-
"Timeout while fetching versions/downloads/subproject_urls for Sphinx context.",
176-
project_slug=self.project.slug,
177-
version_slug=self.version.slug,
178-
)
179-
180-
build_id = self.build_env.build.get("id")
181-
build_url = None
182-
if build_id:
183-
build_url = reverse(
184-
"builds_detail",
185-
kwargs={
186-
"project_slug": self.project.slug,
187-
"build_pk": build_id,
188-
},
189-
)
190-
protocol = "http" if settings.DEBUG else "https"
191-
build_url = f"{protocol}://{settings.PRODUCTION_DOMAIN}{build_url}"
192-
193-
vcs_url = None
194-
if self.version.is_external:
195-
vcs_url = self.version.vcs_url
196-
197-
commit = self.project.vcs_repo(
198-
version=self.version.slug,
199-
environment=self.build_env,
200-
).commit
201-
202-
data = {
203-
"current_version": self.version.verbose_name,
204-
"project": self.project,
205-
"version": self.version,
206-
"settings": settings,
207-
"conf_py_path": conf_py_path,
208-
"api_host": settings.PUBLIC_API_URL,
209-
"commit": commit,
210-
"versions": versions,
211-
"downloads": downloads,
212-
"subproject_urls": subproject_urls,
213-
"build_url": build_url,
214-
"vcs_url": vcs_url,
215-
"proxied_static_path": self.project.proxied_static_path,
216-
# GitHub
217-
"github_user": github_user,
218-
"github_repo": github_repo,
219-
"github_version": remote_version,
220-
"github_version_is_editable": github_version_is_editable,
221-
"display_github": display_github,
222-
# Bitbucket
223-
"bitbucket_user": bitbucket_user,
224-
"bitbucket_repo": bitbucket_repo,
225-
"bitbucket_version": remote_version,
226-
"bitbucket_version_is_editable": bitbucket_version_is_editable,
227-
"display_bitbucket": display_bitbucket,
228-
# GitLab
229-
"gitlab_user": gitlab_user,
230-
"gitlab_repo": gitlab_repo,
231-
"gitlab_version": remote_version,
232-
"gitlab_version_is_editable": gitlab_version_is_editable,
233-
"display_gitlab": display_gitlab,
234-
# Features
235-
"docsearch_disabled": self.project.has_feature(
236-
Feature.DISABLE_SERVER_SIDE_SEARCH
237-
),
238-
}
239-
240-
finalize_sphinx_context_data.send(
241-
sender=self.__class__,
242-
build_env=self.build_env,
243-
data=data,
244-
)
245-
246-
return data
247-
248-
def append_conf(self):
249-
"""
250-
Find a ``conf.py`` and appends default content.
251-
252-
The default content is rendered from ``doc_builder/conf.py.tmpl``.
253-
"""
108+
def show_conf(self):
109+
"""Show the current ``conf.py`` being used."""
254110
if self.config_file is None:
255111
raise ProjectConfigurationError(ProjectConfigurationError.NOT_FOUND)
256112

@@ -264,22 +120,6 @@ def append_conf(self):
264120
},
265121
)
266122

267-
if not self.project.has_feature(Feature.DISABLE_SPHINX_MANIPULATION):
268-
# Allow symlinks, but only the ones that resolve inside the base directory.
269-
# NOTE: if something goes wrong,
270-
# `safe_open` raises an exception that's clearly communicated to the user.
271-
outfile = safe_open(
272-
self.config_file, "a", allow_symlinks=True, base_path=self.project_path
273-
)
274-
275-
# Append config to project conf file
276-
tmpl = template_loader.get_template("doc_builder/conf.py.tmpl")
277-
rendered = tmpl.render(self.get_config_params())
278-
279-
with outfile:
280-
outfile.write("\n")
281-
outfile.write(rendered)
282-
283123
# Print the contents of conf.py in order to make the rendered
284124
# configfile visible in the build logs
285125
self.run(
@@ -357,18 +197,9 @@ def __init__(self, *args, **kwargs):
357197

358198

359199
class LocalMediaBuilder(BaseSphinx):
360-
sphinx_builder = "readthedocssinglehtmllocalmedia"
200+
sphinx_builder = "singlehtml"
361201
relative_output_dir = "htmlzip"
362202

363-
def __init__(self, *args, **kwargs):
364-
super().__init__(*args, **kwargs)
365-
366-
# The builder `readthedocssinglehtmllocalmedia` is defined by our
367-
# `readthedocs-sphinx-ext` extension that we are not installing
368-
# anymore; so we want to use the default Sphinx `singlehtml` builder
369-
if self.project.has_feature(Feature.DISABLE_SPHINX_MANIPULATION):
370-
self.sphinx_builder = "singlehtml"
371-
372203
def _post_build(self):
373204
"""Internal post build to create the ZIP file from the HTML output."""
374205
target_file = os.path.join(

readthedocs/doc_builder/base.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ def get_final_doctype(self):
4040
"""Some builders may have a different doctype at build time."""
4141
return self.config.doctype
4242

43-
def append_conf(self):
44-
"""Set custom configurations for this builder."""
43+
def show_conf(self):
44+
"""Show the configuration used for this builder."""
4545

4646
def build(self):
4747
"""Do the actual building of the documentation."""

readthedocs/doc_builder/director.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
from readthedocs.doc_builder.python_environments import Conda, Virtualenv
2626
from readthedocs.projects.constants import BUILD_COMMANDS_OUTPUT_PATH_HTML
2727
from readthedocs.projects.exceptions import RepositoryError
28-
from readthedocs.projects.models import Feature
2928
from readthedocs.projects.signals import after_build, before_build, before_vcs
3029
from readthedocs.storage import build_tools_storage
3130

@@ -196,9 +195,8 @@ def build(self):
196195
self.run_build_job("post_build")
197196
self.store_readthedocs_build_yaml()
198197

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

203201
after_build.send(
204202
sender=self.data.version,
@@ -647,7 +645,7 @@ def build_docs_class(self, builder_class):
647645
)
648646

649647
if builder_class == self.data.config.doctype:
650-
builder.append_conf()
648+
builder.show_conf()
651649
self.data.version.documentation_type = builder.get_final_doctype()
652650

653651
success = builder.build()

readthedocs/doc_builder/python_environments.py

-7
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,6 @@ def _install_latest_requirements(self, pip_install_cmd):
176176
else:
177177
requirements.append("sphinx")
178178

179-
# Install ``readthedocs-sphinx-ext`` only on old projects
180-
if not self.project.has_feature(Feature.DISABLE_SPHINX_MANIPULATION):
181-
requirements.append("readthedocs-sphinx-ext")
182-
183179
cmd = copy.copy(pip_install_cmd)
184180
cmd.extend(requirements)
185181
self.build_env.run(
@@ -356,9 +352,6 @@ def _get_core_requirements(self):
356352
if self.config.doctype == "mkdocs":
357353
pip_requirements.append("mkdocs")
358354
else:
359-
if not self.project.has_feature(Feature.DISABLE_SPHINX_MANIPULATION):
360-
pip_requirements.append("readthedocs-sphinx-ext")
361-
362355
conda_requirements.extend(["sphinx"])
363356

364357
return pip_requirements, conda_requirements

readthedocs/doc_builder/signals.py

-5
This file was deleted.

0 commit comments

Comments
 (0)