Skip to content

Commit 5d31ac4

Browse files
choldgrafmmcky
andauthored
Update getting started and reference docs (#365)
* Update getting started and reference docs * Update docs/use/formatting_outputs.md Co-authored-by: mmcky <mmcky@users.noreply.github.com>
1 parent 47b33d5 commit 5d31ac4

9 files changed

Lines changed: 147 additions & 107 deletions

File tree

docs/examples/custom-formats.Rmd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ nb_custom_formats = {
3333

3434
:::{important}
3535

36-
By default, Markdown cells in the Notebook will be parsed using the same MyST parser configuration as for other Markdown files ([see available configuration options](start/config-options)).
36+
By default, Markdown cells in the Notebook will be parsed using the same MyST parser configuration as for other Markdown files ([see available configuration options](config/reference)).
3737

3838
But, if this is incompatible with your file format, then you can specify for the Markdown to be parsed as **strictly CommonMark**, using a third argument:
3939

@@ -56,7 +56,7 @@ This key should be a list mapping each cell to the starting line number in the o
5656
}
5757
```
5858

59-
This mapping allows for "true" error reporting, as described in [](start/error-reporting).
59+
This mapping allows for "true" error reporting, as described in [](myst/error-reporting).
6060

6161
## Using Jupytext
6262

docs/use/config-reference.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
2+
(config/reference)=
3+
# Configuration reference
4+
5+
This page lists the configuration options that are available to control MyST-NB.
6+
For more detailed explanation of when to use each option, see the other sections in the documentation.
7+
8+
## MyST Parser configuration
9+
10+
The MyST-NB parser derives from {ref}`the base MyST-Parser <myst:intro/get-started>`, and so all the same configuration options are available.
11+
See the {ref}`MyST configuration options <myst:sphinx/config-options>` for the full set of options.
12+
13+
## Notebook execution configuration
14+
15+
This configuration is used to control how Jupyter Notebooks are executed at build-time.
16+
17+
`````{list-table}
18+
:header-rows: 1
19+
20+
* - Option
21+
- Default
22+
- Description
23+
* - `jupyter_cache`
24+
- ""
25+
- Path to jupyter_cache, [see here](execute/cache) for details.
26+
* - `execution_excludepatterns`
27+
- ()
28+
- Exclude certain file patterns from execution, [see here](execute/config) for details.
29+
* - `jupyter_execute_notebooks`
30+
- "auto"
31+
- The logic for executing notebooks, [see here](execute/config) for details.
32+
* - `execution_in_temp`
33+
- `False`
34+
- If `True`, then a temporary directory will be created and used as the command working directory (cwd), if `False` then the notebook's parent directory will be the cwd.
35+
* - `execution_allow_errors`
36+
- `False`
37+
- If `False`, when a code cell raises an error the execution is stopped, if `True` then all cells are always run.
38+
This can also be overridden by metadata in a notebook, [see here](execute/allow_errors) for details.
39+
* - `execution_timeout`
40+
- 30
41+
- The maximum time (in seconds) each notebook cell is allowed to run.
42+
This can also be overridden by metadata in a notebook, [see here](execute/timeout) for details.
43+
* - `execution_show_tb`
44+
- `False`
45+
- Show failed notebook tracebacks in stdout (in addition to writing to file).
46+
`````
47+
48+
## Notebook parsing and output rendering
49+
50+
These configuration options affect the look and feel of notebook parsing and output rendering.
51+
52+
`````{list-table}
53+
:header-rows: 1
54+
55+
* - Option
56+
- Default
57+
- Description
58+
* - `nb_custom_formats`
59+
- `{}`
60+
- Define custom functions for conversion of files to notebooks, [see here](examples/custom_formats) for details.
61+
* - `nb_render_priority`
62+
- `{}`
63+
- Dict override for MIME type render priority, [see here](use/format/priority) for details.
64+
* - `nb_render_plugin`
65+
- `default`
66+
- Entry point pointing toward a code cell output renderer, [see here](use/format/cutomise) for details.
67+
* - `nb_render_text_lexer`
68+
- `myst-ansi`
69+
- pygments lexer for rendering text outputs, [see here](use/format/ansi) for details.
70+
* - `nb_render_key`
71+
- `render`
72+
- The top-level cell metadata key, to store render control data, [see here](use/format/images) for examples.
73+
* - `nb_output_stderr`
74+
- `show`
75+
- One of 'show', 'remove', 'warn', 'error' or 'severe', [see here](use/format/stderr) for details.
76+
* - `nb_merge_streams`
77+
- `False`
78+
- If `True`, ensure all stdout / stderr output streams are merged into single outputs. This ensures deterministic outputs.
79+
`````

docs/use/execute.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ kernelspec:
1313
name: python3
1414
---
1515

16-
# Executing and caching your content
16+
# Execute and cache your content
1717

1818
MyST-NB can automatically run and cache notebooks contained in your project using [jupyter-cache].
1919
Notebooks can either be run each time the documentation is built, or cached locally so that re-runs occur only when code cells have changed.
@@ -63,7 +63,7 @@ execution_excludepatterns = ['list', 'of', '*patterns']
6363
Any file that matches one of the items in `execution_excludepatterns` will not be executed.
6464

6565
(execute/cache)=
66-
## Caching the notebook execution
66+
## Cache execution outputs
6767

6868
As mentioned above, you can **cache the results of executing a notebook page** by setting:
6969

@@ -123,7 +123,7 @@ This global value can also be overridden per notebook by adding this to you note
123123
```
124124

125125
(execute/allow_errors)=
126-
## Dealing with code that raises errors
126+
## Raise errors in code cells
127127

128128
In some cases, you may want to intentionally show code that doesn't work (e.g., to show the error message).
129129
You can achieve this at "three levels":

docs/use/formatting_outputs.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ kernelspec:
1212
---
1313

1414
(use/format)=
15-
# Formatting code outputs
15+
# Format code outputs
1616

1717
(use/format/priority)=
1818
## Render priority
@@ -42,8 +42,11 @@ nb_render_priority = {
4242
[](use/format/cutomise), for a more advanced means of customisation.
4343
:::
4444

45+
(use/format/stdout-stderr)=
46+
## stdout and stderr
47+
4548
(use/format/stderr)=
46-
## Removing stdout and stderr
49+
### Remove stdout or stderr
4750

4851
In some cases you may not wish to display stdout/stderr outputs in your final documentation,
4952
for example, if they are only for debugging purposes.
@@ -80,6 +83,23 @@ This can be set to:
8083
- `"remove-warn"`: remove all stderr, but log a warning to sphinx if any found
8184
- `"warn"`, `"error"` or `"severe"`: log to sphinx, at a certain level, if any found.
8285

86+
(use/format/group-stderr-stdout)=
87+
### Group stdout and stderr into single streams
88+
89+
Cells may print multiple things to `stdout` and `stderr`.
90+
For example, if a cell prints status updates throughout its execution, each of these is often printed to `stdout`.
91+
By default, these outputs may be split across multiple items, and will be rendered as separate "chunks" in your built documentation.
92+
93+
If you'd like each of the outputs in `stderr` and `stdout` to be merged into a single stream for each, use the following configuration:
94+
95+
```python
96+
nb_merge_streams = True
97+
```
98+
99+
This will ensure that all `stderr` and `stdout` outputs are merged into a single group.
100+
This also makes cell outputs more deterministic.
101+
Normally, slight differences in timing may result in different orders of `stderr` and `stdout` in the cell output, while this setting will sort them properly.
102+
83103
(use/format/images)=
84104
## Images
85105

docs/use/glue.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ kernelspec:
1313

1414
(glue)=
1515

16-
# Inserting variables into pages with `glue`
16+
# Insert variables into pages with `glue`
1717

1818
You often wish to run analyses in one notebook and insert them into your
1919
documents text elsewhere. For example, if you'd like to include a figure,

docs/use/hiding.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ kernelspec:
1111
name: python3
1212
---
1313

14-
# Hiding cell contents
14+
# Hide cell contents
1515

1616
You can use Jupyter Notebook **cell tags** to control some of the behavior of
1717
the rendered notebook. This uses the [**`sphinx-togglebutton`**](https://sphinx-togglebutton.readthedocs.io/en/latest/)
@@ -22,7 +22,7 @@ package to add a little button that toggles the visibility of content.[^download
2222

2323
(use/hiding/code)=
2424

25-
## Hiding code cells
25+
## Hide code cells
2626

2727
You can use **cell tags** to control the content hidden with code cells.
2828
Add the following tags to a cell's metadata to control
@@ -75,7 +75,7 @@ points =ax.scatter(*data, c=data[0], s=data[0])
7575

7676
(use/hiding/markdown)=
7777

78-
## Hiding markdown cells
78+
## Hide markdown cells
7979

8080
There are two ways to hide markdown cells. First, **you can add the `hide-input`**
8181
cell metadata. This triggers the same hiding behavior described above for
@@ -132,7 +132,7 @@ with `#`. If you'd like to use headings, do one of the following:
132132

133133
(use/removing)=
134134

135-
## Removing parts of cells
135+
## Remove parts of cells
136136

137137
Sometimes, you want to entirely remove parts of a cell so that it doesn't make it
138138
into the output at all. To do this, you can use the same tag pattern described above,

docs/use/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ execute
1212
hiding
1313
formatting_outputs
1414
glue
15+
config-reference
1516
```

docs/use/myst.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,25 @@ source_suffix = {
5252
'.myst': 'myst-nb',
5353
}
5454
```
55+
56+
(myst/error-reporting)=
57+
58+
## Error reporting in Sphinx
59+
60+
When Sphinx encounters and error or raises a warning, it will print the location and source file of the text that generated that error.
61+
This works slightly differently depending on whether you use markdown files or Jupyter Notebook files.
62+
63+
For markdown (`.md`) files, Sphinx will correctly report the line number that the error or warning is associated with:
64+
65+
```
66+
source/path:4: (WARNING/2) Duplicate reference definition: abc
67+
```
68+
69+
For Jupyter Notebook (`.ipynb`) files, these errors also correspond to a cell index.
70+
To allow for this, we use a special format of line number corresponding to: `<CELL_INDEX> * 10000 + LINE_NUMBER`.
71+
72+
For example, the following error corresponds to **Cell 1, line 4**:
73+
74+
```
75+
source/path:10004: (WARNING/2) Duplicate reference definition: abc
76+
```

docs/use/start.md

Lines changed: 13 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
# Get started
22

33
This section covers how to get started with the `MyST-NB` Sphinx extension.
4-
The Sphinx extension allows you to read markdown (`.md`) and Jupyter Notebook (`.ipynb`)
5-
files into your Sphinx site. It also enables you to write [MyST Markdown](myst.md)
6-
in your pages.
4+
The Sphinx extension allows you to read markdown (`.md`) and Jupyter Notebook (`.ipynb`) files into your Sphinx site.
5+
It also enables you to write [MyST Markdown](myst.md) in your pages.
76

8-
## Install and activate
9-
10-
To install `myst-nb`, do the following:
7+
To get started with the extension, follow these steps.
118

129
* **Install** `myst-nb` with the following command:
1310

14-
```bash
15-
pip install myst-nb
11+
```console
12+
$ pip install myst-nb
1613
```
1714

1815
* **Activate** the `myst_nb` extension in your Sphinx site by adding it to your list of
@@ -25,94 +22,15 @@ To install `myst-nb`, do the following:
2522
]
2623
```
2724

28-
Once you do this, MyST-NB will now parse both markdown (`.md`), Jupyter notebooks (`.ipynb`), and even [text-based Notebooks](markdown.md) (`.md`) into your Sphinx site
29-
(see also [custom notebook formats](examples/custom_formats)).
30-
31-
(start/error-reporting)=
32-
33-
## Sphinx Error Reporting
34-
35-
For `.md` files, sphinx will correctly report the line number that the error or warning is associated with:
36-
37-
```
38-
source/path:4: (WARNING/2) Duplicate reference definition: abc
39-
```
40-
41-
For `.ipynb` files, these errors also correspond to a cell index.
42-
To allow for this, we use a special format of line number corresponding to: `<CELL_INDEX> * 10000 + LINE_NUMBER`, for example:
43-
44-
```
45-
source/path:10004: (WARNING/2) Duplicate reference definition: abc
46-
```
47-
48-
(start/config-options)=
49-
50-
## MyST-NB configuration options
51-
52-
The MyST-NB parser derives from {ref}`the base MyST-Parser <myst:intro/get-started>`, and so all the same configuration options are available.
53-
See the {ref}`MyST configuration options <myst:sphinx/config-options>` for the full set of options.
54-
55-
MyST-NB then adds some additional configuration, specific to notebooks.
56-
Firstly for execution:
57-
58-
`````{list-table}
59-
:header-rows: 1
25+
* **Add MyST and notebook content** to your documentation's source files.
26+
Sphinx will now be able to parse **markdown files** written in [MyST Markdown](https://myst-parser.readthedocs.io), Jupyter Notebooks (ending in `.ipynb`), and [Jupyter Notebooks written in plain-text with MyST markdown](markdown.md).
27+
Make sure to include paths to your content in a Sphinx `toctree` directive!
6028

61-
* - Option
62-
- Default
63-
- Description
64-
* - `jupyter_cache`
65-
- ""
66-
- Path to jupyter_cache, [see here](execute/cache) for details.
67-
* - `execution_excludepatterns`
68-
- ()
69-
- Exclude certain file patterns from execution, [see here](execute/config) for details.
70-
* - `jupyter_execute_notebooks`
71-
- "auto"
72-
- The logic for executing notebooks, [see here](execute/config) for details.
73-
* - `execution_in_temp`
74-
- `False`
75-
- If `True`, then a temporary directory will be created and used as the command working directory (cwd), if `False` then the notebook's parent directory will be the cwd.
76-
* - `execution_allow_errors`
77-
- `False`
78-
- If `False`, when a code cell raises an error the execution is stopped, if `True` then all cells are always run.
79-
This can also be overridden by metadata in a notebook, [see here](execute/allow_errors) for details.
80-
* - `execution_timeout`
81-
- 30
82-
- The maximum time (in seconds) each notebook cell is allowed to run.
83-
This can also be overridden by metadata in a notebook, [see here](execute/timeout) for details.
84-
* - `execution_show_tb`
85-
- `False`
86-
- Show failed notebook tracebacks in stdout (in addition to writing to file).
87-
`````
29+
* **Build your documentation**. MyST-NB will now parse any markdown (`.md`), Jupyter notebooks (`.ipynb`), and [text-based Notebooks](markdown.md) (`.md`) into your Sphinx site, and include them in the outputs.
8830

89-
Then for parsing and output rendering:
31+
## Next steps
9032

91-
`````{list-table}
92-
:header-rows: 1
33+
There is a lot more that you can do with MyST-NB.
34+
For example, you can define [custom text-based notebook formats](examples/custom_formats), [execute and cache notebook content](execute.md), and [format cell outputs](formatting_outputs.md).
9335

94-
* - Option
95-
- Default
96-
- Description
97-
* - `nb_custom_formats`
98-
- `{}`
99-
- Define custom functions for conversion of files to notebooks, [see here](examples/custom_formats) for details.
100-
* - `nb_render_priority`
101-
- `{}`
102-
- Dict override for MIME type render priority, [see here](use/format/priority) for details.
103-
* - `nb_render_plugin`
104-
- `default`
105-
- Entry point pointing toward a code cell output renderer, [see here](use/format/cutomise) for details.
106-
* - `nb_render_text_lexer`
107-
- `myst-ansi`
108-
- pygments lexer for rendering text outputs, [see here](use/format/ansi) for details.
109-
* - `nb_render_key`
110-
- `render`
111-
- The top-level cell metadata key, to store render control data, [see here](use/format/images) for examples.
112-
* - `nb_output_stderr`
113-
- `show`
114-
- One of 'show', 'remove', 'warn', 'error' or 'severe', [see here](use/format/stderr) for details.
115-
* - `nb_merge_streams`
116-
- `False`
117-
- If `True`, ensure all stdout / stderr output streams are merged into single outputs. This ensures deterministic outputs.
118-
`````
36+
Check out the sections to the left under [Using with Sphinx](index.md) for more information.

0 commit comments

Comments
 (0)