|
16 | 16 | import re
|
17 | 17 | import inspect
|
18 | 18 | import importlib
|
| 19 | +from sphinx.ext.autosummary import _import_by_name |
19 | 20 | import warnings
|
20 | 21 |
|
21 | 22 |
|
|
47 | 48 |
|
48 | 49 | ])
|
49 | 50 |
|
| 51 | +# numpydoc is available in the sphinxext directory, and can't be imported |
| 52 | +# until sphinxext is available in the Python path |
| 53 | +from numpydoc.docscrape import NumpyDocString |
| 54 | + |
50 | 55 | # -- General configuration -----------------------------------------------
|
51 | 56 |
|
52 | 57 | # Add any Sphinx extension module names here, as strings. They can be
|
@@ -506,9 +511,27 @@ def _replace_pandas_items(self, display_name, sig, summary, real_name):
|
506 | 511 | summary = 'Series plotting accessor and method'
|
507 | 512 | return (display_name, sig, summary, real_name)
|
508 | 513 |
|
| 514 | + @staticmethod |
| 515 | + def _is_deprecated(real_name): |
| 516 | + try: |
| 517 | + obj, parent, modname = _import_by_name(real_name) |
| 518 | + except ImportError: |
| 519 | + return False |
| 520 | + doc = NumpyDocString(obj.__doc__ or '') |
| 521 | + summary = ''.join(doc['Summary'] + doc['Extended Summary']) |
| 522 | + return '.. deprecated::' in summary |
| 523 | + |
| 524 | + def _add_deprecation_prefixes(self, items): |
| 525 | + for item in items: |
| 526 | + display_name, sig, summary, real_name = item |
| 527 | + if self._is_deprecated(real_name): |
| 528 | + summary = '(DEPRECATED) %s' % summary |
| 529 | + yield display_name, sig, summary, real_name |
| 530 | + |
509 | 531 | def get_items(self, names):
|
510 | 532 | items = Autosummary.get_items(self, names)
|
511 | 533 | items = [self._replace_pandas_items(*item) for item in items]
|
| 534 | + items = list(self._add_deprecation_prefixes(items)) |
512 | 535 | return items
|
513 | 536 |
|
514 | 537 |
|
|
0 commit comments