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

Blog post: partially or completely override the build process #345

Merged
merged 3 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
81 changes: 81 additions & 0 deletions content/posts/override-build-process-with-build-jobs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
title: You can now partially or completely override the build process
date: January 20, 2025
description: Announcing support for partially or completely override build steps using the `build.jobs` configuration.
category: Feature announcement
tags: configuration-file
authors: Santos Gallegos
status: published
image: /images/override-build-steps-with-build-jobs.jpg
image_credit: Photo by <a href="https://unsplash.com/@ryanquintal?utm_content=creditCopyText&utm_medium=referral&utm_source=unsplash">Ryan Quintal</a> on <a href="https://unsplash.com/photos/purple-block-toy-_H7p-RZUVo4?utm_content=creditCopyText&utm_medium=referral&utm_source=unsplash">Unsplash</a>

We are excited to announce that you can now partially or completely override build steps using the [`build.jobs`](https://docs.readthedocs.io/en/stable/config-file/v2.html#build-jobs) configuration in your `.readthedocs.yaml` configuration file.
This allows you to customize the build process to suit your project's specific requirements.
Find more details and examples in our [documentation](https://docs.readthedocs.io/en/stable/build-customization.html).

Previously, you could only extend the build process by using any of the `pre_` and `post_` build jobs,
we have now extended this functionality to allow you to override the build process completely.
The following build steps are available for you to override:

- `create_environment`
- `install`
- `build.html`
- `build.pdf`
- `build.epub`
- `build.htmlzip`

If you are using Sphinx or MkDocs, but you want to have more control over how a specific step is executed, you can override only that step.
For example, to use the normal build process for HTML and EPUB when building a Sphinx project,
but use [rinohtype](https://www.mos6581.org/rinohtype/master/intro.html#sphinx-builder) for PDF output, you can use the following configuration:

```yaml
version: 2

formats:
- pdf
- epub

sphinx:
configuration: docs/conf.py

python:
install:
- requirements: docs/requirements.txt

build:
os: ubuntu-24.04
tools:
python: "3.13"
jobs:
build:
pdf:
- sphinx-build -b rinoh docs _build/pdf/
- mkdir --parents $READTHEDOCS_OUTPUT/pdf/
- mv _build/pdf/*.pdf $READTHEDOCS_OUTPUT/pdf/
```

If you are using another tool, or you want complete control over the build process,
you can use a similar configuration without specifying a `sphinx` or `mkdocs` configuration to have full control over the build process.
For example, to build using [Markdoc](https://markdoc.dev/) you can use the following configuration:

```yaml
version: 2

build:
os: ubuntu-24.04
tools:
nodejs: "22"
jobs:
install:
- cd docs/ && npm install
build:
html:
- cd docs/ && npm run build
- mkdir --parents $READTHEDOCS_OUTPUT/html/
- cp --recursive docs/out/* $READTHEDOCS_OUTPUT/html/
```

You can check [our docs](https://docs.readthedocs.io/en/stable/intro/markdoc.html) for a working example.

We recommend using [`build.jobs`](https://docs.readthedocs.io/en/stable/config-file/v2.html#build-jobs) over [`build.commands`](https://docs.readthedocs.io/en/stable/config-file/v2.html#build-commands),
as it offers the same functionality as `build.commands`, but in a more structured way that allows you to define different commands for each format,
while also supporting installing system dependencies via `build.apt_packages`.
Comment on lines +79 to +81
Copy link
Member

Choose a reason for hiding this comment

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

We should probably put a section in the docs about when each should be used. I think build.commands is basically for when you want us to run no additional setup, and the reason apt_packages doesn't work is because we aren't doing any kind of environment setup, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

build.jobs can also be used to not run any additional steps, they are basically the same now.