Skip to content

Commit 7b0a03f

Browse files
committed
ENH: Just use obj
1 parent afdb573 commit 7b0a03f

File tree

10 files changed

+117
-112
lines changed

10 files changed

+117
-112
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@
88
*.swo
99
build
1010
dist
11+
doc/_build

doc/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ endif
1515
# Internal variables.
1616
PAPEROPT_a4 = -D latex_paper_size=a4
1717
PAPEROPT_letter = -D latex_paper_size=letter
18-
ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
18+
ALLSPHINXOPTS = -nWT --keep-going -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
1919
# the i18n builder cannot share the environment and doctrees with the others
2020
I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
2121

doc/conf.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@
8282
release = numpydoc.__version__
8383
version = re.sub(r'(\d+\.\d+)\.\d+(.*)', r'\1\2', numpydoc.__version__)
8484
version = re.sub(r'(\.dev\d+).*?$', r'\1', version)
85+
numpydoc_xref_param_type = True
86+
numpydoc_xref_ignore = {'optional'}
8587

8688
# The language for content autogenerated by Sphinx. Refer to documentation
8789
# for a list of supported languages.
@@ -269,5 +271,6 @@
269271
# Example configuration for intersphinx: refer to the Python standard library.
270272
intersphinx_mapping = {
271273
'python': ('http://docs.python.org/', None),
272-
'scikitlearn': ('http://scikit-learn.org/stable/', None),
274+
'numpy': ('https://www.numpy.org/devdocs', None),
275+
'sklearn': ('http://scikit-learn.org/stable/', None),
273276
}

doc/example.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ def foo(var1, var2, long_var_name='hi'):
7878
7979
See Also
8080
--------
81-
otherfunc : relationship (optional)
82-
newfunc : Relationship (optional), which could be fairly long, in which
83-
case the line wraps here.
84-
thirdfunc, fourthfunc, fifthfunc
81+
numpy.array : relationship (optional)
82+
numpy.ndarray : Relationship (optional), which could be fairly long, in
83+
which case the line wraps here.
84+
numpy.dot, numpy.linalg.norm, numpy.eye
8585
8686
Notes
8787
-----

doc/install.rst

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -65,26 +65,21 @@ numpydoc_xref_aliases : dict
6565
intersphinx_mapping = {
6666
'python': ('https://docs.python.org/3/', None),
6767
'numpy': ('https://docs.scipy.org/doc/numpy', None),
68+
...
6869
}
6970

70-
A useful ``dict`` may look like the following::
71+
The default ``numpydoc_xref_aliases`` will supply some common ``Python``
72+
standard library and ``NumPy`` names for you. Then for your module, a useful
73+
``dict`` may look like the following (e.g., if you were documenting
74+
:mod:`sklearn.model_selection`)::
7175

7276
numpydoc_xref_aliases = {
73-
# python
74-
'sequence': ':term:`python:sequence`',
75-
'iterable': ':term:`python:iterable`',
76-
'string': 'str',
77-
# numpy
78-
'array': 'numpy.ndarray',
79-
'dtype': 'numpy.dtype',
80-
'ndarray': 'numpy.ndarray',
81-
'matrix': 'numpy.matrix',
82-
'array-like': ':term:`numpy:array_like`',
83-
'array_like': ':term:`numpy:array_like`',
77+
'LeaveOneOut': 'sklearn.model_selection.LeaveOneOut',
78+
...
8479
}
8580

86-
This option depends on the ``numpydoc_xref_param_type`` option
87-
being ``True``.
81+
This option depends on the ``numpydoc_xref_param_type`` option
82+
being ``True``.
8883
numpydoc_xref_ignore : set
8984
Words not to cross-reference. Most likely, these are common words
9085
used in parameter type descriptions that may be confused for

numpydoc/docscrape_sphinx.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from sphinx.jinja2glue import BuiltinTemplateLoader
1818

