Skip to content

Commit 40cd61d

Browse files
Merge remote-tracking branch 'upstream/master' into attributes_as_param_list
2 parents b311805 + af6690a commit 40cd61d

17 files changed

+810
-287
lines changed

.travis.yml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,29 @@
22
# http://lint.travis-ci.org/
33
language: python
44
sudo: false
5-
python:
6-
- 3.6
7-
- 2.7
85
env:
96
- SPHINX_SPEC="Sphinx==1.2.3"
107
- SPHINX_SPEC="Sphinx"
8+
matrix:
9+
include:
10+
- python: 3.6
11+
- python: 2.7
12+
env:
13+
- SPHINXOPTS='-W'
1114
cache:
1215
directories:
1316
- $HOME/.cache/pip
1417
before_install:
1518
- sudo apt-get install texlive texlive-latex-extra latexmk
1619
- pip install --upgrade pip setuptools # Upgrade pip and setuptools to get ones with `wheel` support
17-
- pip install --find-links http://wheels.astropy.org/ --find-links http://wheels2.astropy.org/ --trusted-host wheels.astropy.org --trusted-host wheels2.astropy.org --use-wheel nose numpy matplotlib ${SPHINX_SPEC}
20+
- pip install pytest numpy matplotlib ${SPHINX_SPEC}
1821
script:
1922
- |
2023
python setup.py sdist
2124
cd dist
2225
pip install numpydoc* -v
23-
- nosetests numpydoc
26+
- pytest --pyargs numpydoc
2427
- |
2528
cd ../doc
26-
make html
27-
make latexpdf
29+
make SPHINXOPTS=$SPHINXOPTS html
30+
make SPHINXOPTS=$SPHINXOPTS latexpdf

README.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ numpydoc -- Numpy's Sphinx extensions
1212
=====================================
1313

1414
This package provides the ``numpydoc`` Sphinx extension for handling
15-
docstrings formatted according to the `NumPy documentation format
16-
<https://github.com/numpy/numpy/blob/master/doc/HOWTO_DOCUMENT.rst.txt>`__.
15+
docstrings formatted according to the NumPy documentation format.
1716
The extension also adds the code description directives
1817
``np:function``, ``np-c:function``, etc.
1918

doc/conf.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,19 @@
4141
'sphinx.ext.autosummary',
4242
'sphinx.ext.doctest',
4343
'sphinx.ext.intersphinx',
44-
'sphinx.ext.pngmath',
4544
'sphinx.ext.todo',
4645
'numpydoc',
4746
'sphinx.ext.ifconfig',
4847
'sphinx.ext.viewcode',
4948
]
5049

50+
try:
51+
import sphinx.ext.imgmath # noqa
52+
except ImportError:
53+
extensions.append('sphinx.ext.pngmath')
54+
else:
55+
extensions.append('sphinx.ext.imgmath')
56+
5157
# Add any paths that contain templates here, relative to this directory.
5258
templates_path = ['_templates']
5359

@@ -149,13 +155,12 @@
149155
html_sidebars = {}
150156

151157
html_title = "%s v%s Manual" % (project, version)
152-
html_static_path = ['_static']
153158
html_last_updated_fmt = '%b %d, %Y'
154159

155160
# Add any paths that contain custom static files (such as style sheets) here,
156161
# relative to this directory. They are copied after the builtin static files,
157162
# so a file named "default.css" will overwrite the builtin "default.css".
158-
html_static_path = ['_static']
163+
html_static_path = [] # ['_static']
159164

160165
# Add any extra paths that contain custom files (such as robots.txt or
161166
# .htaccess) here, relative to this directory. These files are copied
@@ -264,5 +269,5 @@
264269
# Example configuration for intersphinx: refer to the Python standard library.
265270
intersphinx_mapping = {
266271
'python': ('http://docs.python.org/', None),
267-
'scikit-learn': ('http://scikit-learn.org/stable/', None),
272+
'scikitlearn': ('http://scikit-learn.org/stable/', None),
268273
}

doc/example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def foo(var1, var2, long_var_name='hi'):
9393
9494
.. math:: X(e^{j\omega } ) = x(n)e^{ - j\omega n}
9595
96-
And even use a greek symbol like :math:`omega` inline.
96+
And even use a Greek symbol like :math:`\omega` inline.
9797
9898
References
9999
----------

doc/format.rst

Lines changed: 60 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ The sections of a function's docstring are:
119119

