Skip to content
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

Build: disable Sphinx manipulation #11441

Merged
merged 6 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/user/reference/environment-variables.rst
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ All :doc:`build processes </builds>` have the following environment variables au
:Example: ``https://docs.readthedocs.io/ja/stable/``
:Example: ``https://example--17.org.readthedocs.build/fr/17/``

.. envvar:: READTHEDOCS_REPOSITORY_PATH

Path where the repository was cloned.

:Example: ``/home/docs/checkouts/readthedocs.org/user_builds/test-builds/checkouts/latest``

.. envvar:: READTHEDOCS_GIT_CLONE_URL

URL for the remote source repository, from which the documentation is cloned.
Expand Down
25 changes: 13 additions & 12 deletions readthedocs/doc_builder/backends/sphinx.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,20 +264,21 @@ def append_conf(self):
},
)

# 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
)
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())
# 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)
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
Expand Down
9 changes: 9 additions & 0 deletions readthedocs/doc_builder/director.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
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 @@ -200,6 +201,10 @@ 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

after_build.send(
sender=self.data.version,
)
Expand Down Expand Up @@ -645,6 +650,9 @@ def get_rtd_env_vars(self):
"READTHEDOCS_VERSION_NAME": self.data.version.verbose_name,
"READTHEDOCS_PROJECT": self.data.project.slug,
"READTHEDOCS_LANGUAGE": self.data.project.language,
"READTHEDOCS_REPOSITORY_PATH": self.data.project.checkout_path(
self.data.version.slug
),
"READTHEDOCS_OUTPUT": os.path.join(
self.data.project.checkout_path(self.data.version.slug), "_readthedocs/"
),
Expand All @@ -654,6 +662,7 @@ def get_rtd_env_vars(self):
# "READTHEDOCS_GIT_HTML_URL": self.data.project.remote_repository.html_url,
"READTHEDOCS_GIT_IDENTIFIER": self.data.version.identifier,
"READTHEDOCS_GIT_COMMIT_HASH": self.data.build["commit"],
"READTHEDOCS_PRODUCTION_DOMAIN": settings.PRODUCTION_DOMAIN,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This kinda feels like an internal thing, especially not documenting it. I assume it's needed for something downstream?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is required by the sphinx-build-compatibility extension to know if we have to perform the APIv2 call to community or business. I may miss the documentation for this, but I will add it in that case. Seems useful to pass it to the build commands.

}
return env

Expand Down
11 changes: 5 additions & 6 deletions readthedocs/doc_builder/python_environments.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,11 @@ def _install_latest_requirements(self, pip_install_cmd):
if self.config.doctype == "mkdocs":
requirements.append("mkdocs")
else:
requirements.extend(
[
"sphinx",
"readthedocs-sphinx-ext",
]
)
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)
Expand Down
9 changes: 8 additions & 1 deletion readthedocs/projects/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1896,6 +1896,7 @@ def add_features(sender, **kwargs):
DONT_INSTALL_LATEST_PIP = "dont_install_latest_pip"
USE_SPHINX_RTD_EXT_LATEST = "rtd_sphinx_ext_latest"
INSTALL_LATEST_CORE_REQUIREMENTS = "install_latest_core_requirements"
DISABLE_SPHINX_MANIPULATION = "disable_sphinx_manipulation"

# Search related features
DISABLE_SERVER_SIDE_SEARCH = "disable_server_side_search"
Expand Down Expand Up @@ -1973,6 +1974,12 @@ def add_features(sender, **kwargs):
"Build: Install all the latest versions of Read the Docs core requirements"
),
),
(
DISABLE_SPHINX_MANIPULATION,
_(
"Sphinx: Don't append `conf.py` and don't install ``readthedocs-sphinx-ext``"
),
),
# Search related features.
(
DISABLE_SERVER_SIDE_SEARCH,
Expand Down Expand Up @@ -2033,7 +2040,7 @@ def get_feature_display(self):
Because the field is not a ChoiceField here, we need to manually
implement this behavior.
"""
return dict(self.FEATURES).get(self.feature_id, self.feature_id)
return str(dict(self.FEATURES).get(self.feature_id, self.feature_id))


class EnvironmentVariable(TimeStampedModel, models.Model):
Expand Down
4 changes: 4 additions & 0 deletions readthedocs/projects/tests/test_build_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,12 +361,16 @@ def test_get_env_vars(self, load_yaml_config, build_environment, config, externa
"READTHEDOCS_VERSION_NAME": self.version.verbose_name,
"READTHEDOCS_PROJECT": self.project.slug,
"READTHEDOCS_LANGUAGE": self.project.language,
"READTHEDOCS_OUTPUT": os.path.join(
self.project.checkout_path(self.version.slug),
),
"READTHEDOCS_OUTPUT": os.path.join(
self.project.checkout_path(self.version.slug), "_readthedocs/"
),
"READTHEDOCS_GIT_CLONE_URL": self.project.repo,
"READTHEDOCS_GIT_IDENTIFIER": self.version.identifier,
"READTHEDOCS_GIT_COMMIT_HASH": self.build.commit,
"READTHEDOCS_PRODUCTION_DOMAIN": settings.PRODUCTION_DOMAIN,
}

self._trigger_update_docs_task()
Expand Down