Skip to content

Commit 593328a

Browse files
authored
Merge pull request astropy#335 from drdavella/doctest-directives
Allow Sphinx doctest extension to recognize standard doctest directives
2 parents 1412645 + c636267 commit 593328a

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

‎CHANGES.rst‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ astropy-helpers Changelog
3434
it could not work as intended. Add new function ``add_exclude_packages`` to
3535
provide intended behavior. [#331]
3636

37+
- Allow custom Sphinx doctest extension to recognize and process standard
38+
doctest directives ``testsetup`` and ``doctest``. [#335]
39+
3740
2.0.1 (2017-07-28)
3841
------------------
3942

‎astropy_helpers/sphinx/ext/doctest.py‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ def run(self):
2626
return [literal_block(code, code)]
2727

2828

29+
class DoctestOmitDirective(Directive):
30+
has_content = True
31+
32+
def run(self):
33+
# Simply do not add any content when this directive is encountered
34+
return []
35+
36+
2937
class DoctestRequiresDirective(DoctestSkipDirective):
3038
# This is silly, but we really support an unbounded number of
3139
# optional arguments
@@ -37,6 +45,12 @@ def setup(app):
3745
app.add_directive('doctest-requires', DoctestRequiresDirective)
3846
app.add_directive('doctest-skip', DoctestSkipDirective)
3947
app.add_directive('doctest-skip-all', DoctestSkipDirective)
48+
app.add_directive('doctest', DoctestSkipDirective)
49+
# Code blocks that use this directive will not appear in the generated
50+
# documentation. This is intended to hide boilerplate code that is only
51+
# useful for testing documentation using doctest, but does not actually
52+
# belong in the documentation itself.
53+
app.add_directive('testsetup', DoctestOmitDirective)
4054

4155
return {'parallel_read_safe': True,
4256
'parallel_write_safe': True}

0 commit comments

Comments
 (0)