Skip to content

Commit 0d9afc5

Browse files
committed
Merge branch 'master' into deflist
2 parents 059ea70 + 2f075a6 commit 0d9afc5

File tree

8 files changed

+87
-60
lines changed

8 files changed

+87
-60
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ cache:
1212
directories:
1313
- $HOME/.cache/pip
1414
before_install:
15+
- sudo apt-get install texlive texlive-latex-extra latexmk
1516
- pip install --upgrade pip setuptools # Upgrade pip and setuptools to get ones with `wheel` support
1617
- 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}
1718
script:

doc/conf.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
# ones.
3939
extensions = [
4040
'sphinx.ext.autodoc',
41+
'sphinx.ext.autosummary',
4142
'sphinx.ext.doctest',
4243
'sphinx.ext.intersphinx',
4344
'sphinx.ext.pngmath',
@@ -223,7 +224,7 @@
223224
# (source start file, target name, title,
224225
# author, documentclass [howto, manual, or own class]).
225226
latex_documents = [
226-
('index', '.tex', u'numpydoc Documentation',
227+
('index', 'numpydoc.tex', u'numpydoc Documentation',
227228
u'Numpydoc maintainers', 'manual'),
228229
]
229230

doc/format.rst

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,12 @@ facilitate reading the docstrings in text terminals.
8888

8989
Sections
9090
--------
91-
The sections of the docstring are:
91+
92+
The docstring consists of a number of sections separated by headings (except
93+
for the deprecation warning). Each heading should be underlined in hyphens, and
94+
the section ordering should be consistent with the description below.
95+
96+
The sections of a function's docstring are:
9297

9398
1. **Short summary**
9499

@@ -127,12 +132,12 @@ The sections of the docstring are:
127132

128133
* New recommended way of obtaining the same functionality.
129134

130-
This section should use the note Sphinx directive instead of an
135+
This section should use the ``deprecated`` Sphinx directive instead of an
131136
underlined section header.
132137

133138
::
134139

135-
.. note:: Deprecated in NumPy 1.6.0
140+
.. deprecated:: 1.6.0
136141
`ndobj_old` will be removed in NumPy 2.0.0, it is replaced by
137142
`ndobj_new` because the latter works also with array subclasses.
138143

@@ -264,7 +269,16 @@ The sections of the docstring are:
264269
This section should be used judiciously, i.e., only for errors
265270
that are non-obvious or have a large chance of getting raised.
266271

267-
9. **See Also**
272+
9. **Warns**
273+
274+
An optional section detailing which warnings get raised and
275+
under what conditions, formatted similarly to Raises.
276+
277+
10. **Warnings**
278+
279+
An optional section with cautions to the user in free text/reST.
280+
281+
11. **See Also**
268282

269283
An optional section used to refer to related code. This section
270284
can be very useful, but should be used judiciously. The goal is to
@@ -303,7 +317,7 @@ The sections of the docstring are:
303317
func_b, func_c_, func_d
304318
func_e
305319

306-
10. **Notes**
320+
12. **Notes**
307321

308322
An optional section that provides additional information about the
309323
code, possibly including a discussion of the algorithm. This
@@ -348,7 +362,7 @@ The sections of the docstring are:
348362
where filename is a path relative to the reference guide source
349363
directory.
350364

351-
11. **References**
365+
13. **References**
352366

353367
References cited in the **notes** section may be listed here,
354368
e.g. if you cited the article below using the text ``[1]_``,
@@ -373,7 +387,7 @@ The sections of the docstring are:
373387
should not be required to understand it. References are numbered, starting
374388
from one, in the order in which they are cited.
375389

376-
12. **Examples**
390+
14. **Examples**
377391

378392
An optional section for examples, using the `doctest
379393
<http://docs.python.org/library/doctest.html>`_ format.
@@ -597,6 +611,19 @@ Other points to keep in mind
597611
(i.e. scalar types, sequence types), those arguments can be documented
598612
with type `array_like`.
599613

614+
* Links : If you need to include hyperlinks in your docstring, note that
615+
some docstring sections are not parsed as standard reST, and in these
616+
sections, numpydoc may become confused by hyperlink targets such as::
617+
618+
.. _Example: http://www.example.com
619+
620+
If the Sphinx build issues a warning of the form
621+
``WARNING: Unknown target name: "example"``, then that is what is happening.
622+
To avoid this problem, use the inline hyperlink form::
623+
624+
`Example <http://www.example.com>`_
625+
626+
600627
Common reST concepts
601628
--------------------
602629
For paragraphs, indentation is significant and indicates indentation in the

doc/install.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,7 @@ The following options can be set in your Sphinx ``conf.py``:
1919

2020
numpydoc_use_plots : bool
2121
Whether to produce ``plot::`` directives for Examples sections that
22-
contain ``import matplotlib``.
23-
numpydoc_use_blockqutoes : bool
24-
Until version 0.8, parameter definitions were shown as blockquotes, rather
25-
than in a definition list. If your styling requires blockquotes, switch
26-
this config option to True. This option will be removed in version 0.10.
22+
contain ``import matplotlib`` or ``from matplotlib import``.
2723
numpydoc_show_class_members : bool
2824
Whether to show all members of a class in the Methods and Attributes
2925
sections automatically.
@@ -42,7 +38,11 @@ numpydoc_citation_re : str
4238
should be mangled to avoid conflicts due to
4339
duplication across the documentation. Defaults
4440
to ``[\w-]+``.
41+
numpydoc_use_blockqutoes : bool
42+
Until version 0.8, parameter definitions were shown as blockquotes, rather
43+
than in a definition list. If your styling requires blockquotes, switch
44+
this config option to True. This option will be removed in version 0.10.
4545
numpydoc_edit_link : bool
46-
.. deprecated: edit your HTML template instead
46+
.. deprecated:: edit your HTML template instead
4747

4848
Whether to insert an edit link after docstrings.

numpydoc/docscrape.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,8 @@ def _parse_param_list(self, content):
229229

230230
return params
231231

232-
_name_rgx = re.compile(r"^\s*(:(?P<role>\w+):`(?P<name>[a-zA-Z0-9_.-]+)`|"
232+
_name_rgx = re.compile(r"^\s*(:(?P<role>\w+):"
233+
r"`(?P<name>(?:~\w+\.)?[a-zA-Z0-9_.-]+)`|"
233234
r" (?P<name2>[a-zA-Z0-9_.-]+))\s*", re.X)
234235

235236
def _parse_see_also(self, content):

numpydoc/docscrape_sphinx.py

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
sixu = lambda s: unicode(s, 'unicode_escape')
2222

2323

24+
IMPORT_MATPLOTLIB_RE = r'\b(import +matplotlib|from +matplotlib +import)\b'
25+
26+
2427
class SphinxDocString(NumpyDocString):
2528
def __init__(self, docstring, config={}):
2629
NumpyDocString.__init__(self, docstring, config=config)
@@ -88,10 +91,10 @@ def _str_returns(self, name='Returns'):
8891
out += ['']
8992
return out
9093

91-
def _process_param(self, param, desc, autosum):
94+
def _process_param(self, param, desc, fake_autosummary):
9295
"""Determine how to display a parameter
9396
94-
Emulates autosummary behavior if autosum is not None.
97+
Emulates autosummary behavior if fake_autosummary
9598
9699
Parameters
97100
----------
@@ -100,12 +103,9 @@ def _process_param(self, param, desc, autosum):
100103
desc : list of str
101104
The parameter description as given in the docstring. This is
102105
ignored when autosummary logic applies.
103-
autosum : list or None
104-
If a list, autosummary-style behaviour will apply for params
106+
fake_autosummary : bool
107+
If True, autosummary-style behaviour will apply for params
105108
that are attributes of the class and have a docstring.
106-
Names for autosummary generation will be appended to this list.
107-
108-
If None, autosummary is disabled.
109109
110110
Returns
111111
-------
@@ -128,7 +128,7 @@ def _process_param(self, param, desc, autosum):
128128
param = param.strip()
129129
display_param = ('**%s**' if self.use_blockquotes else '%s') % param
130130

131-
if autosum is None:
131+
if not fake_autosummary:
132132
return display_param, desc
133133

134134
param_obj = getattr(self._obj, param, None)
@@ -150,7 +150,6 @@ def _process_param(self, param, desc, autosum):
150150
link_prefix = ''
151151

152152
# Referenced object has a docstring
153-
autosum.append(" %s%s" % (autosum_prefix, param))
154153
display_param = ':obj:`%s <%s%s>`' % (param,
155154
link_prefix,
156155
param)
@@ -190,15 +189,11 @@ def _str_param_list(self, name, fake_autosummary=False):
190189
"""
191190
out = []
192191
if self[name]:
193-
if fake_autosummary:
194-
autosum = []
195-
else:
196-
autosum = None
197-
198192
out += self._str_field_list(name)
199193
out += ['']
200194
for param, param_type, desc in self[name]:
201-
display_param, desc = self._process_param(param, desc, autosum)
195+
display_param, desc = self._process_param(param, desc,
196+
fake_autosummary)
202197

203198
if param_type:
204199
out += self._str_indent(['%s : %s' % (display_param,
@@ -211,14 +206,6 @@ def _str_param_list(self, name, fake_autosummary=False):
211206
out += self._str_indent(desc, 8)
212207
out += ['']
213208

214-
if fake_autosummary and autosum:
215-
if self.class_members_toctree:
216-
autosum.insert(0, ' :toctree:')
217-
autosum.insert(0, '.. autosummary::')
218-
out += ['..', ' HACK to make autogen generate docs:']
219-
out += self._str_indent(autosum, 4)
220-
out += ['']
221-
222209
return out
223210

224211
@property
@@ -348,7 +335,7 @@ def _str_references(self):
348335
def _str_examples(self):
349336
examples_str = "\n".join(self['Examples'])
350337

351-
if (self.use_plots and 'import matplotlib' in examples_str
338+
if (self.use_plots and re.search(IMPORT_MATPLOTLIB_RE, examples_str)
352339
and 'plot::' not in examples_str):
353340
out = []
354341
out += self._str_header('Examples')

numpydoc/numpydoc.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,30 +39,36 @@
3939
def rename_references(app, what, name, obj, options, lines,
4040
reference_offset=[0]):
4141
# replace reference numbers so that there are no duplicates
42-
references = []
42+
references = set()
4343
for line in lines:
4444
line = line.strip()
4545
m = re.match(sixu('^.. \\[(%s)\\]') % app.config.numpydoc_citation_re,
4646
line, re.I)
4747
if m:
48-
references.append(m.group(1))
48+
references.add(m.group(1))
4949

5050
if references:
51-
for i, line in enumerate(lines):
52-
for r in references:
53-
if re.match(sixu('^\\d+$'), r):
54-
new_r = sixu("R%d") % (reference_offset[0] + int(r))
55-
else:
56-
new_r = sixu("%s%d") % (r, reference_offset[0])
51+
for r in references:
52+
if r.isdigit():
53+
new_r = sixu("R%d") % (reference_offset[0] + int(r))
54+
else:
55+
new_r = sixu("%s%d") % (r, reference_offset[0])
56+
57+
for i, line in enumerate(lines):
5758
lines[i] = lines[i].replace(sixu('[%s]_') % r,
5859
sixu('[%s]_') % new_r)
5960
lines[i] = lines[i].replace(sixu('.. [%s]') % r,
6061
sixu('.. [%s]') % new_r)
6162

62-
reference_offset[0] += len(references)
63+
reference_offset[0] += len(references)
64+
65+
66+
DEDUPLICATION_TAG = ' !! processed by numpydoc !!'
6367

6468

6569
def mangle_docstrings(app, what, name, obj, options, lines):
70+
if DEDUPLICATION_TAG in lines:
71+
return
6672

6773
cfg = {'use_plots': app.config.numpydoc_use_plots,
6874
'use_blockquotes': app.config.numpydoc_use_blockquotes,
@@ -100,6 +106,8 @@ def mangle_docstrings(app, what, name, obj, options, lines):
100106
# duplicates
101107
rename_references(app, what, name, obj, options, lines)
102108

109+
lines += ['..', DEDUPLICATION_TAG]
110+
103111

104112
def mangle_signature(app, what, name, obj, options, sig, retann):
105113
# Do not try to inspect classes that don't define `__init__`

numpydoc/tests/test_docscrape.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -685,21 +685,23 @@ def test_see_also():
685685
func_f, func_g, :meth:`func_h`, func_j,
686686
func_k
687687
:obj:`baz.obj_q`
688+
:obj:`~baz.obj_r`
688689
:class:`class_j`: fubar
689690
foobar
690691
""")
691692

692-
assert len(doc6['See Also']) == 12
693+
assert len(doc6['See Also']) == 13
693694
for func, desc, role in doc6['See Also']:
694695
if func in ('func_a', 'func_b', 'func_c', 'func_f',
695-
'func_g', 'func_h', 'func_j', 'func_k', 'baz.obj_q'):
696+
'func_g', 'func_h', 'func_j', 'func_k', 'baz.obj_q',
697+
'~baz.obj_r'):
696698
assert(not desc)
697699
else:
698700
assert(desc)
699701

700702
if func == 'func_h':
701703
assert role == 'meth'
702-
elif func == 'baz.obj_q':
704+
elif func == 'baz.obj_q' or func == '~baz.obj_r':
703705
assert role == 'obj'
704706
elif func == 'class_j':
705707
assert role == 'class'
@@ -830,6 +832,15 @@ def test_plot_examples():
830832
""", config=cfg)
831833
assert 'plot::' in str(doc), str(doc)
832834

835+
doc = SphinxDocString("""
836+
Examples
837+
--------
838+
>>> from matplotlib import pyplot as plt
839+
>>> plt.plot([1,2,3],[4,5,6])
840+
>>> plt.show()
841+
""", config=cfg)
842+
assert 'plot::' in str(doc), str(doc)
843+
833844
doc = SphinxDocString("""
834845
Examples
835846
--------
@@ -1146,15 +1157,6 @@ def no_period(self):
11461157
:obj:`no_period <no_period>`
11471158
This does not have a period
11481159
1149-
..
1150-
HACK to make autogen generate docs:
1151-
.. autosummary::
1152-
:toctree:
1153-
an_attribute
1154-
multiline_sentence
1155-
midword_period
1156-
no_period
1157-
11581160
.. rubric:: Methods
11591161
11601162
===== ==========

0 commit comments

Comments
 (0)