Skip to content

Conversation

weiji14
Copy link

@weiji14 weiji14 commented Jun 17, 2025

Fixes "WARNING: doctest_block node not implemented". Re-using the same code from literal_block here:

def visit_literal_block(self, node):
self.push_myst_node({"type": "code", "value": str(node.children[0])}, node)
return SkipChildren

For example, for my PR at weiji14/cog3pio#35 where I'm trying to render a NumPy-style docstring like this:

    """
    Examples
    --------
    Read a GeoTIFF from a HTTP url into a numpy.ndarray:

    >>> from cog3pio import read_geotiff
    ...
    >>> array = read_geotiff("https://github.com/pka/georaster/raw/v0.2.0/data/tiff/float32.tif")
    >>> array.shape
    (1, 20, 20)
    """

The rendering should look something like this:

image

Not sure yet how to add syntax highlighting, open to tips!

Fixes `WARNING: `doctest_block` node not implemented`.
weiji14 added a commit to weiji14/cog3pio that referenced this pull request Jun 17, 2025
Figured out how to get doctest_block nodes working with a one-line change at jupyter-book/sphinx-ext-mystmd#2. Partially reverts 5d0ff56.
weiji14 added a commit to weiji14/cog3pio that referenced this pull request Jun 17, 2025
* ➕ Add jupyter-book

Create beautiful, publication-quality books and documents from computational content!

* 🌱 Initialize Jupyter Book 2 with MyST

Starting with a minimal Jupyter Book initialized with `jupyter book init`. Changed the `myst.yml` to use a proper title and description.

* 📝 Use sphinx-ext-mystmd to generate autodoc API reference

Move myst.yml to docs/ folder, and create a Sphinx configuration file at docs/conf.py. Docs are now built using `cd docs/ && sphinx-build --builder myst . _build/myst-asts && jupyter book start`.

Extensions used:
- `myst_parser` - Because the index page and API docs page in MyST instead of ReST
- `sphinx_ext_mystmd` - Allows Sphinx to build an `api.myst.json` file that can then be used by MyST-MD
- `sphinx.ext.autodoc` - Regular Sphinx extension to pull in documentation from docstrings
- `sphinx.ext.napolean` - Support for NumPy style docstrings

Note: needed to use {eval-rst} directive in API docs because https://myst-parser.readthedocs.io/en/latest/syntax/code_and_apis.html#sphinx-ext-autodoc says `sphinx.ext.autodoc` generates ReST only, and I didn't want to use `sphinx-autodoc2`.

* 💬 Indent doctest examples to render them as code blocks

Need to add a sentence, and then indent the code block by 4 spaces to it into a literal block (couldn't figure out syntax highlighting yet). Also taking the chance to properly update the docstrings, mentioning that read_geotiff only supports float32, and documenting the xy_coords method with more details.

* 💚 Don't run rustdoc tests on pyo3 modules

Fixes error with `cargo test` trying to run doctests in src/python/adapters.rs that are meant for Python, not Rust. Xref https://users.rust-lang.org/t/disabling-rustdoc-tests-for-module/50110/2

* 🎨 Use sphinx-ext-mystmd patch to unindent doctest blocks

Figured out how to get doctest_block nodes working with a one-line change at jupyter-book/sphinx-ext-mystmd#2. Partially reverts 5d0ff56.
weiji14 added a commit to weiji14/cog3pio that referenced this pull request Jun 23, 2025
Need to use an official PyPI released version in pyproject.toml, but still installing from jupyter-book/sphinx-ext-mystmd#2 in the docs/.readthedocs.yml file.
weiji14 added a commit to weiji14/cog3pio that referenced this pull request Jun 23, 2025
Need to use an official PyPI released version in pyproject.toml, but still installing from jupyter-book/sphinx-ext-mystmd#2 in the docs/.readthedocs.yml file.
weiji14 added a commit to weiji14/cog3pio that referenced this pull request Jun 23, 2025
Need to use an official PyPI released version in pyproject.toml, but still installing from jupyter-book/sphinx-ext-mystmd#2 in the docs/.readthedocs.yml file.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant