Skip to content

Commit 85f754a

Browse files
Port documentation info from msprime to here.
1 parent b914beb commit 85f754a

1 file changed

Lines changed: 106 additions & 28 deletions

File tree

docs/development.md

Lines changed: 106 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -306,19 +306,15 @@ To bypass the checks temporarily use `git commit --no-verify`.
306306
## Documentation
307307

308308
The documentation for tskit is written using
309-
[Sphinx](http://www.sphinx-doc.org/en/stable/)
310-
and contained in the `docs` directory. The files in this directory are
311-
markdown files that serve as an input to [jupyterbook](https://jupyterbook.org/),
312-
which allows jupyter notebook code, primarily in Python, to be automatically
313-
executed and the output inserted before deployment. The docs are then
314-
deployed automatically to the [tskit.dev website](https://tskit.dev/).
315-
API documentation for both Python and C are generated automatically from
316-
source: documentation embedded in the source code makes use of sphinx and
317-
the [reStructuredText](http://docutils.sourceforge.net/rst.html) format to
318-
alloow formating and cross referencing.
319-
For the C code, a combination of [Doxygen](http://www.doxygen.nl/)
320-
and [breathe](https://breathe.readthedocs.io/en/latest/) is used to
321-
generate API documentation.
309+
[Sphinx](http://www.sphinx-doc.org/en/stable/) and contained in the `docs`
310+
directory. Narrative pages are written in
311+
[MyST Markdown](https://jupyterbook.org/content/myst.html) and built with
312+
[JupyterBook](https://jupyterbook.org/), which executes embedded Python code
313+
cells and inserts their output before deployment. API docstrings are written in
314+
[reStructuredText](http://docutils.sourceforge.net/rst.html). For the C code,
315+
a combination of [Doxygen](http://www.doxygen.nl/) and
316+
[breathe](https://breathe.readthedocs.io/en/latest/) generates API documentation.
317+
The docs are deployed automatically to the [tskit.dev website](https://tskit.dev/).
322318

323319
Please help us to improve the documentation! You can check on the list of
324320
[documentation issues](https://github.com/tskit-dev/tskit/issues?q=is%3Aissue+is%3Aopen+label%3Adocumentation)
@@ -369,25 +365,107 @@ Once you are happy with the changes, commit your updates and
369365
open a pull request on GitHub.
370366

371367

372-
### Tips and resources
368+
(sec_development_documentation_markup)=
373369

374-
- The reStructuredText
375-
[primer](https://www.sphinx-doc.org/en/1.8/usage/restructuredtext/basics.html)
376-
is a useful general resource on rst.
370+
### Markup languages
377371

378-
- See also the sphinx and rst [cheatsheet
379-
](https://docs.typo3.org/m/typo3/docs-how-to-document/master/en-us/WritingReST/CheatSheet.html)
372+
Because of the mixture of API documentation and notebook content, documentation
373+
is written using **two different markup languages**:
380374

381-
- The Sphinx Python and C
382-
[domains](https://www.sphinx-doc.org/en/master/usage/restructuredtext/domains.html)
383-
have extensive options for marking up code.
375+
- **MyST Markdown** for all narrative pages, thematic sections, and code
376+
examples. This is a superset of [CommonMark](https://commonmark.org) that
377+
enables executable Jupyter content and Sphinx cross-referencing.
378+
- **reStructuredText (rST)** for API docstrings embedded in the source code.
379+
These are processed by Sphinx and appear in the API reference pages.
384380

385-
- Make extensive use of
386-
[cross referencing](https://docs.typo3.org/m/typo3/docs-how-to-document/master/en-us/WritingReST/Hyperlinks.html).
387-
When linking to sections in the documentation, use the
388-
`` :ref:`sec_some_section_label` `` form rather than matching on the section
389-
title (which is brittle). Use `` :meth:`.Tree.some_method` ``,
390-
`` :func:`some_function` `` etc to refer to parts of the API.
381+
Some useful links for MyST:
382+
383+
- The [MyST cheat sheet](https://jupyterbook.org/reference/cheatsheet.html)
384+
- The "Write Book Content" section of the [Jupyter Book](https://jupyterbook.org/) docs
385+
- The [MyST Syntax Guide](https://myst-parser.readthedocs.io/en/latest/using/syntax.html)
386+
- The [Sphinx domains reference](https://www.sphinx-doc.org/en/master/usage/restructuredtext/domains.html)
387+
for marking up Python and C API elements
388+
- The [types of source files](https://jupyterbook.org/file-types/index.html)
389+
in the Jupyter Book docs (useful for understanding the MyST/rST mix)
390+
391+
Some directives are only available in rST and must be wrapped in an
392+
``eval-rst`` block within a Markdown file:
393+
394+
````md
395+
```{eval-rst}
396+
.. autoclass:: tskit.TreeSequence
397+
```
398+
````
399+
400+
(sec_development_documentation_api)=
401+
402+
### API Reference
403+
404+
API reference documentation comes from
405+
[docstrings](https://www.python.org/dev/peps/pep-0257/) in the source code,
406+
written in rST. Docstrings should be **concise** and **precise**. Examples
407+
should not be embedded directly in docstrings; instead, each significant
408+
parameter should link to the relevant section in the narrative documentation.
409+
410+
(sec_development_documentation_examples)=
411+
412+
### Examples
413+
414+
Narrative sections should provide context and worked examples using inline
415+
Jupyter code cells. These behave exactly like cells in a Jupyter notebook —
416+
the whole page is executed as one notebook during the build.
417+
418+
Code cells are written like this:
419+
420+
````md
421+
```{code-cell}
422+
import tskit
423+
# example code here
424+
```
425+
````
426+
427+
:::{warning}
428+
For a page to be executed as a notebook you **must** have the correct
429+
[YAML frontmatter](https://jupyterbook.org/reference/cheatsheet.html#executable-code)
430+
at the top of the file.
431+
:::
432+
433+
(sec_development_documentation_cross_referencing)=
434+
435+
### Cross referencing
436+
437+
Use the ``{ref}`` role to link to labelled sections within the docs:
438+
439+
````md
440+
See the {ref}`sec_development_documentation_cross_referencing` section for details.
441+
````
442+
443+
Sections should be labelled hierarchically immediately above the heading:
444+
445+
````md
446+
(sec_development_documentation_cross_referencing)=
447+
### Cross referencing
448+
````
449+
450+
The label is used as link text automatically, but can be overridden:
451+
452+
````md
453+
See {ref}`this section <sec_development_documentation_cross_referencing>` for more.
454+
````
455+
456+
To refer to API elements, use the appropriate inline role:
457+
458+
````md
459+
The {class}`.TreeSequence` class, the {meth}`.TreeSequence.trees` method,
460+
and the {func}`.load` function.
461+
````
462+
463+
From an rST docstring, use the colon-prefixed equivalents:
464+
465+
````rst
466+
See :ref:`sec_development_documentation_cross_referencing` for details.
467+
The :meth:`.TreeSequence.trees` method returns an iterator.
468+
````
391469

392470
(sec_development_python)=
393471

0 commit comments

Comments
 (0)