Skip to content

Commit

Permalink
fix(docs): surround executable code blocks with interactive mode on/off
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcloud authored and kszucs committed Jan 19, 2024
1 parent 8ed19ea commit 4c660e0
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 30 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,4 @@ ibis/examples/descriptions

# automatically generated odbc file for ci
ci/odbc/odbc.ini
*-citibike-tripdata.tar.xz
49 changes: 26 additions & 23 deletions docs/_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ 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 @@ -39,11 +37,22 @@ 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 any(map(should_skip, chunk)):
if skipped := any(map(should_skip, chunk)):
start = end = ""
else:
has_executed_chunks = True
start, end = "{}"
result.append(
dedent(
"""
```{python}
#| echo: false
import ibis
ibis.options.interactive = True
```
"""
)
)

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

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

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
if not skipped:
result.append(
dedent(
"""
```{python}
#| echo: false
ibis.options.interactive = False
```
"""
)
)

return "\n".join(result)
3 changes: 1 addition & 2 deletions ibis/expr/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,7 @@ def table(
Create a table with no data backing it
>>> import ibis
>>> ibis.options.interactive
False
>>> ibis.options.interactive = False
>>> t = ibis.table(schema=dict(a="int", b="string"), name="t")
>>> t
UnboundTable: t
Expand Down
7 changes: 2 additions & 5 deletions ibis/selectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,8 @@ def numeric() -> Predicate:
>>> import ibis
>>> import ibis.selectors as s
>>> t = ibis.table(dict(a="int", b="string", c="array<string>"), name="t")
>>> t
UnboundTable: t
a int64
b string
c array<string>
>>> t.columns
['a', 'b', 'c']
>>> expr = t.select(s.numeric()) # `a` has integer type, so it's numeric
>>> expr.columns
['a']
Expand Down

0 comments on commit 4c660e0

Please sign in to comment.