Skip to content

Commit

Permalink
docs(build): turn off interactive mode before every example
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcloud committed Dec 17, 2023
1 parent 2f9ec90 commit 502b88c
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions docs/_renderer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

from textwrap import dedent

import quartodoc as qd
import toolz
from plum import dispatch
Expand All @@ -26,6 +28,8 @@ def render(self, el: qd.ast.ExampleCode) -> str:
lambda line: quartodoc_skip_doctest in line or skip_doctest in line
)

has_executed_chunks = False

for chunk in toolz.partitionby(chunker, lines):
first, *rest = chunk

Expand All @@ -35,10 +39,11 @@ def render(self, el: qd.ast.ExampleCode) -> str:
# check whether to skip execution and if so, render the code
# block as `python` (not `{python}`) if it's marked with
# skip_doctest, expect_failure or quartodoc_skip_doctest
if not any(map(should_skip, chunk)):
start, end = "{}"
else:
if any(map(should_skip, chunk)):
start = end = ""
else:
has_executed_chunks = True
start, end = "{}"

result.append(f"```{start}python{end}")

Expand All @@ -62,4 +67,22 @@ def render(self, el: qd.ast.ExampleCode) -> str:
result.extend(rest)
result.append("```\n")

return "\n".join(result)
examples = "\n".join(result)

if has_executed_chunks:
# turn off interactive mode before rendering
return (
dedent(
"""
```{python}
#| echo: false
import ibis
ibis.options.interactive = False
```
"""
)
+ examples
)
else:
return examples

0 comments on commit 502b88c

Please sign in to comment.