Skip to content

Commit 7906307

Browse files
authored
Add sphinx extension myst-nb to enable writing executable Markdown notebooks (#3379)
* Add sphinx extension myst-nb and remove myst-parser * Exclude .ipynb and .py files generated by sphinx-gallery * Change install.md to be a notebook format and insert the output image into the document * Split the test script into two separate cells
1 parent ce8e8eb commit 7906307

File tree

5 files changed

+30
-7
lines changed

5 files changed

+30
-7
lines changed

.github/workflows/ci_docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ jobs:
107107
build
108108
make
109109
pip
110-
myst-parser
110+
myst-nb
111111
panel
112112
sphinx
113113
sphinx-autodoc-typehints

ci/requirements/docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ dependencies:
2222
- make
2323
- pip
2424
# Dev dependencies (building documentation)
25-
- myst-parser
25+
- myst-nb
2626
- panel
2727
- sphinx
2828
- sphinx-autodoc-typehints

doc/conf.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
)
2525

2626
extensions = [
27-
"myst_parser",
27+
"myst_nb",
2828
"sphinx.ext.autodoc",
2929
"sphinx.ext.autosummary",
3030
"sphinx.ext.coverage",
@@ -153,7 +153,21 @@
153153

154154
# Sphinx project configuration
155155
templates_path = ["_templates"]
156-
exclude_patterns = ["_build", "**.ipynb_checkpoints"]
156+
exclude_patterns = [
157+
"_build",
158+
"**.ipynb_checkpoints",
159+
# Workaround from https://github.com/executablebooks/MyST-NB/issues/363 to prevent
160+
# myst-nb from parsing the .ipynb and .py files generated by sphinx-gallery.
161+
"gallery/**.ipynb",
162+
"tutorials/**.ipynb",
163+
"get_started/**.ipynb",
164+
"projections/**.ipynb",
165+
"gallery/**.py",
166+
"tutorials/**.py",
167+
"get_started/**.py",
168+
"projections/**.py",
169+
]
170+
157171
source_suffix = ".rst"
158172
needs_sphinx = "1.8"
159173
# The encoding of source files.

doc/install.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
---
2+
file_format: mystnb
3+
---
4+
15
# Installing
26

37
## Quickstart
@@ -233,16 +237,21 @@ from Python.
233237
To ensure that PyGMT and its dependencies are installed correctly, run the following
234238
in your Python interpreter:
235239

236-
```python
240+
```{code-cell} ipython
241+
---
242+
tags: [hide-output]
243+
---
244+
237245
import pygmt
238246
pygmt.show_versions()
247+
```
239248

249+
```{code-cell} ipython
240250
fig = pygmt.Figure()
241251
fig.coast(projection="N15c", region="g", frame=True, land="tan", water="lightblue")
242252
fig.text(position="MC", text="PyGMT", font="80p,Helvetica-Bold,red@75")
243253
fig.show()
244254
```
245-
![pygmt-get-started](https://github.com/GenericMappingTools/pygmt/assets/3974108/f7f51484-8640-4b58-ae5b-6c71e7150f7a){.align-center width="70%"}
246255

247256
You should see a global map with land and water masses colored in tan and lightblue
248257
respectively. On top, there should be the semi-transparent text "PyGMT". If the

environment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ dependencies:
3434
- pytest-doctestplus
3535
- pytest-mpl
3636
# Dev dependencies (building documentation)
37-
- myst-parser
37+
- myst-nb
3838
- panel
3939
- sphinx
4040
- sphinx-autodoc-typehints

0 commit comments

Comments
 (0)