Skip to content

Commit 4c9698e

Browse files
committed
ENH: Just use obj
1 parent 807f4e0 commit 4c9698e

12 files changed

+136
-137
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

.travis.yml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
# After changing this file, check it on:
22
# http://lint.travis-ci.org/
33
language: python
4+
dist: xenial
45
sudo: false
5-
env:
6-
- SPHINX_SPEC="Sphinx==1.2.3"
7-
- SPHINX_SPEC="Sphinx"
86
matrix:
97
include:
10-
- python: 3.6
8+
- python: 3.7
9+
env: SPHINX_SPEC="==1.2.3" SPHINXOPTS=""
10+
- python: 3.7
1111
- python: 2.7
12-
env:
13-
- SPHINXOPTS='-W'
1412
cache:
1513
directories:
1614
- $HOME/.cache/pip
1715
before_install:
1816
- sudo apt-get install texlive texlive-latex-extra latexmk
1917
- pip install --upgrade pip setuptools # Upgrade pip and setuptools to get ones with `wheel` support
20-
- pip install pytest numpy matplotlib ${SPHINX_SPEC}
18+
- pip install pytest numpy matplotlib sphinx${SPHINX_SPEC}
2119
script:
2220
- |
2321
python setup.py sdist

doc/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33

44
# You can set these variables from the command line.
5-
SPHINXOPTS =
5+
SPHINXOPTS = -nWT --keep-going
66
SPHINXBUILD = sphinx-build
77
PAPER =
88
BUILDDIR = _build

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', 'type_without_description', 'BadException'}
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
@@ -70,26 +70,21 @@ numpydoc_xref_aliases : dict
7070
intersphinx_mapping = {
7171
'python': ('https://docs.python.org/3/', None),
7272
'numpy': ('https://docs.scipy.org/doc/numpy', None),
73+
...
7374
}
7475

75-
A useful ``dict`` may look like the following::
76+
The default ``numpydoc_xref_aliases`` will supply some common ``Python``
77+
standard library and ``NumPy`` names for you. Then for your module, a useful
78+
``dict`` may look like the following (e.g., if you were documenting
79+
:mod:`sklearn.model_selection`)::
7680

7781
numpydoc_xref_aliases = {
78-
# python
79-
'sequence': ':term:`python:sequence`',
80-
'iterable': ':term:`python:iterable`',
81-
'string': 'str',
82-
# numpy
83-
'array': 'numpy.ndarray',
84-
'dtype': 'numpy.dtype',
85-
'ndarray': 'numpy.ndarray',
86-
'matrix': 'numpy.matrix',
87-
'array-like': ':term:`numpy:array_like`',
88-
'array_like': ':term:`numpy:array_like`',
82+
'LeaveOneOut': 'sklearn.model_selection.LeaveOneOut',
83+
...
8984
}
9085

91-
This option depends on the ``numpydoc_xref_param_type`` option
92-
being ``True``.
86+
This option depends on the ``numpydoc_xref_param_type`` option
87+
being ``True``.
9388
numpydoc_xref_ignore : set
9489
Words not to cross-reference. Most likely, these are common words
9590
used in parameter type descriptions that may be confused for

numpydoc/docscrape_sphinx.py

Lines changed: 7 additions & 10 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
@@ -85,15 +85,15 @@ def _str_returns(self, name='Returns'):
8585
for param in self[name]:
8686
param_type = param.type
8787
if param_type and self.xref_param_type:
88-
param_type = make_xref_param_type(
88+
param_type = make_xref(
8989
param_type,
9090
self.xref_aliases,
9191
self.xref_ignore)
9292
if param.name:
9393
out += self._str_indent([named_fmt % (param.name.strip(),
9494
param_type)])
9595
else:
96-
out += self._str_indent([unnamed_fmt % param_type.strip()])
96+
out += self._str_indent([unnamed_fmt % param_type.strip()])
9797
if not param.desc:
9898
out += self._str_indent(['..'], 8)
9999
else:
@@ -168,10 +168,8 @@ def _process_param(self, param, desc, fake_autosummary):
168168

169169
prefix = getattr(self, '_name', '')
170170
if prefix:
171-
autosum_prefix = '~%s.' % prefix
172171
link_prefix = '%s.' % prefix
173172
else:
174-
autosum_prefix = ''
175173
link_prefix = ''
176174

177175
# Referenced object has a docstring
@@ -227,14 +225,13 @@ def _str_param_list(self, name, fake_autosummary=False):
227225
if param_type:
228226
param_type = param.type
229227
if self.xref_param_type:
230-
param_type = make_xref_param_type(
228+
param_type = make_xref(
231229
param_type,
232230
self.xref_aliases,
233231
self.xref_ignore)
234-
(??) out += self._str_indent(['%s : %s' % (display_param,
235-
(??) param.type)])
236-
(??) else:
237-
(??) out += self._str_indent([display_param])
232+
parts.append(param_type)
233+
out += self._str_indent([' : '.join(parts)])
234+
238235
if desc and self.use_blockquotes:
239236
out += ['']
240237
elif not desc:

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:
@@ -223,7 +223,7 @@ def setup(app, get_doc_object_=get_doc_object):
223223

224224
app.setup_extension('sphinx.ext.autosummary')
225225

226-
app.add_role('xref_param_type', xref_param_type_role)
226+
app.connect('builder-inited', update_config)
227227
app.connect('autodoc-process-docstring', mangle_docstrings)
228228
app.connect('autodoc-process-signature', mangle_signature)
229229
app.connect('doctree-read', relabel_references)
@@ -248,6 +248,14 @@ def setup(app, get_doc_object_=get_doc_object):
248248
'parallel_read_safe': True}
249249
return metadata
250250

251+
252+
def update_config(app):
253+
"""Update the configuration with default values."""
254+
for key, value in DEFAULT_LINKS.items():
255+
if key not in app.config.numpydoc_xref_aliases:
256+
app.config.numpydoc_xref_aliases[key] = value
257+
258+
251259
# ------------------------------------------------------------------------------
252260
# Docstring-mangling domains
253261
# ------------------------------------------------------------------------------

numpydoc/tests/test_docscrape.py

Lines changed: 19 additions & 19 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,
@@ -382,11 +384,11 @@ def _strip_blank_lines(s):
382384
return s
383385

384386

385-
def line_by_line_compare(a, b):
387+
def line_by_line_compare(a, b, n_lines=None):
386388
a = textwrap.dedent(a)
387389
b = textwrap.dedent(b)
388-
a = [l.rstrip() for l in _strip_blank_lines(a).split('\n')]
389-
b = [l.rstrip() for l in _strip_blank_lines(b).split('\n')]
390+
a = [l.rstrip() for l in _strip_blank_lines(a).split('\n')][:n_lines]
391+
b = [l.rstrip() for l in _strip_blank_lines(b).split('\n')][:n_lines]
390392
assert len(a) == len(b)
391393
for ii, (aa, bb) in enumerate(zip(a, b)):
392394
assert aa == bb
@@ -518,8 +520,7 @@ def test_yield_str():
518520
The number of bananas.
519521
int
520522
The number of unknowns.
521-
522-
.. index:: """)
523+
""")
523524

