mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Added `exclude
argument to :func:
.autodoc.between`. From http://bitbucket.org/mfperzel/sphinx-additions.
This commit is contained in:
parent
d30d286486
commit
7c7d3f4010
1
CHANGES
1
CHANGES
@ -143,6 +143,7 @@ Features added
|
||||
instead of PNG images, controlled by the
|
||||
:confval:`graphviz_output_format` config value.
|
||||
- Added ``alt`` option to :rst:dir:`graphviz` extension directives.
|
||||
- Added ``exclude`` argument to :func:`.autodoc.between`.
|
||||
|
||||
* Translations:
|
||||
|
||||
|
@ -164,11 +164,12 @@ def cut_lines(pre, post=0, what=None):
|
||||
lines.append('')
|
||||
return process
|
||||
|
||||
def between(marker, what=None, keepempty=False):
|
||||
def between(marker, what=None, keepempty=False, exclude=False):
|
||||
"""
|
||||
Return a listener that only keeps lines between lines that match the
|
||||
*marker* regular expression. If no line matches, the resulting docstring
|
||||
would be empty, so no change will be made unless *keepempty* is true.
|
||||
Return a listener that either keeps, or if *exclude* is True excludes, lines
|
||||
between lines that match the *marker* regular expression. If no line
|
||||
matches, the resulting docstring would be empty, so no change will be made
|
||||
unless *keepempty* is true.
|
||||
|
||||
If *what* is a sequence of strings, only docstrings of a type in *what* will
|
||||
be processed.
|
||||
@ -178,7 +179,7 @@ def between(marker, what=None, keepempty=False):
|
||||
if what and what_ not in what:
|
||||
return
|
||||
deleted = 0
|
||||
delete = True
|
||||
delete = not exclude
|
||||
orig_lines = lines[:]
|
||||
for i, line in enumerate(orig_lines):
|
||||
if delete:
|
||||
|
@ -271,7 +271,7 @@ def test_docstring_processing():
|
||||
app.disconnect(lid)
|
||||
|
||||
lid = app.connect('autodoc-process-docstring', between('---', ['function']))
|
||||
def f():
|
||||
def g():
|
||||
"""
|
||||
first line
|
||||
---
|
||||
@ -279,9 +279,21 @@ def test_docstring_processing():
|
||||
---
|
||||
third line
|
||||
"""
|
||||
assert process('function', 'f', f) == ['second line', '']
|
||||
assert process('function', 'g', g) == ['second line', '']
|
||||
app.disconnect(lid)
|
||||
|
||||
lid = app.connect('autodoc-process-docstring', between('---', ['function'],
|
||||
exclude=True))
|
||||
def h():
|
||||
"""
|
||||
first line
|
||||
---
|
||||
second line
|
||||
---
|
||||
third line
|
||||
"""
|
||||
assert process('function', 'h', h) == ['first line', 'third line', '']
|
||||
app.disconnect(lid)
|
||||
|
||||
def test_new_documenter():
|
||||
class MyDocumenter(ModuleLevelDocumenter):
|
||||
|
Loading…
Reference in New Issue
Block a user