1919
from .docscrape import NumpyDocString, FunctionDoc, ClassDoc
20-
from .xref import make_xref_param_type
20+
from .xref import make_xref
2121

2222
if sys.version_info[0] >= 3:
2323
sixu = lambda s: s
@@ -84,7 +84,7 @@ def _str_returns(self, name='Returns'):
8484
for param in self[name]:
8585
param_type = param.type
8686
if param_type and self.xref_param_type:
87-
param_type = make_xref_param_type(
87+
param_type = make_xref(
8888
param_type,
8989
self.xref_aliases,
9090
self.xref_ignore)
@@ -226,7 +226,7 @@ def _str_param_list(self, name, fake_autosummary=False):
226226
if param_type:
227227
param_type = param.type
228228
if self.xref_param_type:
229-
param_type = make_xref_param_type(
229+
param_type = make_xref(
230230
param_type,
231231
self.xref_aliases,
232232
self.xref_ignore)

numpydoc/numpydoc.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
raise RuntimeError("Sphinx 1.0.1 or newer is required")
3838

3939
from .docscrape_sphinx import get_doc_object
40-
from .xref import xref_param_type_role
40+
from .xref import DEFAULT_LINKS
4141
from . import __version__
4242

4343
if sys.version_info[0] >= 3:
@@ -221,7 +221,7 @@ def setup(app, get_doc_object_=get_doc_object):
221221

222222
app.setup_extension('sphinx.ext.autosummary')
223223

224-
app.add_role('xref_param_type', xref_param_type_role)
224+
app.connect('builder-inited', update_config)
225225
app.connect('autodoc-process-docstring', mangle_docstrings)
226226
app.connect('autodoc-process-signature', mangle_signature)
227227
app.connect('doctree-read', relabel_references)
@@ -245,6 +245,14 @@ def setup(app, get_doc_object_=get_doc_object):
245245
'parallel_read_safe': True}
246246
return metadata
247247

248+
249+
def update_config(app):
250+
"""Update the configuration with default values."""
251+
for key, value in DEFAULT_LINKS.items():
252+
if key not in app.config.numpydoc_xref_aliases:
253+
app.config.numpydoc_xref_aliases[key] = value
254+
255+
248256
# ------------------------------------------------------------------------------
249257
# Docstring-mangling domains
250258
# ------------------------------------------------------------------------------

numpydoc/tests/test_docscrape.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
# -*- encoding:utf-8 -*-
22
from __future__ import division, absolute_import, print_function
33

4+
from collections import namedtuple
45
import re
56
import sys
67
import textwrap
78
import warnings
89

910
import jinja2
1011

12+
from numpydoc.numpydoc import update_config
1113
from numpydoc.docscrape import (
1214
NumpyDocString,
1315
FunctionDoc,
@@ -1389,7 +1391,7 @@ def test_autoclass():
13891391
List of integers
13901392
p4 : :class:`pandas.DataFrame`
13911393
A dataframe
1392-
p5 : sequence of int
1394+
p5 : sequence of `int`
13931395
A sequence
13941396
13951397
Returns
@@ -1405,37 +1407,39 @@ def test_autoclass():
14051407
14061408
:Parameters:
14071409
1408-
**p1** : :xref_param_type:`int`
1410+
**p1** : :class:`python:int`
14091411
Integer value
14101412
1411-
**p2** : :xref_param_type:`float`, optional
1413+
**p2** : :class:`python:float`, optional
14121414
Integer value
14131415
14141416
:Returns:
14151417
1416-
**out** : :xref_param_type:`array <numpy.ndarray>`
1418+
**out** : :obj:`array <numpy.ndarray>`
14171419
Numerical return value
14181420
14191421
14201422
:Other Parameters:
14211423
1422-
**p3** : :xref_param_type:`list`\[:xref_param_type:`int`]
1424+
**p3** : :class:`python:list`\[:class:`python:int`]
14231425
List of integers
14241426
14251427
**p4** : :class:`pandas.DataFrame`
14261428
A dataframe
14271429
1428-
**p5** : :term:`python:sequence` of :xref_param_type:`int`
1430+
**p5** : :obj:`python:sequence` of `int`
14291431
A sequence
14301432
"""
14311433

14321434

14331435
def test_xref():
14341436
xref_aliases = {
1435-
'sequence': ':term:`python:sequence`',
1436-
'iterable': ':term:`python:iterable`',
1437-
'array': 'numpy.ndarray',
1437+
'sequence': ':obj:`python:sequence`',
14381438
}
1439+
config = namedtuple('numpydoc_xref_aliases',
1440+
'numpydoc_xref_aliases')(xref_aliases)
1441+
app = namedtuple('config', 'config')(config)
1442+
update_config(app)
14391443

14401444
xref_ignore = {'of', 'default', 'optional'}
14411445

numpydoc/tests/test_xref.py

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# -*- encoding:utf-8 -*-
22
from __future__ import division, absolute_import, print_function
33

4-
from numpydoc.xref import make_xref_param_type
4+
from numpydoc.xref import make_xref
55

66
xref_aliases = {
77
# python
@@ -20,49 +20,49 @@
2020
# Comes mainly from numpy
2121
data = r"""
2222
(...) array_like, float, optional
23-
(...) :term:`numpy:array_like`, :xref_param_type:`float`, optional
23+
(...) :term:`numpy:array_like`, :obj:`float`, optional
2424
2525
(2,) ndarray
26-
(2,) :xref_param_type:`ndarray <numpy.ndarray>`
26+
(2,) :obj:`ndarray <numpy.ndarray>`
2727
2828
(...,M,N) array_like
2929
(...,M,N) :term:`numpy:array_like`
3030
3131
(..., M, N) array_like
32-
(..., :xref_param_type:`M`, :xref_param_type:`N`) :term:`numpy:array_like`
32+
(..., :obj:`M`, :obj:`N`) :term:`numpy:array_like`
3333
3434
(float, float), optional
35-
(:xref_param_type:`float`, :xref_param_type:`float`), optional
35+
(:obj:`float`, :obj:`float`), optional
3636
3737
1-D array or sequence
38-
1-D :xref_param_type:`array <numpy.ndarray>` or :term:`python:sequence`
38+
1-D :obj:`array <numpy.ndarray>` or :term:`python:sequence`
3939
4040
array of str or unicode-like
41-
:xref_param_type:`array <numpy.ndarray>` of :xref_param_type:`str` or unicode-like
41+
:obj:`array <numpy.ndarray>` of :obj:`str` or unicode-like
4242
4343
array_like of float
44-
:term:`numpy:array_like` of :xref_param_type:`float`
44+
:term:`numpy:array_like` of :obj:`float`
4545
4646
bool or callable
47-
:xref_param_type:`bool` or :xref_param_type:`callable`
47+
:obj:`bool` or :obj:`callable`
4848
4949
int in [0, 255]
50-
:xref_param_type:`int` in [0, 255]
50+
:obj:`int` in [0, 255]
5151
5252
int or None, optional
53-
:xref_param_type:`int` or :xref_param_type:`None`, optional
53+
:obj:`int` or :obj:`None`, optional
5454
5555
list of str or array_like
56-
:xref_param_type:`list` of :xref_param_type:`str` or :term:`numpy:array_like`
56+
:obj:`list` of :obj:`str` or :term:`numpy:array_like`
5757
5858
sequence of array_like
5959
:term:`python:sequence` of :term:`numpy:array_like`
6060
6161
str or pathlib.Path
62-
:xref_param_type:`str` or :xref_param_type:`pathlib.Path`
62+
:obj:`str` or :obj:`pathlib.Path`
6363
6464
{'', string}, optional
65-
{'', :xref_param_type:`string <str>`}, optional
65+
{'', :obj:`string <str>`}, optional
6666
6767
{'C', 'F', 'A', or 'K'}, optional
6868
{'C', 'F', 'A', or 'K'}, optional
@@ -71,55 +71,55 @@
7171
{'linear', 'lower', 'higher', 'midpoint', 'nearest'}
7272
7373
{False, True, 'greedy', 'optimal'}
74-
{:xref_param_type:`False`, :xref_param_type:`True`, 'greedy', 'optimal'}
74+
{:obj:`False`, :obj:`True`, 'greedy', 'optimal'}
7575
7676
{{'begin', 1}, {'end', 0}}, {string, int}
77-
{{'begin', 1}, {'end', 0}}, {:xref_param_type:`string <str>`, :xref_param_type:`int`}
77+
{{'begin', 1}, {'end', 0}}, {:obj:`string <str>`, :obj:`int`}
7878
7979
callable f'(x,*args)
80-
:xref_param_type:`callable` f'(x,*args)
80+
:obj:`callable` f'(x,*args)
8181
8282
callable ``fhess(x, *args)``, optional
83-
:xref_param_type:`callable` ``fhess(x, *args)``, optional
83+
:obj:`callable` ``fhess(x, *args)``, optional
8484
8585
spmatrix (format: ``csr``, ``bsr``, ``dia`` or coo``)
86-
:xref_param_type:`spmatrix` (format: ``csr``, ``bsr``, ``dia`` or coo``)
86+
:obj:`spmatrix` (format: ``csr``, ``bsr``, ``dia`` or coo``)
8787
8888
:ref:`strftime <strftime-strptime-behavior>`
8989
:ref:`strftime <strftime-strptime-behavior>`
9090
9191
callable or :ref:`strftime <strftime-strptime-behavior>`
92-
:xref_param_type:`callable` or :ref:`strftime <strftime-strptime-behavior>`
92+
:obj:`callable` or :ref:`strftime <strftime-strptime-behavior>`
9393
9494
callable or :ref:`strftime behavior <strftime-strptime-behavior>`
95-
:xref_param_type:`callable` or :ref:`strftime behavior <strftime-strptime-behavior>`
95+
:obj:`callable` or :ref:`strftime behavior <strftime-strptime-behavior>`
9696
9797
list(int)
98-
:xref_param_type:`list`\(:xref_param_type:`int`)
98+
:obj:`list`\(:obj:`int`)
9999
100100
list[int]
101-
:xref_param_type:`list`\[:xref_param_type:`int`]
101+
:obj:`list`\[:obj:`int`]
102102
103103
dict(str, int)
104-
:xref_param_type:`dict`\(:xref_param_type:`str`, :xref_param_type:`int`)
104+
:obj:`dict`\(:obj:`str`, :obj:`int`)
105105
106106
dict[str, int]
107-
:xref_param_type:`dict`\[:xref_param_type:`str`, :xref_param_type:`int`]
107+
:obj:`dict`\[:obj:`str`, :obj:`int`]
108108
109109
tuple(float, float)
110-
:xref_param_type:`tuple`\(:xref_param_type:`float`, :xref_param_type:`float`)
110+
:obj:`tuple`\(:obj:`float`, :obj:`float`)
111111
112112
dict[tuple(str, str), int]
113-
:xref_param_type:`dict`\[:xref_param_type:`tuple`\(:xref_param_type:`str`, :xref_param_type:`str`), :xref_param_type:`int`]
113+
:obj:`dict`\[:obj:`tuple`\(:obj:`str`, :obj:`str`), :obj:`int`]
114114
""" # noqa: E501
115115

116116
xref_ignore = {'or', 'in', 'of', 'default', 'optional'}
117117

118118

119-
def test_make_xref_param_type():
119+
def test_make_xref():
120120
for s in data.strip().split('\n\n'):
121121
param_type, expected_result = s.split('\n')
122-
result = make_xref_param_type(
122+
result = make_xref(
123123
param_type,
124124
xref_aliases,
125125
xref_ignore

0 commit comments

Comments
 (0)