120120
"""
121121

122+
.. highlight:: rst
123+
122124
2. **Deprecation warning**
123125

124126
A section (use if applicable) to warn users that the object is deprecated.
@@ -250,13 +252,21 @@ The sections of a function's docstring are:
250252
Support for the **Yields** section was added in `numpydoc
251253
<https://github.com/numpy/numpydoc>`_ version 0.6.
252254

253-
7. **Other Parameters**
255+
7. **Receives**
256+
257+
Explanation of parameters passed to a generator's ``.send()`` method,
258+
formatted as for Parameters, above. Since, like for Yields and Returns, a
259+
single object is always passed to the method, this may describe either the
260+
single parameter, or positional arguments passed as a tuple. If a docstring
261+
includes Receives it must also include Yields.
262+
263+
8. **Other Parameters**
254264

255265
An optional section used to describe infrequently used parameters.
256266
It should only be used if a function has a large number of keyword
257267
parameters, to prevent cluttering the **Parameters** section.
258268

259-
8. **Raises**
269+
9. **Raises**
260270

261271
An optional section detailing which errors get raised and under
262272
what conditions::
@@ -269,55 +279,55 @@ The sections of a function's docstring are:
269279
This section should be used judiciously, i.e., only for errors
270280
that are non-obvious or have a large chance of getting raised.
271281

272-
9. **Warns**
282+
10. **Warns**
273283

274284
An optional section detailing which warnings get raised and
275285
under what conditions, formatted similarly to Raises.
276286

277-
10. **Warnings**
287+
11. **Warnings**
278288

279-
An optional section with cautions to the user in free text/reST.
289+
An optional section with cautions to the user in free text/reST.
280290

281-
11. **See Also**
291+
12. **See Also**
282292

283-
An optional section used to refer to related code. This section
284-
can be very useful, but should be used judiciously. The goal is to
285-
direct users to other functions they may not be aware of, or have
286-
easy means of discovering (by looking at the module docstring, for
287-
example). Routines whose docstrings further explain parameters
288-
used by this function are good candidates.
293+
An optional section used to refer to related code. This section
294+
can be very useful, but should be used judiciously. The goal is to
295+
direct users to other functions they may not be aware of, or have
296+
easy means of discovering (by looking at the module docstring, for
297+
example). Routines whose docstrings further explain parameters
298+
used by this function are good candidates.
289299

290-
As an example, for ``numpy.mean`` we would have::
300+
As an example, for ``numpy.mean`` we would have::
291301

292-
See Also
293-
--------
294-
average : Weighted average
302+
See Also
303+
--------
304+
average : Weighted average
295305

296-
When referring to functions in the same sub-module, no prefix is
297-
needed, and the tree is searched upwards for a match.
306+
When referring to functions in the same sub-module, no prefix is
307+
needed, and the tree is searched upwards for a match.
298308

299-
Prefix functions from other sub-modules appropriately. E.g.,
300-
whilst documenting the ``random`` module, refer to a function in
301-
``fft`` by
309+
Prefix functions from other sub-modules appropriately. E.g.,
310+
whilst documenting the ``random`` module, refer to a function in
311+
``fft`` by
302312

303-
::
313+
::
304314

305-
fft.fft2 : 2-D fast discrete Fourier transform
315+
fft.fft2 : 2-D fast discrete Fourier transform
306316

307-
When referring to an entirely different module::
317+
When referring to an entirely different module::
308318

309-
scipy.random.norm : Random variates, PDFs, etc.
319+
scipy.random.norm : Random variates, PDFs, etc.
310320

311-
Functions may be listed without descriptions, and this is
312-
preferable if the functionality is clear from the function name::
321+
Functions may be listed without descriptions, and this is
322+
preferable if the functionality is clear from the function name::
313323

314-
See Also
315-
--------
316-
func_a : Function a with its description.
317-
func_b, func_c_, func_d
318-
func_e
324+
See Also
325+
--------
326+
func_a : Function a with its description.
327+
func_b, func_c_, func_d
328+
func_e
319329

320-
12. **Notes**
330+
13. **Notes**
321331

322332
An optional section that provides additional information about the
323333
code, possibly including a discussion of the algorithm. This
@@ -362,7 +372,7 @@ The sections of a function's docstring are:
362372
where filename is a path relative to the reference guide source
363373
directory.
364374

365-
13. **References**
375+
14. **References**
366376

367377
References cited in the **notes** section may be listed here,
368378
e.g. if you cited the article below using the text ``[1]_``,
@@ -374,7 +384,7 @@ The sections of a function's docstring are:
374384
and neural-network techniques," Computers & Geosciences, vol. 22,
375385
pp. 585-588, 1996.
376386

377-
which renders as
387+
which renders as [1]_:
378388

379389
.. [1] O. McNoleg, "The integration of GIS, remote sensing,
380390
expert systems and adaptive co-kriging for environmental habitat
@@ -393,7 +403,9 @@ The sections of a function's docstring are:
393403
docstring, the table markup will be broken by numpydoc processing. See
394404
`numpydoc issue #130 <https://github.com/numpy/numpydoc/issues/130>`_
395405

396-
14. **Examples**
406+
.. highlight:: pycon
407+
408+
15. **Examples**
397409

398410
An optional section for examples, using the `doctest
399411
<http://docs.python.org/library/doctest.html>`_ format.
@@ -413,6 +425,14 @@ The sections of a function's docstring are:
413425
>>> np.add([1, 2], [3, 4])
414426
array([4, 6])
415427

428+
The example code may be split across multiple lines, with each line after
429+
the first starting with '... '::
430+
431+
>>> np.add([[1, 2], [3, 4]],
432+
... [[5, 6], [7, 8]])
433+
array([[ 6, 8],
434+
[10, 12]])
435+
416436
For tests with a result that is random or platform-dependent, mark the
417437
output as such::
418438

@@ -456,6 +476,7 @@ The sections of a function's docstring are:
456476
`matplotlib.sphinxext.plot_directive` is loaded as a Sphinx extension in
457477
``conf.py``.
458478

479+
.. highlight:: rst
459480

460481
Documenting classes
461482
-------------------
@@ -493,7 +514,9 @@ In general, it is not necessary to list class methods. Those that are
493514
not part of the public API have names that start with an underscore.
494515
In some cases, however, a class may have a great many methods, of
495516
which only a few are relevant (e.g., subclasses of ndarray). Then, it
496-
becomes useful to have an additional **Methods** section::
517+
becomes useful to have an additional **Methods** section:
518+
519+
.. code-block:: python
497520
498521
class Photo(ndarray):
499522
"""

