Skip to content

Use Sphinx's mocking for dependencies in the docs build - #616

Merged
tompollard merged 1 commit into
mainfrom
fix/docs-mock-annotation
Nov 4, 2026
Merged

tompollard merged 1 commit into
mainfrom
fix/docs-mock-annotation

Conversation

@tompollard

Copy link
Copy Markdown
Member

The API docs show Record.to_dataframe() as returning <MagicMock id='...'>, because docs/conf.py replaced NumPy, pandas, SciPy and Matplotlib with hand-written MagicMock modules, and the -> pd.DataFrame annotation rendered as the mock's repr.

This switches to Sphinx's built-in autodoc_mock_imports, which shows mocked names properly, so the signature now reads to_dataframe() → pandas.DataFrame.

I compared the generated HTML with main (numpydoc 1.7.0 and 1.11.0): apart from that signature in io.html and wfdb.html, every page is identical. The docs build passes with -W.

The hand-written MagicMock modules made type annotations render as
their repr, so Record.to_dataframe() was shown as returning
<MagicMock id='...'>. autodoc_mock_imports shows the mocked name
(pandas.DataFrame) instead. The rest of the generated HTML is unchanged.
@tompollard
tompollard force-pushed the fix/docs-mock-annotation branch from 7715b82 to b8c7eec Compare October 31, 2026 19:38
tompollard added a commit that referenced this pull request Nov 1, 2026
As discussed in #606: each change now adds its own file in
`changelog.d/` instead of editing `docs/changes.rst`, so pull requests
no longer conflict on the changelog.

- Fragments are plain `.rst` files named after the change (for example
`rr2ann-fixes.rst`), in the same bold-heading format as now.
`changelog.d/README.rst` explains this.
- At release time, `uv run towncrier build --version X.Y.Z --date "Mon
YYYY"` adds a `Version X.Y.Z (Mon YYYY)` section to `docs/changes.rst`
and deletes the fragments. Entries are sorted by file name.
- The 25 existing unreleased entries are moved into `changelog.d/`
unchanged. I checked that `towncrier build --draft` reproduces them
exactly, and ran a real build on a copy: the docs build passes with `-W`
both before and after.
- `towncrier` is pinned in the `dev` group, like Ruff. AGENTS.md and
DEVELOPING.md are updated.

One trade-off: the unreleased changes no longer show on the docs site
until a release. If you'd like them there, `sphinxcontrib-towncrier` can
render a draft section, but that touches `docs/conf.py`, so I'd do it
after #616.

#619 and #583 add entries to `docs/changes.rst`, so they'd need to move
them into a fragment after this is merged (or the other way round,
whichever goes in first).

@lukepayyapilli lukepayyapilli left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Tom, checked b8c7eec9 locally merged with main:

  • Docs build: make -C docs html SPHINXOPTS="-W --keep-going" with --only-group docs passes on both main and the merged tree, with no warnings.
  • Output: comparing the generated HTML with main, only io.html and wfdb.html change, each in the to_dataframe signature (<MagicMock id='...'> becomes pandas.DataFrame). The only other change is that searchindex.js drops the magicmock and id terms, so searching for them no longer finds the old signature. No MagicMock repr is left anywhere in the build.

@tompollard
tompollard merged commit 21d0eeb into main Nov 4, 2026
18 checks passed
@tompollard
tompollard deleted the fix/docs-mock-annotation branch November 4, 2026 17:25
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.

2 participants