524525

525526
def test_receives_str():
@@ -537,8 +538,7 @@ def test_receives_str():
537538
The number of bananas.
538539
c : int
539540
The number of oranges.
540-
541-
.. index:: """)
541+
""")
542542

543543

544544
def test_no_index_in_str():
@@ -1200,8 +1200,6 @@ def test_class_members_doc():
12001200
b
12011201
c
12021202
1203-
.. index::
1204-
12051203
""")
12061204

12071205

@@ -1422,7 +1420,7 @@ def test_autoclass():
14221420
.. rubric:: Methods
14231421
14241422
1425-
''')
1423+
''', 5)
14261424

14271425

14281426
xref_doc_txt = """
@@ -1442,7 +1440,7 @@ def test_autoclass():
14421440
List of integers
14431441
p4 : :class:`pandas.DataFrame`
14441442
A dataframe
1445-
p5 : sequence of int
1443+
p5 : sequence of `int`
14461444
A sequence
14471445
14481446
Returns
@@ -1458,37 +1456,39 @@ def test_autoclass():
14581456
14591457
:Parameters:
14601458
1461-
**p1** : :xref_param_type:`int`
1459+
**p1** : :class:`python:int`
14621460
Integer value
14631461
1464-
**p2** : :xref_param_type:`float`, optional
1462+
**p2** : :class:`python:float`, optional
14651463
Integer value
14661464
14671465
:Returns:
14681466
1469-
**out** : :xref_param_type:`array <numpy.ndarray>`
1467+
**out** : :obj:`array <numpy.ndarray>`
14701468
Numerical return value
14711469
14721470
14731471
:Other Parameters:
14741472
1475-
**p3** : :xref_param_type:`list`\[:xref_param_type:`int`]
1473+
**p3** : :class:`python:list`\[:class:`python:int`]
14761474
List of integers
14771475
14781476
**p4** : :class:`pandas.DataFrame`
14791477
A dataframe
14801478
1481-
**p5** : :term:`python:sequence` of :xref_param_type:`int`
1479+
**p5** : :obj:`python:sequence` of `int`
14821480
A sequence
14831481
"""
14841482

14851483

14861484
def test_xref():
14871485
xref_aliases = {
1488-
'sequence': ':term:`python:sequence`',
1489-
'iterable': ':term:`python:iterable`',
1490-
'array': 'numpy.ndarray',
1486+
'sequence': ':obj:`python:sequence`',
14911487
}
1488+
config = namedtuple('numpydoc_xref_aliases',
1489+
'numpydoc_xref_aliases')(xref_aliases)
1490+
app = namedtuple('config', 'config')(config)
1491+
update_config(app)
14921492

14931493
xref_ignore = {'of', 'default', 'optional'}
14941494

numpydoc/tests/test_numpydoc.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ class MockConfig():
1010
numpydoc_show_class_members = True
1111
numpydoc_show_inherited_class_members = True
1212
numpydoc_class_members_toctree = True
13+
numpydoc_xref_param_type = False
14+
numpydoc_xref_aliases = {}
15+
numpydoc_xref_ignore = set()
1316
templates_path = []
1417
numpydoc_edit_link = False
1518
numpydoc_citation_re = '[a-z0-9_.-]+'
@@ -41,7 +44,7 @@ def test_mangle_docstrings():
4144
doc = mangle_docstrings(MockApp(), 'class', 'str', str, {'members': ['upper']}, lines)
4245
assert 'rpartition' not in [x.strip() for x in lines]
4346
assert 'upper' in [x.strip() for x in lines]
44-
47+
4548
lines = s.split('\n')
4649
doc = mangle_docstrings(MockApp(), 'class', 'str', str, {'exclude-members': ALL}, lines)
4750
assert 'rpartition' not in [x.strip() for x in lines]

0 commit comments

Comments
 (0)