Skip to content

Commit 10996fe

Browse files
CAM-Gerlachhugovk
andauthored
Overhaul Building the Documentation section for clarity (GH-1038)
* Overhaul Building the Documentation section for clarity * Apply suggestions and further clarifications from Hugo Co-authored-by: Hugo van Kemenade <[email protected]>
1 parent e2fc6f3 commit 10996fe

File tree

1 file changed

+79
-49
lines changed

1 file changed

+79
-49
lines changed

documentation/start-documenting.rst

Lines changed: 79 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -64,79 +64,109 @@ Building the documentation
6464

6565
.. highlight:: bash
6666

67-
The toolset used to build the docs is written in Python and is called Sphinx_.
68-
Sphinx is maintained separately and is not included in this tree. Also needed
69-
are blurb_, a tool to create :file:`Misc/NEWS` on demand; and
70-
python-docs-theme_, the Sphinx theme for the Python documentation.
67+
To build the documentation, follow the steps in one of the sections below.
68+
You can view the documentation after building the HTML
69+
by opening the file :file:`Doc/build/html/index.html` in a web browser.
7170

72-
To build the documentation, follow the instructions from one of the sections
73-
below. You can view the documentation after building the HTML by pointing
74-
a browser at the file :file:`Doc/build/html/index.html`.
71+
.. note::
7572

76-
You are expected to have installed the latest stable version of
77-
Sphinx_ and blurb_ on your system or in a virtualenv_ (which can be
78-
created using ``make venv``), so that the Makefile can find the
79-
``sphinx-build`` command. You can also specify the location of
80-
``sphinx-build`` with the ``SPHINXBUILD`` :command:`make` variable.
73+
The following instructions all assume your current working dir is
74+
the ``Doc`` subdirectory in your :ref:`CPython repository clone <checkout>`.
75+
Make sure to switch to it with ``cd Doc`` if necessary.
8176

8277

83-
.. _building-using-make:
78+
.. _doc-create-venv:
79+
80+
Create a virtual environment
81+
----------------------------
8482

85-
Using make / make.bat
86-
---------------------
83+
.. _doc-create-venv-unix:
8784

88-
**On Unix**, run the following from the root of your :ref:`repository clone
89-
<checkout>` to build the output as HTML::
85+
**On Unix platforms** that support :program:`make`
86+
(including Linux, macOS and BSD),
87+
you can create a new :mod:`venv` with the required dependencies using::
9088

91-
cd Doc
9289
make venv
93-
make html
9490

95-
or alternatively ``make -C Doc/ venv html``. ``htmlview`` can be used
96-
instead of ``html`` to conveniently open the docs in a browser once the
97-
build completes.
91+
Building the docs with :program:`make` will automatically use this environment
92+
without you having to activate it.
93+
94+
.. _doc-create-venv-windows:
95+
96+
**On Windows**, or if not using :program:`make`,
97+
`create a new virtual environment <venv-create_>`__ manually.
98+
Always be sure to `activate this environment <venv-activate_>`__
99+
before building the documentation.
100+
101+
102+
.. _building-using-make:
103+
.. _using-make-make-bat:
104+
.. _doc-build-make:
105+
106+
Build using make / make.bat
107+
---------------------------
98108

99-
You can also use ``make help`` to see a list of targets supported by
100-
:command:`make`. Note that ``make check`` is automatically run when
101-
you submit a :ref:`pull request <pullrequest>`, so you should make
102-
sure that it runs without errors.
109+
A Unix ``Makefile`` is provided, :cpy-file:`Doc/Makefile`,
110+
along with a :cpy-file:`Doc/make.bat` batch file for Windows
111+
that attempts to emulate it as closely as practical.
103112

104-
**On Windows**, the :cpy-file:`Doc/make.bat` batchfile tries to emulate
105-
:command:`make` as closely as possible, but the venv target is not implemented,
106-
so you will probably want to make sure you are working in a virtual environment
107-
before proceeding, otherwise all dependencies will be automatically installed
108-
on your system.
113+
.. important::
109114

110-
When ready, run the following from the root of your :ref:`repository clone
111-
<checkout>` to build the output as HTML::
115+
The Windows ``make.bat`` batch file lacks a ``make venv`` target.
116+
Instead, it automatically installs any missing dependencies
117+
into the currently activated environment (or the base Python, if none).
118+
Make sure the environment you :ref:`created above <doc-create-venv-windows>`
119+
is `activated <venv-activate_>`__ before running ``make.bat``.
120+
121+
To build the docs as HTML, run::
112122

113-
cd Doc
114123
make html
115124

116-
You can also use ``make help`` to see a list of targets supported by
117-
:cpy-file:`Doc/make.bat`.
125+
.. tip:: Substitute ``htmlview`` for ``html`` to open the docs in a web browser
126+
once the build completes.
127+
128+
To check the docs for common errors with `Sphinx Lint`_
129+
(which is run on all :ref:`pull requests <pullrequest>`), use::
130+
131+
make check
132+
133+
To list other supported :program:`make` targets, run::
134+
135+
make help
136+
137+
See :cpy-file:`Doc/README.rst` for more information.
138+
139+
140+
.. _using-sphinx-build:
141+
.. _doc-build-sphinx:
142+
143+
Build using Sphinx directly
144+
---------------------------
145+
146+
Advanced users may want to invoke Sphinx directly,
147+
to pass specialized options or to handle specific use cases.
118148

119-
See also :cpy-file:`Doc/README.rst` for more information.
149+
Make sure the environment you :ref:`created above <doc-create-venv-windows>`
150+
is `activated <venv-activate_>`__.
151+
Then, install the documentation requirements, :cpy-file:`Doc/requirements.txt`.
152+
Using pip::
120153

121-
Using sphinx-build
122-
------------------
154+
python -m pip install --upgrade -r requirements.txt
123155

124-
Sometimes we directly want to execute the sphinx-build tool instead of through
125-
``make`` (although the latter is still the preferred way). In this case, you can
126-
use the following command line from the ``Doc`` directory (make sure to install
127-
Sphinx_, blurb_ and python-docs-theme_ packages from PyPI)::
156+
Finally, directly invoke Sphinx with::
128157

129-
sphinx-build -b<builder> . build/<builder>
158+
python -m sphinx -b html . build/html
130159

131-
where ``<builder>`` is one of html, text, latex, or htmlhelp (for explanations
132-
see the make targets above).
160+
To use a different `Sphinx builder`_,
161+
replace ``html`` above with the desired builder ``name``.
133162

134163

135164
.. _docutils: https://docutils.sourceforge.io/
136-
.. _python-docs-theme: https://pypi.org/project/python-docs-theme/
137165
.. _Sphinx: https://www.sphinx-doc.org/
138-
.. _virtualenv: https://virtualenv.pypa.io/
139-
.. _blurb: https://pypi.org/project/blurb/
166+
.. _Sphinx builder: https://www.sphinx-doc.org/en/master/usage/builders/index.html
167+
.. _Sphinx Lint: https://github.com/sphinx-contrib/sphinx-lint
168+
.. _venv-activate: https://packaging.python.org/en/latest/guides/installing-using-pip-and-virtual-environments/#activating-a-virtual-environment
169+
.. _venv-create: https://packaging.python.org/en/latest/guides/installing-using-pip-and-virtual-environments/#creating-a-virtual-environment
140170

141171

142172
Style Guide

0 commit comments

Comments
 (0)