Skip to content

Commit 85cec95

Browse files
committed
Docs: unconditionally show plain Python example
1 parent aa27703 commit 85cec95

File tree

3 files changed

+34
-47
lines changed

3 files changed

+34
-47
lines changed

src/doc/en/installation/source-distro.rst

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -993,10 +993,6 @@ Environment variables controlling the documentation build
993993
- add ``--no-plot`` to this variable to avoid building the graphics coming from
994994
the ``.. PLOT`` directive within the documentation,
995995

996-
- add ``--no-preparsed-examples`` to only show the original Sage code of
997-
"EXAMPLES" blocks, suppressing the tab with the preparsed, plain Python
998-
version, or
999-
1000996
- add ``--include-tests-blocks`` to include all "TESTS" blocks in the reference
1001997
manual.
1002998

src/sage_docbuild/__main__.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@
3434
-j, --mathjax, --jsmath
3535
ignored for backwards compatibility
3636
--no-plot do not include graphics auto-generated using the '.. plot' markup
37-
--no-preparsed-examples
38-
do not show preparsed versions of EXAMPLES blocks
3937
--include-tests-blocks
4038
include TESTS blocks in the reference manual
4139
--no-pdf-links do not include PDF links in DOCUMENT 'website';
@@ -297,9 +295,6 @@ def setup_parser():
297295
standard.add_argument("--no-plot", dest="no_plot",
298296
action="store_true",
299297
help="do not include graphics auto-generated using the '.. plot' markup")
300-
standard.add_argument("--no-preparsed-examples", dest="no_preparsed_examples",
301-
action="store_true",
302-
help="do not show preparsed versions of EXAMPLES blocks")
303298
standard.add_argument("--include-tests-blocks", dest="skip_tests", default=True,
304299
action="store_false",
305300
help="include TESTS blocks in the reference manual")
@@ -513,8 +508,6 @@ def excepthook(*exc_info):
513508
build_options.ALLSPHINXOPTS += "-n "
514509
if args.no_plot:
515510
os.environ['SAGE_SKIP_PLOT_DIRECTIVE'] = 'yes'
516-
if args.no_preparsed_examples:
517-
os.environ['SAGE_PREPARSED_DOC'] = 'no'
518511
if args.live_doc:
519512
os.environ['SAGE_LIVE_DOC'] = 'yes'
520513
if args.skip_tests:

src/sage_docbuild/conf.py

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
# ---------------------
4040

4141
SAGE_LIVE_DOC = os.environ.get('SAGE_LIVE_DOC', 'no')
42-
SAGE_PREPARSED_DOC = os.environ.get('SAGE_PREPARSED_DOC', 'yes')
4342

4443
# Add any Sphinx extension module names here, as strings. They can be extensions
4544
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
@@ -993,40 +992,40 @@ def apply(self):
993992
if isinstance(prev_node, nodes.paragraph):
994993
prev_node['classes'].append('with-sage-tab')
995994

996-
if SAGE_PREPARSED_DOC == 'yes':
997-
# Tab for preparsed version
998-
from sage.repl.preparse import preparse
999-
container = TabContainer("", type="tab", new_set=False)
1000-
textnodes = [Text('Python')]
1001-
label = Label("", "", *textnodes)
1002-
container += label
1003-
content = Container("", is_div=True, classes=["tab-content"])
1004-
example_lines = []
1005-
preparsed_lines = ['>>> from sage.all import *']
1006-
for line in node.rawsource.splitlines() + ['']: # one extra to process last example
1007-
newline = line.lstrip()
1008-
if newline.startswith('....: '):
995+
# Tab for preparsed version
996+
from sage.repl.preparse import preparse
997+
container = TabContainer("", type="tab", new_set=False)
998+
textnodes = [Text('Python')]
999+
label = Label("", "", *textnodes)
1000+
container += label
1001+
content = Container("", is_div=True, classes=["tab-content"])
1002+
example_lines = []
1003+
preparsed_lines = ['>>> from sage.all import *']
1004+
for line in node.rawsource.splitlines() + ['']: # one extra to process last example
1005+
newline = line.lstrip()
1006+
if newline.startswith('....: '):
1007+
example_lines.append(newline[6:])
1008+
else:
1009+
if example_lines:
1010+
preparsed_example = preparse('\n'.join(example_lines))
1011+
prompt = '>>> '
1012+
for preparsed_line in preparsed_example.splitlines():
1013+
preparsed_lines.append(prompt + preparsed_line)
1014+
prompt = '... '
1015+
example_lines = []
1016+
if newline.startswith('sage: '):
10091017
example_lines.append(newline[6:])
10101018
else:
1011-
if example_lines:
1012-
preparsed_example = preparse('\n'.join(example_lines))
1013-
prompt = '>>> '
1014-
for preparsed_line in preparsed_example.splitlines():
1015-
preparsed_lines.append(prompt + preparsed_line)
1016-
prompt = '... '
1017-
example_lines = []
1018-
if newline.startswith('sage: '):
1019-
example_lines.append(newline[6:])
1020-
else:
1021-
preparsed_lines.append(line)
1022-
preparsed = '\n'.join(preparsed_lines)
1023-
preparsed_node = LiteralBlock(preparsed, preparsed, language='ipycon')
1024-
content += preparsed_node
1025-
container += content
1026-
parent.insert(index, container)
1027-
index += 1
1028-
if isinstance(prev_node, nodes.paragraph):
1029-
prev_node['classes'].append('with-python-tab')
1019+
preparsed_lines.append(line)
1020+
preparsed = '\n'.join(preparsed_lines)
1021+
preparsed_node = LiteralBlock(preparsed, preparsed, language='ipycon')
1022+
content += preparsed_node
1023+
container += content
1024+
parent.insert(index, container)
1025+
index += 1
1026+
if isinstance(prev_node, nodes.paragraph):
1027+
prev_node['classes'].append('with-python-tab')
1028+
10301029
if SAGE_LIVE_DOC == 'yes':
10311030
# Tab for Jupyter-sphinx cell
10321031
from jupyter_sphinx.ast import CellInputNode, JupyterCellNode
@@ -1084,9 +1083,8 @@ def setup(app):
10841083
app.connect('autodoc-process-docstring', skip_TESTS_block)
10851084
app.connect('autodoc-skip-member', skip_member)
10861085
app.add_transform(SagemathTransform)
1087-
if SAGE_LIVE_DOC == 'yes' or SAGE_PREPARSED_DOC == 'yes':
1088-
app.add_transform(SagecodeTransform)
1089-
else:
1086+
app.add_transform(SagecodeTransform)
1087+
if SAGE_LIVE_DOC != 'yes':
10901088
app.add_directive("jupyter-execute", Ignore)
10911089
app.add_directive("jupyter-kernel", Ignore)
10921090
app.add_directive("jupyter-input", Ignore)

0 commit comments

Comments
 (0)