Skip to content

Commit 9a98a7a

Browse files
committed
Build: don't run default steps if no sphinx or mkdocs
This PR modifies the build to not run default commands when the user doesn't specify `sphinx` or `mkdocs` configs in the YAML file. This allows to use the following YAML file to build with Docusaurus, for example: ```yaml version: 2 build: os: ubuntu-24.04 tools: nodejs: "22" jobs: install: - cd docs/ && npm install build: html: - cd docs/ && npm run build post_build: - mkdir --parents $READTHEDOCS_OUTPUT/html/ - cp --recursive docs/build/* $READTHEDOCS_OUTPUT/html/ ``` This is the structure I've been wanting to have to allow any type of doctool to work in our platform following the `build.jobs` pattern. The code deployed in production doesn't allow this because it runs automatically `create_environment`, `install_core_dependencies` and `install_requirements` even if the project is not using Python --which is incorrect. It fails with the generic error: " Unknown problem. There was a problem with Read the Docs while building your documentation" - https://app.readthedocs.org/projects/test-builds/builds/26425680/ - https://read-the-docs.sentry.io/issues/4458662274/ This PR detects if the user is defining `sphinx` or `mkdocs` and if it's not, it doesn't run those jobs and leave the user to handle the build workflow completely. * Related #11216 * Related #11551
1 parent d95c58b commit 9a98a7a

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

readthedocs/config/config.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,14 @@ def doctype(self):
828828

829829
if self.mkdocs:
830830
return "mkdocs"
831-
return self.sphinx.builder
831+
832+
# NOTE: we need to use "source config" here because `_config` is
833+
# auto-populated with Sphinx if no `sphinx` and no `mkdocs` keys are
834+
# declared.
835+
if self.source_config.get("sphinx"):
836+
return self.sphinx.builder
837+
838+
return GENERIC
832839

833840
@property
834841
def submodules(self):

readthedocs/doc_builder/director.py

+18-7
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ def setup_vcs(self):
107107
# self.run_build_job("pre_checkout")
108108
self.checkout()
109109

110+
self.run_default_commands = self.is_type_mkdocs() or self.is_type_sphinx()
111+
110112
self.run_build_job("post_checkout")
111113

112114
commit = self.data.build_commit or self.vcs_repository.commit
@@ -309,23 +311,28 @@ def create_environment(self):
309311
if self.data.config.build.jobs.create_environment is not None:
310312
self.run_build_job("create_environment")
311313
return
312-
self.language_environment.setup_base()
314+
315+
if self.run_default_commands or self.data.config.source_config.get("python"):
316+
self.language_environment.setup_base()
313317

314318
# Install
315319
def install(self):
316320
if self.data.config.build.jobs.install is not None:
317321
self.run_build_job("install")
318322
return
319323

320-
self.language_environment.install_core_requirements()
321-
self.language_environment.install_requirements()
324+
if self.run_default_commands or self.data.config.source_config.get("python"):
325+
self.language_environment.install_core_requirements()
326+
self.language_environment.install_requirements()
322327

323328
# Build
324329
def build_html(self):
325330
if self.data.config.build.jobs.build.html is not None:
326331
self.run_build_job("build.html")
327332
return
328-
return self.build_docs_class(self.data.config.doctype)
333+
334+
if self.run_default_commands:
335+
return self.build_docs_class(self.data.config.doctype)
329336

330337
def build_pdf(self):
331338
if "pdf" not in self.data.config.formats or self.data.version.type == EXTERNAL:
@@ -336,7 +343,7 @@ def build_pdf(self):
336343
return
337344

338345
# Mkdocs has no pdf generation currently.
339-
if self.is_type_sphinx():
346+
if self.is_type_sphinx() and self.run_default_commands:
340347
return self.build_docs_class("sphinx_pdf")
341348

342349
return False
@@ -353,7 +360,7 @@ def build_htmlzip(self):
353360
return
354361

355362
# We don't generate a zip for mkdocs currently.
356-
if self.is_type_sphinx():
363+
if self.is_type_sphinx() and self.run_default_commands:
357364
return self.build_docs_class("sphinx_singlehtmllocalmedia")
358365
return False
359366

@@ -366,7 +373,7 @@ def build_epub(self):
366373
return
367374

368375
# Mkdocs has no epub generation currently.
369-
if self.is_type_sphinx():
376+
if self.is_type_sphinx() and self.run_default_commands:
370377
return self.build_docs_class("sphinx_epub")
371378
return False
372379

@@ -744,6 +751,10 @@ def is_type_sphinx(self):
744751
"""Is documentation type Sphinx."""
745752
return "sphinx" in self.data.config.doctype
746753

754+
def is_type_mkdocs(self):
755+
"""Is documentation type MkDocs."""
756+
return "mkdocs" in self.data.config.doctype
757+
747758
def store_readthedocs_build_yaml(self):
748759
# load YAML from user
749760
yaml_path = os.path.join(

0 commit comments

Comments
 (0)