|
| 1 | +How to add a configuration file |
| 2 | +=============================== |
| 3 | + |
| 4 | +As part of the initial set up for your Read the Docs site, |
| 5 | +you need to create a **configuration file** called ``.readthedocs.yaml``. |
| 6 | +The configuration file tells Read the Docs what specific settings to use for your project. |
| 7 | + |
| 8 | +This how-to guide covers: |
| 9 | + |
| 10 | +#. Where to put your configuration file. |
| 11 | +#. What to put in the configuration file. |
| 12 | +#. How to customize the configuration for your project. |
| 13 | + |
| 14 | +.. seealso:: |
| 15 | + |
| 16 | + :doc:`/tutorial/index`. |
| 17 | + Following the steps in our tutorial will help you setup your first documentation project. |
| 18 | + |
| 19 | + |
| 20 | +Where to put your configuration file |
| 21 | +------------------------------------ |
| 22 | + |
| 23 | +The ``.readthedocs.yaml`` file should be placed in the top-most directory of your project's repository. |
| 24 | +We will get to the contents of the file in the next steps. |
| 25 | + |
| 26 | +When you have changed the configuration file, |
| 27 | +you need to commit and push the changes to your Git repository. |
| 28 | +Read the Docs will then automatically find and use the configuration to build your project. |
| 29 | + |
| 30 | +.. note:: |
| 31 | + |
| 32 | + The Read the Docs configuration file is a `YAML`_ file. |
| 33 | + YAML is a human-friendly data serialization language for all programming languages. |
| 34 | + To learn more about the structure of these files, see the `YAML language overview`_. |
| 35 | + |
| 36 | +.. _YAML: https://yaml.org/ |
| 37 | +.. _YAML language overview: https://yaml.org/spec/1.2.2/#chapter-1-introduction-to-yaml |
| 38 | + |
| 39 | +.. _howto_templates: |
| 40 | + |
| 41 | +Getting started with a template |
| 42 | +------------------------------- |
| 43 | + |
| 44 | +Here are some configuration file examples to help you get started. |
| 45 | +Pick an example based on the tool that your project is using, |
| 46 | +copy its contents to ``.readthedocs.yaml`` and add the file to your Git repository. |
| 47 | + |
| 48 | +.. tabs:: |
| 49 | + |
| 50 | + .. tab:: Sphinx |
| 51 | + |
| 52 | + If your project uses Sphinx, |
| 53 | + we offer a special builder optimized for Sphinx projects. |
| 54 | + |
| 55 | + .. literalinclude:: /config-file/examples/sphinx/.readthedocs.yaml |
| 56 | + :language: yaml |
| 57 | + :linenos: |
| 58 | + :caption: .readthedocs.yaml |
| 59 | + |
| 60 | + |
| 61 | + .. tab:: MkDocs |
| 62 | + |
| 63 | + If your project uses MkDocs, |
| 64 | + we offer a special builder optimized for MkDocs projects. |
| 65 | + |
| 66 | + .. literalinclude:: /config-file/examples/mkdocs/.readthedocs.yaml |
| 67 | + :language: yaml |
| 68 | + :linenos: |
| 69 | + :caption: .readthedocs.yaml |
| 70 | + |
| 71 | +Editing the template |
| 72 | +-------------------- |
| 73 | + |
| 74 | +Now that you have a ``.readthedocs.yaml`` file added to your Git repository, |
| 75 | +you should see Read the Docs trying to build your project with the configuration file. |
| 76 | +The configuration file probably needs some adjustments to accommodate exactly your project setup. |
| 77 | + |
| 78 | +.. note:: |
| 79 | + |
| 80 | + If you added the configuration file in a separate branch, |
| 81 | + you may have to activate a :doc:`version </versions>` for that branch. |
| 82 | + |
| 83 | + If you have added the file in a pull request, |
| 84 | + you should enable :doc:`pull request builds </guides/pull-requests>`. |
| 85 | + |
| 86 | +Skip: file header and comments |
| 87 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 88 | + |
| 89 | +There are some parts of the templates that you can leave in place: |
| 90 | + |
| 91 | +Comments |
| 92 | + We added comments that explain the configuration options and optional features. |
| 93 | + These lines begin with a ``#``. |
| 94 | + |
| 95 | +Commented out features |
| 96 | + We use the ``#`` in front of some popular configuration options. |
| 97 | + They are there as examples, |
| 98 | + which you can choose to enable, delete or save for later. |
| 99 | + |
| 100 | +``version`` key |
| 101 | + The version key tells the system how to read the rest of the configuration file. |
| 102 | + The current and only supported version is **version 2**. |
| 103 | + |
| 104 | + |
| 105 | +Adjust: ``build.os`` |
| 106 | +~~~~~~~~~~~~~~~~~~~~ |
| 107 | + |
| 108 | +In our examples, |
| 109 | +we are using Read the Docs' custom image based on the latest Ubuntu release. |
| 110 | +Package versions in these images will not change drastically, |
| 111 | +though will receive periodic security updates. |
| 112 | + |
| 113 | +You should pay attention to this field if your project needs to build on an older version of Ubuntu, |
| 114 | +or in the future when you need features from a newer Ubuntu. |
| 115 | + |
| 116 | +.. seealso:: |
| 117 | + |
| 118 | + :ref:`config-file/v2:build.os` |
| 119 | + Configuration file reference with all values possible for ``build.os``. |
| 120 | + |
| 121 | + |
| 122 | +Adjust: Python configuration |
| 123 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 124 | + |
| 125 | +If you are using Python in your builds, |
| 126 | +you should define the Python version in ``build.tools.python``. |
| 127 | + |
| 128 | +The ``python`` key contains a list of sub-keys, |
| 129 | +specifying the requirements to install. |
| 130 | + |
| 131 | +- Use ``python.install.package`` to install the project itself as a Python package using pip |
| 132 | +- Use ``python.install.requirements`` to install packages from a requirements file |
| 133 | +- Use ``build.jobs`` to install packages using Poetry or PDM |
| 134 | + |
| 135 | +.. seealso:: |
| 136 | + |
| 137 | + :ref:`config-file/v2:build.tools.python` |
| 138 | + Configuration file reference with all Python versions available for ``build.tools.python``. |
| 139 | + |
| 140 | + :ref:`config-file/v2:python` |
| 141 | + Configuration file reference for configuring the Python environment activated by ``build.tools.python``. |
| 142 | + |
| 143 | +Adjust: Sphinx and MkDocs version |
| 144 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 145 | + |
| 146 | +If you are using either the ``sphinx`` or ``mkdocs`` builder, |
| 147 | +then Sphinx or MkDocs will be installed automatically in its latest version. |
| 148 | + |
| 149 | +But we recommend that you specify the version that your documentation project uses. |
| 150 | +The ``requirements`` key is a file path that points to a text (``.txt``) file |
| 151 | +that lists the Python packages you want Read the Docs to install. |
| 152 | + |
| 153 | +.. seealso:: |
| 154 | + |
| 155 | + :ref:`guides/reproducible-builds:Use a requirements file for Python dependencies` |
| 156 | + This guide explains how to specify Python requirements, |
| 157 | + such as the version of Sphinx or MkDocs. |
| 158 | + |
| 159 | + :ref:`config-file/v2:sphinx` |
| 160 | + Configuration file reference for configuring the Sphinx builder. |
| 161 | + |
| 162 | + :ref:`config-file/v2:mkdocs` |
| 163 | + Configuration file reference for configuring the MkDocs builder. |
| 164 | + |
| 165 | +Next steps |
| 166 | +---------- |
| 167 | + |
| 168 | +There are more configuration options that the ones mentioned in this guide. |
| 169 | + |
| 170 | +After you add a configuration file your Git repository, |
| 171 | +and you can see that Read the Docs is building your documentation using the file, |
| 172 | +you should have a look at the complete configuration file reference for options that might apply to your project. |
| 173 | + |
| 174 | +.. seealso:: |
| 175 | + |
| 176 | + :doc:`/config-file/v2`. |
| 177 | + The complete list of all possible ``.readthedocs.yaml`` settings, |
| 178 | + including the optional settings not covered in on this page. |
| 179 | + |
| 180 | + :doc:`/build-customization` |
| 181 | + Are familiar with running a command line? |
| 182 | + Perhaps there are special commands that you know you want Read the Docs to run. |
| 183 | + Read this guide and learn more about how you add your own commands to ``.readthedocs.yaml``. |
0 commit comments