Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e614b60

Browse files
authored
docs: google style docs (marimo-team#3217)
1 parent e960e6d commit e614b60

File tree

6 files changed

+289
-289
lines changed

6 files changed

+289
-289
lines changed

marimo/_ast/cell.py

Lines changed: 92 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,16 @@ def configure(self, update: dict[str, Any] | CellConfig) -> CellImpl:
186186

187187
@property
188188
def runtime_state(self) -> Optional[RuntimeStateType]:
189+
"""Gets the current runtime state of the cell.
190+
191+
Returns:
192+
Optional[RuntimeStateType]: The current state, one of:
193+
- "idle": cell has run with latest inputs
194+
- "queued": cell is queued to run
195+
- "running": cell is running
196+
- "disabled-transitively": cell is disabled because a parent is disabled
197+
- None: state not set
198+
"""
189199
return self._status.state
190200

191201
@property
@@ -194,7 +204,11 @@ def run_result_status(self) -> Optional[RunResultStatusType]:
194204

195205
@property
196206
def sqls(self) -> list[str]:
197-
"""Return a list of SQL statements for this cell."""
207+
"""Returns parsed SQL statements from this cell.
208+
209+
Returns:
210+
list[str]: List of SQL statement strings parsed from the cell code.
211+
"""
198212
if self._sqls.parsed is not None:
199213
return self._sqls.parsed
200214

@@ -257,7 +271,12 @@ def is_coroutine(self) -> bool:
257271
def set_runtime_state(
258272
self, status: RuntimeStateType, stream: Stream | None = None
259273
) -> None:
260-
"""Set execution status and broadcast to frontends."""
274+
"""Sets the cell's execution status and broadcasts to frontends.
275+
276+
Args:
277+
status (RuntimeStateType): New runtime state to set
278+
stream (Stream | None, optional): Stream to broadcast on. Defaults to None.
279+
"""
261280
from marimo._messaging.ops import CellOp
262281
from marimo._runtime.context import (
263282
ContextNotInitializedError,
@@ -405,103 +424,104 @@ def run(
405424
tuple[Any, Mapping[str, Any]]
406425
| Awaitable[tuple[Any, Mapping[str, Any]]]
407426
):
408-
"""Run this cell and return its visual output and definitions
427+
"""
428+
Run this cell and return its visual output and definitions.
409429
410430
Use this method to run **named cells** and retrieve their output and
411-
definitions.
412-
413-
This lets you use reuse cells defined in one notebook in another
431+
definitions. This lets you reuse cells defined in one notebook in another
414432
notebook or Python file. It also makes it possible to write and execute
415433
unit tests for notebook cells using a test framework like `pytest`.
416434
417-
**Example.** marimo cells can be given names either through the
418-
editor cell menu or by manually changing the function name in the
419-
notebook file. For example, consider a notebook `notebook.py`:
420-
421-
```python
422-
import marimo
435+
Examples:
436+
marimo cells can be given names either through the editor cell menu
437+
or by manually changing the function name in the notebook file. For
438+
example, consider a notebook `notebook.py`:
423439
424-
app = marimo.App()
440+
```python
441+
import marimo
425442
443+
app = marimo.App()
426444
427-
@app.cell
428-
def __():
429-
import marimo as mo
430445
431-
return (mo,)
446+
@app.cell
447+
def __():
448+
import marimo as mo
432449
450+
return (mo,)
433451
434-
@app.cell
435-
def __():
436-
x = 0
437-
y = 1
438-
return (x, y)
439452
453+
@app.cell
454+
def __():
455+
x = 0
456+
y = 1
457+
return (x, y)
440458
441-
@app.cell
442-
def add(mo, x, y):
443-
z = x + y
444-
mo.md(f"The value of z is {z}")
445-
return (z,)
446459
460+
@app.cell
461+
def add(mo, x, y):
462+
z = x + y
463+
mo.md(f"The value of z is {z}")
464+
return (z,)
447465
448-
if __name__ == "__main__":
449-
app.run()
450-
```
451466
452-
To reuse the `add` cell in another notebook, you'd simply write
467+
if __name__ == "__main__":
468+
app.run()
469+
```
453470
454-
```python
455-
from notebook import add
471+
To reuse the `add` cell in another notebook, you'd simply write:
456472
457-
# `output` is the markdown rendered by `add`
458-
# defs["z"] == `1`
459-
output, defs = add.run()
460-
```
473+
```python
474+
from notebook import add
461475
462-
When `run` is called without arguments, it automatically computes the
463-
values that the cell depends on (in this case, `mo`, `x`, and `y`). You
464-
can override these values by providing any subset of them as keyword
465-
arguments. For example,
476+
# `output` is the markdown rendered by `add`
477+
# defs["z"] == `1`
478+
output, defs = add.run()
479+
```
466480
467-
```python
468-
# defs["z"] == 4
469-
output, defs = add.run(x=2, y=2)
470-
```
481+
When `run` is called without arguments, it automatically computes
482+
the values that the cell depends on (in this case, `mo`, `x`, and
483+
`y`). You can override these values by providing any subset of them
484+
as keyword arguments. For example,
471485
472-
**Defined UI Elements.** If the cell's `output` has UI elements
473-
that are in `defs`, interacting with the output in the frontend will
474-
trigger reactive execution of cells that reference the `defs` object.
475-
For example, if `output` has a slider defined by the cell, then
476-
scrubbing the slider will cause cells that reference `defs` to run.
486+
```python
487+
# defs["z"] == 4
488+
output, defs = add.run(x=2, y=2)
489+
```
477490
478-
**Async cells.** If this cell is a coroutine function (starting with
479-
`async`), or if any of its ancestors are coroutine functions, then
480-
you'll need to `await` the result: `output, defs = await cell.run()`.
481-
You can check whether the result is an awaitable using:
491+
Defined UI Elements:
492+
If the cell's `output` has UI elements that are in `defs`, interacting
493+
with the output in the frontend will trigger reactive execution of
494+
cells that reference the `defs` object. For example, if `output` has
495+
a slider defined by the cell, then scrubbing the slider will cause
496+
cells that reference `defs` to run.
482497
483-
```python
484-
from collections.abc import Awaitable
485-
486-
ret = cell.run()
487-
if isinstance(ret, Awaitable):
488-
output, defs = await ret
489-
else:
490-
output, defs = ret
491-
```
498+
Async cells:
499+
If this cell is a coroutine function (starting with `async`), or if
500+
any of its ancestors are coroutine functions, then you'll need to
501+
`await` the result: `output, defs = await cell.run()`. You can check
502+
whether the result is an awaitable using:
492503
493-
**Arguments**:
504+
```python
505+
from collections.abc import Awaitable
494506
495-
- You may pass values for any of this cell's references as keyword
496-
arguments. marimo will automatically compute values for any refs
497-
that are not provided by executing the parent cells that compute
498-
them.
507+
ret = cell.run()
508+
if isinstance(ret, Awaitable):
509+
output, defs = await ret
510+
else:
511+
output, defs = ret
512+
```
499513
500-
**Returns**:
514+
Args:
515+
**kwargs (Any):
516+
You may pass values for any of this cell's references as keyword
517+
arguments. marimo will automatically compute values for any refs
518+
that are not provided by executing the parent cells that compute
519+
them.
501520
502-
- a tuple `(output, defs)`, or an awaitable of the same, where `output`
503-
is the cell's last expression and `defs` is a `Mapping` from the
504-
cell's defined names to their values.
521+
Returns:
522+
tuple `(output, defs)`, or an awaitable of the same:
523+
`output` is the cell's last expression and `defs` is a `Mapping`
524+
from the cell's defined names to their values.
505525
"""
506526
assert self._app is not None
507527
if self._is_coroutine():

marimo/_plugins/stateless/mpl/_mpl.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -332,21 +332,18 @@ def interactive(figure: Union[Figure, SubFigure, Axes]) -> Html:
332332
The interactive viewer allows you to pan, zoom, and see plot coordinates
333333
on mouse hover.
334334
335-
**Example**:
336-
337-
```python
338-
plt.plot([1, 2])
339-
# plt.gcf() gets the current figure
340-
mo.mpl.interactive(plt.gcf())
341-
```
342-
343-
**Args**:
344-
345-
- figure: a matplotlib `Figure` or `Axes` object
346-
347-
**Returns**:
348-
349-
- An interactive matplotlib figure as an `Html` object
335+
Example:
336+
```python
337+
plt.plot([1, 2])
338+
# plt.gcf() gets the current figure
339+
mo.mpl.interactive(plt.gcf())
340+
```
341+
342+
Args:
343+
figure (matplotlib Figure or Axes): A matplotlib `Figure` or `Axes` object.
344+
345+
Returns:
346+
Html: An interactive matplotlib figure as an `Html` object.
350347
"""
351348
# We can't support interactive plots in Pyodide
352349
# since they require a WebSocket connection

marimo/_runtime/app_meta.py

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@
44
from typing import Literal, Optional
55

66
from marimo._config.config import DEFAULT_CONFIG
7+
from marimo._output.rich_help import mddoc
78
from marimo._runtime.context.types import (
89
ContextNotInitializedError,
910
get_context,
1011
)
1112
from marimo._runtime.context.utils import get_mode
1213

1314

15+
@mddoc
1416
class AppMeta:
15-
"""
16-
Metadata about the app.
17+
"""Metadata about the app.
1718
1819
This class provides access to runtime metadata about a marimo app, such as
1920
its display theme and execution mode.
@@ -23,25 +24,21 @@ class AppMeta:
2324
def theme(self) -> str:
2425
"""The display theme of the app.
2526
26-
Returns either "light" or "dark". If the user's configuration is set to
27-
"system", currently returns "light".
28-
29-
**Examples**:
30-
31-
Get the current theme and conditionally set a plotting library's theme:
32-
33-
```python
34-
import altair as alt
27+
Returns:
28+
str: Either "light" or "dark". If the user's configuration is set to
29+
"system", currently returns "light".
3530
36-
# Enable dark theme for Altair when marimo is in dark mode
37-
alt.themes.enable(
38-
"dark" if mo.app_meta().theme == "dark" else "default"
39-
)
40-
```
31+
Examples:
32+
Get the current theme and conditionally set a plotting library's theme:
4133
42-
**Returns**:
34+
```python
35+
import altair as alt
4336
44-
- "light" or "dark", indicating the app's display theme
37+
# Enable dark theme for Altair when marimo is in dark mode
38+
alt.themes.enable(
39+
"dark" if mo.app_meta().theme == "dark" else "default"
40+
)
41+
```
4542
"""
4643
try:
4744
context = get_context()
@@ -57,22 +54,21 @@ def theme(self) -> str:
5754

5855
@property
5956
def mode(self) -> Optional[Literal["edit", "run", "script"]]:
60-
"""The execution mode of the app.
61-
62-
**Examples**:
63-
64-
Show content only in edit mode:
57+
"""
58+
The execution mode of the app.
6559
66-
```python
67-
# Only show this content when editing the notebook
68-
mo.md("# Developer Notes") if mo.app_meta().mode == "edit" else None
69-
```
60+
Examples:
61+
Show content only in edit mode:
7062
71-
**Returns**:
63+
```python
64+
# Only show this content when editing the notebook
65+
mo.md("# Developer Notes") if mo.app_meta().mode == "edit" else None
66+
```
7267
73-
- "edit": The notebook is being edited in the marimo editor
74-
- "run": The notebook is being run as an app
75-
- "script": The notebook is being run as a script
76-
- None: The mode could not be determined
68+
Returns:
69+
- "edit": The notebook is being edited in the marimo editor
70+
- "run": The notebook is being run as an app
71+
- "script": The notebook is being run as a script
72+
- None: The mode could not be determined
7773
"""
7874
return get_mode()

0 commit comments

Comments
 (0)