Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: update docstrings to Google Style format #3218

Merged
merged 2 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 20 additions & 21 deletions marimo/_plugins/stateless/flex.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,17 @@ def vstack(

Args:
items (Sequence[object]): A list of items.
align (Literal["start", "end", "center", "stretch"], optional): Align items
align (Optional[Literal["start", "end", "center", "stretch"]]): Align items
horizontally: start, end, center, or stretch.
justify (Literal["start", "center", "end", "space-between", "space-around"]):
Justify items vertically: start, center, end, space-between, or space-around.
Defaults to "start".
gap (float, optional): Gap between items as a float in rem. 1rem is 16px by default.
gap (float): Gap between items as a float in rem. 1rem is 16px by default.
Defaults to 0.5.
heights (Union[Literal["equal"], Sequence[float]], optional): "equal" to give items
heights (Optional[Literal["equal"] | Sequence[float]]): "equal" to give items
equal height; or a list of relative heights with same length as `items`,
eg, [1, 2] means the second item is twice as tall as the first;
or None for a sensible default.
eg, [1, 2] means the second item is twice as tall as the first; or None
for a sensible default.

Returns:
Html: An Html object.
Expand Down Expand Up @@ -168,15 +168,15 @@ def hstack(
justify (Literal["start", "center", "end", "space-between", "space-around"]):
Justify items horizontally: start, center, end, space-between, or space-around.
Defaults to "space-between".
align (Literal["start", "end", "center", "stretch"], optional): Align items
align (Optional[Literal["start", "end", "center", "stretch"]]): Align items
vertically: start, end, center, or stretch.
wrap (bool, optional): Wrap items or not. Defaults to False.
gap (float, optional): Gap between items as a float in rem. 1rem is 16px by default.
wrap (bool): Wrap items or not. Defaults to False.
gap (float): Gap between items as a float in rem. 1rem is 16px by default.
Defaults to 0.5.
widths (Union[Literal["equal"], Sequence[float]], optional): "equal" to give items
widths (Optional[Literal["equal"] | Sequence[float]]): "equal" to give items
equal width; or a list of relative widths with same length as `items`,
eg, [1, 2] means the second item is twice as wide as the first;
or None for a sensible default.
eg, [1, 2] means the second item is twice as wide as the first; or None
for a sensible default.

Returns:
Html: An Html object.
Expand Down Expand Up @@ -208,17 +208,16 @@ def _spaced(
A grid built with this function has a fixed number of items per row.
For more flexibility, use `hstack` and `vstack`.

**Args.**

- `items`: Items to arrange
- `justify`: Justify items normally, left, right, or center.
- `items_per_row`: Number of items to place in each row
- `column_gap`: Minimum gap in rem between columns
- `row_gap`: Minimum gap in rem between rows

**Returns.**
Args:
items (Sequence[object]): Items to arrange
justify (Literal["left", "right", "center", "normal"]): Justify items normally,
left, right, or center.
items_per_row (Optional[int]): Number of items to place in each row
column_gap (float): Minimum gap in rem between columns
row_gap (float): Minimum gap in rem between rows

- An `Html` object.
Returns:
Html: An `Html` object.
"""
items_per_row = len(items) if items_per_row is None else items_per_row
style = create_style(
Expand Down
44 changes: 20 additions & 24 deletions marimo/_plugins/stateless/icon.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ def icon(
rotate: Optional[Literal["90deg", "180deg", "270deg"]] = None,
style: Optional[dict[str, Union[str, int, float, None]]] = None,
) -> Html:
"""
Displays an icon. These icons are referenced by name from the
"""Displays an icon. These icons are referenced by name from the
[Iconify](https://iconify.design/) library.

They are named in the format `icon-set:icon-name`, e.g.
Expand All @@ -34,29 +33,26 @@ def icon(

These can be used in buttons, tabs, and other UI elements.

**Examples.**

```python
mo.md(f"# {mo.icon('lucide:leaf')} Leaf")

mo.ui.button(
label=f"{mo.icon('lucide:rocket')} Submit",
)
```

**Args.**

- `icon_name`: the name of the icon to display
- `size`: the size of the icon in pixels
- `color`: the color of the icon
- `inline`: whether to display the icon inline or as a block element
- `flip`: whether to flip the icon horizontally, vertically, or both
- `rotate`: whether to rotate the icon 90, 180, or 270 degrees
- `style`: a dictionary of CSS styles to apply to the icon
Examples:
```python
mo.md(f"# {mo.icon('lucide:leaf')} Leaf")

**Returns.**

- An `Html` object.
mo.ui.button(
label=f"{mo.icon('lucide:rocket')} Submit",
)
```

Args:
icon_name: the name of the icon to display
size: the size of the icon in pixels
color: the color of the icon
inline: whether to display the icon inline or as a block element
flip: whether to flip the icon horizontally, vertically, or both
rotate: whether to rotate the icon 90, 180, or 270 degrees
style: a dictionary of CSS styles to apply to the icon

Returns:
Html: An `Html` object.
"""

if style is None:
Expand Down
43 changes: 20 additions & 23 deletions marimo/_plugins/stateless/pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,29 @@ def pdf(
This currently uses the native browser PDF viewer,
but may be replaced with a custom viewer.

**Example.**

```python3
mo.pdf(
src="https://arxiv.org/pdf/2104.00282.pdf",
width="100%",
height="50vh",
)

with open("paper.pdf", "rb") as file:
mo.pdf(src=file)
```

**Args.**
Example:
```python3
mo.pdf(
src="https://arxiv.org/pdf/2104.00282.pdf",
width="100%",
height="50vh",
)

- `src`: the URL of the pdf or a file-like object
- `initial_page`: the page to open the pdf to.
only works if `src` is a URL
- `width`: the width of the pdf
- `height`: the height of the pdf. for a percentage
of the user's viewport, use a string like `"50vh"`
- `style`: a dictionary of CSS styles to apply to the pdf
with open("paper.pdf", "rb") as file:
mo.pdf(src=file)
```

**Returns.**
Args:
src: the URL of the pdf or a file-like object
initial_page: the page to open the pdf to.
only works if `src` is a URL
width: the width of the pdf
height: the height of the pdf. for a percentage
of the user's viewport, use a string like `"50vh"`
style: a dictionary of CSS styles to apply to the pdf

`Html` object
Returns:
`Html` object
"""
resolved_src = src if isinstance(src, str) else mo_data.pdf(src.read()).url
if initial_page is not None and isinstance(src, str):
Expand Down
19 changes: 9 additions & 10 deletions marimo/_plugins/stateless/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,17 @@ def tree(
) -> Html:
"""Render a nested structure of lists, tuples, or dicts as a tree.

**Example.**
```python3
mo.tree(["entry", "another entry", {"key": [0, 1, 2]}], label="A tree.")
```
**Args.**
Example:
```python3
mo.tree(["entry", "another entry", {"key": [0, 1, 2]}], label="A tree.")
```

- `items`: nested structure of lists, tuples, or dicts
- `label`: optional text label for the tree
Args:
items: nested structure of lists, tuples, or dicts
label: optional text label for the tree

**Returns.**

`Html` object
Returns:
Html: `Html` object
"""
if not isinstance(items, (list, tuple, dict)):
raise ValueError(
Expand Down
41 changes: 19 additions & 22 deletions marimo/_plugins/stateless/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,27 @@ def video(
) -> Html:
"""Render an video as HTML.

**Example.**

```python3
mo.video(
src="https://v3.cdnpk.net/videvo_files/video/free/2013-08/large_watermarked/hd0992_preview.mp4",
controls=False,
)
```

**Args.**

- `src`: the URL of the video or a file-like object
- `controls`: whether to show the controls
- `muted`: whether to mute the video
- `autoplay`: whether to autoplay the video.
the video will only autoplay if `muted` is `True`
- `loop`: whether to loop the video
- `width`: the width of the video in pixels or a string with units
- `height`: the height of the video in pixels or a string with units
- `rounded`: whether to round the corners of the video
Example:
```python3
mo.video(
src="https://v3.cdnpk.net/videvo_files/video/free/2013-08/large_watermarked/hd0992_preview.mp4",
controls=False,
)
```

**Returns.**
Args:
src: the URL of the video or a file-like object
controls: whether to show the controls
muted: whether to mute the video
autoplay: whether to autoplay the video.
the video will only autoplay if `muted` is `True`
loop: whether to loop the video
width: the width of the video in pixels or a string with units
height: the height of the video in pixels or a string with units
rounded: whether to round the corners of the video

`Html` object
Returns:
`Html` object
"""
# Convert to bytes right away since can only be read once
if isinstance(src, io.BufferedReader):
Expand Down
Loading