Skip to content

Commit 21d0eeb

Browse files
authored
Use Sphinx's mocking for dependencies in the docs build (#616)
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`.
2 parents 7c4dcf5 + b8c7eec commit 21d0eeb

1 file changed

Lines changed: 3 additions & 12 deletions

File tree

‎docs/conf.py‎

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,9 @@
2222

2323
sys.path.insert(0, os.path.abspath("../src"))
2424

25-
# For dependencies
26-
from unittest.mock import MagicMock
27-
28-
29-
class Mock(MagicMock):
30-
@classmethod
31-
def __getattr__(cls, name):
32-
return MagicMock()
33-
34-
35-
MOCK_MODULES = ["numpy", "matplotlib", "matplotlib.pyplot", "pandas", "scipy"]
36-
sys.modules.update((mod_name, Mock()) for mod_name in MOCK_MODULES)
25+
# Heavy dependencies aren't installed for the docs build. Sphinx mocks them, and
26+
# shows mocked names in signatures (e.g. `pandas.DataFrame`).
27+
autodoc_mock_imports = ["numpy", "matplotlib", "pandas", "scipy"]
3728

3829
# -- General configuration ------------------------------------------------
3930

0 commit comments

Comments
 (0)