Skip to content

Commit e6d424c

Browse files
authored
Merge pull request #5569 from lethosor/docs-docs-improvements
Documentation system docs improvements
2 parents 16a723c + 26fcf36 commit e6d424c

File tree

5 files changed

+122
-43
lines changed

5 files changed

+122
-43
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ if(BUILD_DOCS)
523523

524524
add_custom_command(OUTPUT ${SPHINX_OUTPUT}
525525
COMMAND "${Python3_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/docs/build.py"
526-
${SPHINX_BUILD_TARGETS} --sphinx="${SPHINX_EXECUTABLE}" -- -q -W
526+
${SPHINX_BUILD_TARGETS} --sphinx="${SPHINX_EXECUTABLE}" --quiet -- -W
527527
DEPENDS ${SPHINX_DEPS}
528528
COMMENT "Building documentation with Sphinx"
529529
)

docs/build.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ def output_format(s):
6262
help='Sphinx executable to run [environment variable: SPHINX; default: "sphinx-build"]')
6363
parser.add_argument('-j', '--jobs', type=str, default=os.environ.get('JOBS', 'auto'),
6464
help='Number of Sphinx threads to run [environment variable: JOBS; default: "auto"]')
65+
parser.add_argument('-q', '--quiet', action='store_true',
66+
help='Disable most output on stdout (also passed to sphinx-build)')
6567
parser.add_argument('--debug', action='store_true',
6668
help='Log commands that are run, etc.')
6769
parser.add_argument('--offline', action='store_true',
@@ -91,11 +93,14 @@ def output_format(s):
9193
command = [args.sphinx] + OUTPUT_FORMATS[format_name].args + ['-j', args.jobs]
9294
if args.clean:
9395
command += ['-E']
96+
if args.quiet:
97+
command += ['-q']
9498
command += forward_args
9599

96100
if args.debug:
97101
print('Building:', format_name)
98102
print('Running:', command)
99103
subprocess.run(command, check=True, env=sphinx_env)
100104

101-
print('')
105+
if not args.quiet:
106+
print('')

docs/changelog.txt

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,30 @@
11
=== Scroll down for changes
22

33
===[[[
4-
The text below is included in docs/dev/Documentation.rst - see that file for more details on the changelog setup.
5-
This is kept in this file as a quick syntax reference.
4+
For information on how to edit/build the changelogs, see `docs/html/docs/dev/Documentation.html` or `docs/dev/Documentation.rst`.
65

7-
===help
6+
The text between the `syntax-reference` markers is included in `docs/dev/Documentation.rst`, so it must be valid RST.
7+
It is kept in this file as a quick syntax reference.
88

9-
changelog.txt uses a syntax similar to RST, with a few special sequences:
9+
===syntax-reference-start
10+
11+
The changelogs use a syntax similar to RST, with a few special sequences:
1012

1113
- ``===`` indicates the start of a comment
1214
- ``#`` indicates the start of a release name (do not include "DFHack")
13-
- ``##`` indicates the start of a section name (this must be listed in ``gen_changelog.py``)
15+
- ``##`` indicates the start of a section name (which must be listed in ``docs/sphinx_extensions/dfhack/changelog.py``)
1416
- ``-`` indicates the start of a changelog entry. **Note:** an entry currently must be only one line.
15-
- ``:`` (colon followed by space) separates the name of a feature from a description of a change to that feature.
16-
Changes made to the same feature are grouped if they end up in the same section.
17-
- ``:\`` (colon, backslash, space) avoids the above behavior
18-
- ``- @`` (the space is optional) indicates the start of an entry that should only be displayed in NEWS-dev.rst.
19-
Use this sparingly, e.g. for immediate fixes to one development build in another development build that
20-
are not of interest to users of stable builds only.
17+
- ``:`` (followed by space) separates the name of a feature from a description of a change to that feature.
18+
- Changes made to the same feature are grouped if they end up in the same section.
19+
- ``:\`` (followed by space) avoids the above behavior
20+
- ``- @`` (the space is optional) indicates the start of an entry that should only be displayed in ``NEWS-dev.rst``.
21+
- Use this sparingly, e.g. for immediate fixes to one development build in another development build that
22+
are not of interest to users of stable builds only.
2123
- Three ``[`` characters indicate the start of a block (possibly a comment) that
2224
spans multiple lines. Three ``]`` characters indicate the end of such a block.
23-
- ``!`` immediately before a phrase set up to be replaced (see gen_changelog.py) stops that occurrence from being replaced.
25+
- ``!`` immediately before a configured replacement (see ``docs/sphinx_extensions/dfhack/changelog.py``) stops that occurrence from being replaced.
26+
27+
===syntax-reference-end
2428

2529
Template for new versions:
2630

@@ -40,7 +44,6 @@ Template for new versions:
4044

4145
## Removed
4246

43-
===end
4447
]]]
4548

4649
================================================================================

docs/dev/Documentation.rst

Lines changed: 85 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ with relevant tags. These are used to compile indices and generate cross-links b
6767
commands, both in the HTML documents and in-game. See the list of available `tag-list` and
6868
think about which categories your new tool belongs in.
6969

70+
.. _docs-links:
71+
7072
Links
7173
-----
7274

@@ -418,6 +420,8 @@ Once you have pip available, you can install Sphinx with the following command::
418420
Note that this may require opening a new (admin) command prompt if you just
419421
installed pip from the same command prompt.
420422

423+
.. _docs-build:
424+
421425
Building the documentation
422426
==========================
423427

@@ -427,16 +431,18 @@ Sphinx to build the docs:
427431
Using CMake
428432
-----------
429433

430-
See our page on `build options <building-documentation>`
434+
See our page on `build options <building-documentation>`.
431435

432-
Running Sphinx manually
433-
-----------------------
436+
Using the documentation build script
437+
------------------------------------
434438

435439
You can also build the documentation without running CMake - this is faster if
436-
you only want to rebuild the documentation regardless of any code changes. The
437-
``docs/build.py`` script will build the documentation in any specified formats
438-
(HTML only by default) using the same command that CMake runs when building the
439-
docs. Run the script with ``--help`` to see additional options.
440+
you only want to rebuild the documentation regardless of any code changes.
441+
442+
The recommended approach is the ``docs/build.py`` script. This is the same
443+
script that CMake uses internally, which wraps Sphinx with a few additional
444+
options to handle common cases and can build multiple documentation formats with
445+
a single invocation.
440446

441447
Examples:
442448

@@ -449,15 +455,43 @@ Examples:
449455
* ``docs/build.py --clean``
450456
Build HTML and force a clean build (all source files are re-read)
451457

452-
The resulting documentation will be stored in ``docs/html`` and/or ``docs/text``.
458+
* ``docs/build.py --help``
459+
Display a full list of available options
460+
461+
The resulting documentation will be stored in ``docs/html`` and/or ``docs/text``
462+
(or generally, a subfolder of ``docs/`` named after the requested output format(s)).
463+
464+
Building a PDF version
465+
----------------------
466+
467+
ReadTheDocs automatically builds a PDF version of the documentation (available
468+
under the "Downloads" section when clicking on the release selector). If you
469+
want to build a PDF version locally, you will need the ``pdflatex`` command, which is part
470+
of a TeX distribution. The following command will then build a PDF, located in
471+
``docs/pdf/latex/DFHack.pdf``, with default options::
472+
473+
docs/build.py pdf
474+
475+
Running Sphinx manually
476+
-----------------------
477+
478+
If ``docs/build.py`` does not support what you need, you can also run Sphinx
479+
manually. This is primarily useful for low-level debugging.
453480

454-
Alternatively, you can run Sphinx manually with::
481+
For a good starting point, add the ``--debug`` argument to your call to
482+
``docs/build.py``. This will cause the script to print out the Sphinx command(s)
483+
that it is running.
455484

456-
sphinx-build . docs/html
485+
Some examples:
457486

458-
or, to build plain-text output::
487+
* ``sphinx-build . docs/html``
488+
Build the HTML docs (equivalent to ``docs/build.py``)
459489

460-
sphinx-build -b text . docs/text
490+
* ``sphinx-build -b text . docs/text``
491+
Build the plain text docs (equivalent to ``docs/build.py text``)
492+
493+
* ``sphinx-build -M latexpdf . docs/pdf``
494+
Build the PDF docs
461495

462496
Sphinx has many options to enable clean builds, parallel builds, logging, and
463497
more - run ``sphinx-build --help`` for details. If you specify a different
@@ -466,20 +500,47 @@ folder. Also be aware that when running ``sphinx-build`` directly, the
466500
``docs/html`` folder may be polluted with intermediate build files that normally
467501
get written in the cmake ``build`` directory.
468502

469-
Building a PDF version
470-
----------------------
503+
Troubleshooting
504+
===============
471505

472-
ReadTheDocs automatically builds a PDF version of the documentation (available
473-
under the "Downloads" section when clicking on the release selector). If you
474-
want to build a PDF version locally, you will need ``pdflatex``, which is part
475-
of a TeX distribution. The following command will then build a PDF, located in
476-
``docs/pdf/latex/DFHack.pdf``, with default options::
506+
Sphinx errors are typically printed by Sphinx, so ensure that you are not silencing Sphinx output.
477507

478-
docs/build.py pdf
508+
When built with ``docs/build.py`` or CMake, errors are also logged to
509+
``build/docs/<format>/sphinx-warnings.txt`` (for instance, if you are building
510+
the HTML docs, ``build/docs/html/sphinx-warnings.txt``).
511+
512+
513+
"undefined label"
514+
-----------------
515+
516+
Typical causes:
517+
518+
* You have used single backticks for an inline code snippet, where double backticks should be used instead (see `docs-links`)::
519+
520+
`this is an invalid inline code snippet (actually a link)`
521+
``this is a valid inline code snippet``
522+
523+
* You are attempting to link to a section/label, but either it does not have a label defined or you have spelled it incorrectly::
524+
525+
.. my-label:
526+
527+
This is where the link should go to.
528+
529+
...
530+
531+
This is `a valid link to the earlier label <my-label>`. So is `my-label`.
532+
533+
"toctree contains reference to document that doesn't have a title"
534+
------------------------------------------------------------------
535+
536+
Due to the nature of our autogenerated documentation, this can sometimes occur
537+
when switching between branches that have different autogenerated files, and can
538+
result in autogenerated documentation (e.g. for individual tools) being missing
539+
from the table of contents, or links failing to generate.
479540

480-
Alternatively, you can run Sphinx manually with::
541+
The quickest resolution is a clean docs build::
481542

482-
sphinx-build -M latexpdf . docs/pdf
543+
docs/build.py --clean
483544

484545
.. _build-changelog:
485546

@@ -515,8 +576,8 @@ Changelog syntax
515576
----------------
516577

517578
.. include:: /docs/changelog.txt
518-
:start-after: ===help
519-
:end-before: ===end
579+
:start-after: ===syntax-reference-start
580+
:end-before: ===syntax-reference-end
520581

521582
.. _docs-ci:
522583

docs/dev/compile/Options.rst

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,16 +136,26 @@ Usage::
136136

137137
Documentation
138138
=============
139-
If you need to build documentation. Documentation can be built as HTML, and PDF,
140-
but there are also plain text files generated for in-game.
139+
If you need to build `documentation <documentation>`.
141140

142-
Variable: ``BUILD_DOCS``
141+
.. note::
142+
143+
These options are primarily useful for verifying that the end-to-end process
144+
for building and packaging the documentation is working as expected. For
145+
iterating on documentation changes, `faster alternatives <docs-build>` are
146+
available.
147+
148+
Variables:
149+
150+
* ``BUILD_DOCS``: enables the default documentation build
151+
* ``BUILD_DOCS_NO_HTML``: disables the HTML documentation build (only builds the text documentation used in-game)
143152

144153
Usage::
145154

146155
cmake .. -DBUILD_DOCS:bool=ON
147156
cmake .. -DBUILD_DOCS=1
148-
157+
cmake .. -DBUILD_DOCS_NO_HTML:bool=ON
158+
cmake .. -DBUILD_DOCS_NO_HTML=1
149159

150160
The generated documentation is stored in ``docs/html`` and ``docs/text`` (respectively)
151161
in the root DFHack folder, and they will both be installed to ``hack/docs`` when you

0 commit comments

Comments
 (0)