|
18 | 18 | import importlib
|
19 | 19 | import logging
|
20 | 20 | import warnings
|
| 21 | + |
21 | 22 | from sphinx.ext.autosummary import _import_by_name
|
| 23 | +from numpydoc.docscrape import NumpyDocString |
| 24 | +from numpydoc.docscrape_sphinx import SphinxDocString |
22 | 25 |
|
23 | 26 | logger = logging.getLogger(__name__)
|
24 | 27 |
|
|
49 | 52 |
|
50 | 53 | ])
|
51 | 54 |
|
52 |
| -# numpydoc is available in the sphinxext directory, and can't be imported |
53 |
| -# until sphinxext is available in the Python path |
54 |
| -from numpydoc.docscrape import NumpyDocString |
55 |
| - |
56 | 55 | # -- General configuration -----------------------------------------------
|
57 | 56 |
|
58 | 57 | # Add any Sphinx extension module names here, as strings. They can be
|
|
64 | 63 | 'sphinx.ext.doctest',
|
65 | 64 | 'sphinx.ext.extlinks',
|
66 | 65 | 'sphinx.ext.todo',
|
67 |
| - 'numpydoc', |
| 66 | + 'numpydoc', # handle NumPy documentation formatted docstrings |
68 | 67 | 'IPython.sphinxext.ipython_directive',
|
69 | 68 | 'IPython.sphinxext.ipython_console_highlighting',
|
70 | 69 | 'matplotlib.sphinxext.plot_directive',
|
|
91 | 90 | if any(re.match(r"\s*api\s*", l) for l in index_rst_lines):
|
92 | 91 | autosummary_generate = True
|
93 | 92 |
|
94 |
| -# numpydoc |
95 |
| -# for now use old parameter listing (styling + **kwargs problem) |
96 |
| -numpydoc_use_blockquotes = True |
97 |
| -# use member listing for attributes |
98 |
| -numpydoc_attributes_as_param_list = False |
99 |
| - |
100 | 93 | # matplotlib plot directive
|
101 | 94 | plot_include_source = True
|
102 | 95 | plot_formats = [("png", 90)]
|
|
411 | 404 | ]
|
412 | 405 |
|
413 | 406 |
|
| 407 | +def sphinxdocstring_str(self, indent=0, func_role="obj"): |
| 408 | + # Pandas displays Attributes section in style like Methods section |
| 409 | + |
| 410 | + # Function is copy of `SphinxDocString.__str__` |
| 411 | + ns = { |
| 412 | + 'signature': self._str_signature(), |
| 413 | + 'index': self._str_index(), |
| 414 | + 'summary': self._str_summary(), |
| 415 | + 'extended_summary': self._str_extended_summary(), |
| 416 | + 'parameters': self._str_param_list('Parameters'), |
| 417 | + 'returns': self._str_returns('Returns'), |
| 418 | + 'yields': self._str_returns('Yields'), |
| 419 | + 'other_parameters': self._str_param_list('Other Parameters'), |
| 420 | + 'raises': self._str_param_list('Raises'), |
| 421 | + 'warns': self._str_param_list('Warns'), |
| 422 | + 'warnings': self._str_warnings(), |
| 423 | + 'see_also': self._str_see_also(func_role), |
| 424 | + 'notes': self._str_section('Notes'), |
| 425 | + 'references': self._str_references(), |
| 426 | + 'examples': self._str_examples(), |
| 427 | + # Replaced `self._str_param_list('Attributes', fake_autosummary=True)` |
| 428 | + # with `self._str_member_list('Attributes')` |
| 429 | + 'attributes': self._str_member_list('Attributes'), |
| 430 | + 'methods': self._str_member_list('Methods'), |
| 431 | + } |
| 432 | + ns = {k: '\n'.join(v) for k, v in ns.items()} |
| 433 | + |
| 434 | + rendered = self.template.render(**ns) |
| 435 | + return '\n'.join(self._str_indent(rendered.split('\n'), indent)) |
| 436 | + |
| 437 | + |
| 438 | +SphinxDocString.__str__ = sphinxdocstring_str |
| 439 | + |
| 440 | + |
| 441 | +# Fix "WARNING: Inline strong start-string without end-string." |
| 442 | +# PR #155 "Escape the * in *args and **kwargs" from numpydoc |
| 443 | +# Can be removed after PR merges in v0.9.0 |
| 444 | +def decorate_process_param(func): |
| 445 | + def _escape_args_and_kwargs(name): |
| 446 | + if name[:2] == '**': |
| 447 | + return r'\*\*' + name[2:] |
| 448 | + elif name[:1] == '*': |
| 449 | + return r'\*' + name[1:] |
| 450 | + else: |
| 451 | + return name |
| 452 | + |
| 453 | + def func_wrapper(self, param, desc, fake_autosummary): |
| 454 | + param = _escape_args_and_kwargs(param.strip()) |
| 455 | + return func(self, param, desc, fake_autosummary) |
| 456 | + |
| 457 | + return func_wrapper |
| 458 | + |
| 459 | + |
| 460 | +func = SphinxDocString._process_param |
| 461 | +SphinxDocString._process_param = decorate_process_param(func) |
| 462 | + |
414 | 463 | # Add custom Documenter to handle attributes/methods of an AccessorProperty
|
415 | 464 | # eg pandas.Series.str and pandas.Series.dt (see GH9322)
|
416 | 465 |
|
|
0 commit comments