Added `exclude argument to :func:.autodoc.between`. From http://bitbucket.org/mfperzel/sphinx-additions.

This commit is contained in:
Georg Brandl 2010-06-12 18:16:18 +02:00
parent d30d286486
commit 7c7d3f4010
3 changed files with 21 additions and 7 deletions

View File

@ -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:

View File

@ -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:

View File

@ -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):