doc/index.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Sphinx, and adds the code description directives ``np:function``,
1111
``np-c:function``, etc. that support the Numpy docstring syntax.
1212

1313
- Development: https://github.com/numpy/numpydoc/
14-
- Documentation: https://numpydoc.readthedocs.org/
14+
- Documentation: https://numpydoc.readthedocs.io/
1515
- PyPI: https://pypi.python.org/pypi/numpydoc/
1616

1717

@@ -22,3 +22,4 @@ Documentation
2222
install
2323
format
2424
example
25+
validation

doc/validation.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
==============================
2+
Validating NumpyDoc docstrings
3+
==============================
4+
5+
One tool for validating docstrings is to see how an object's dosctring
6+
translates to Restructured Text. Using numpydoc as a command-line tool
7+
facilitates this. For example to see the Restructured Text generated
8+
for ``numpy.ndarray``, use:
9+
10+
.. code-block:: bash
11+
12+
$ python -m numpydoc numpy.ndarray

numpydoc/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import division, absolute_import, print_function
22

3-
__version__ = '0.8.0.dev0'
3+
__version__ = '0.9.0.dev0'
44

55

66
def setup(app, *args, **kwargs):

numpydoc/__main__.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import argparse
2+
import importlib
3+
import ast
4+
5+
from .docscrape_sphinx import get_doc_object
6+
7+
8+
def main(argv=None):
9+
"""Test numpydoc docstring generation for a given object"""
10+
11+
ap = argparse.ArgumentParser(description=__doc__)
12+
ap.add_argument('import_path', help='e.g. numpy.ndarray')
13+
14+
def _parse_config(s):
15+
key, _, value = s.partition('=')
16+
value = ast.literal_eval(value)
17+
return key, value
18+
19+
ap.add_argument('-c', '--config', type=_parse_config,
20+
action='append',
21+
help='key=val where val will be parsed by literal_eval, '
22+
'e.g. -c use_plots=True. Multiple -c can be used.')
23+
args = ap.parse_args(argv)
24+
25+
parts = args.import_path.split('.')
26+
27+
for split_point in range(len(parts), 0, -1):
28+
try:
29+
path = '.'.join(parts[:split_point])
30+
obj = importlib.import_module(path)
31+
except ImportError:
32+
continue
33+
break
34+
else:
35+
raise ImportError('Could not resolve {!r} to an importable object'
36+
''.format(args.import_path))
37+
38+
for part in parts[split_point:]:
39+
obj = getattr(obj, part)
40+
41+
print(get_doc_object(obj, config=dict(args.config or [])))
42+
43+
if __name__ == '__main__':
44+
main()

0 commit comments

Comments
 (0)