|
26 | 26 | # https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration |
27 | 27 |
|
28 | 28 | extensions = [ |
29 | | - 'autoapi.extension' |
| 29 | + 'autoapi.extension', |
| 30 | + 'sphinx.ext.doctest', |
30 | 31 | ] |
31 | 32 |
|
32 | 33 | autoapi_dirs = ['../../src'] |
33 | 34 |
|
| 35 | +# -- doctest configuration --------------------------------------------------- |
| 36 | +# The examples in the narrative docs are executable doctests, run with |
| 37 | +# ``sphinx-build -b doctest`` (``make doctest``). ELLIPSIS lets the |
| 38 | +# non-deterministic ``Took: ...`` timing lines match; NORMALIZE_WHITESPACE makes |
| 39 | +# the DataFrame/table reprs robust to incidental spacing differences. |
| 40 | +import doctest as _doctest |
| 41 | + |
| 42 | +doctest_default_flags = _doctest.ELLIPSIS | _doctest.NORMALIZE_WHITESPACE |
| 43 | + |
| 44 | +# Run once before every doctest group: import the libraries, route raffalib's |
| 45 | +# logging output to stdout so doctest can capture it (mirroring |
| 46 | +# ``create_logger(rich=False, fmt="{message}")``), and pin the table-rendering |
| 47 | +# width so the captured reprs are deterministic. |
| 48 | +doctest_global_setup = """ |
| 49 | +import logging |
| 50 | +import numpy as np |
| 51 | +import pandas as pd |
| 52 | +import polars as pl |
| 53 | +import polars.selectors as cs |
| 54 | +import raffalib |
| 55 | +import raffalib.pandas |
| 56 | +import raffalib.polars |
| 57 | +
|
| 58 | +
|
| 59 | +class _DoctestLogHandler(logging.Handler): |
| 60 | + def emit(self, record): |
| 61 | + print(self.format(record)) |
| 62 | +
|
| 63 | +
|
| 64 | +_handler = _DoctestLogHandler() |
| 65 | +_handler.setFormatter(logging.Formatter("%(message)s")) |
| 66 | +_raffalogger = logging.getLogger("raffalib") |
| 67 | +_raffalogger.handlers = [_handler] |
| 68 | +_raffalogger.setLevel(logging.INFO) |
| 69 | +_raffalogger.propagate = False |
| 70 | +
|
| 71 | +pd.set_option("display.max_columns", None) |
| 72 | +pd.set_option("display.width", 200) |
| 73 | +pl.Config(thousands_separator=",", tbl_cols=-1, tbl_width_chars=200) |
| 74 | +""" |
| 75 | + |
34 | 76 | # Document the class docstring and the __init__ docstring together. |
35 | 77 | autoapi_python_class_content = "both" |
36 | 78 |
|
|
0 commit comments