Skip to content

Commit

Permalink
Update all of the docstrings on public-facing APIs to numpy style (#1001
Browse files Browse the repository at this point in the history
)

* Update __init__.py

* More docstrings

* lints

* Tweak the material class template

* Add some extra spacing

* Docstrings for the dataclasses

* Update obb docstring

* docstrings for camera

* docstrings for meshes and images

* More docstring linting

* docstrings for lines

* Docstrings for images

* docstrings for points

* docstrings for rects

* Docstrings for scalar

* Docstrings for tensor

* Docstrings for text

* docstrings for transforms

* Make tabs sticky

* Revert usage of type subscriptions since not in python 3.8

* unused import

* Fix docstring for rerun.init()

* Consistency in points doc
  • Loading branch information
jleibs committed Jan 31, 2023
1 parent 52c752a commit 1838b71
Show file tree
Hide file tree
Showing 20 changed files with 656 additions and 183 deletions.
1 change: 1 addition & 0 deletions rerun_py/docs/common/SUMMARY.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
* [Initialization](initialization.md)
* [Logging Primitives](primitives.md)
* [Logging Images](images.md)
* [Annotations](annotation.md)
* [Plotting](plotting.md)
* [Transforms](transforms.md)
1 change: 1 addition & 0 deletions rerun_py/docs/common/annotation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
::: rerun.log_annotation_context
1 change: 0 additions & 1 deletion rerun_py/docs/common/images.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@
::: rerun.log_image_file
::: rerun.log_depth_image
::: rerun.log_segmentation_image
::: rerun.log_annotation_context
5 changes: 5 additions & 0 deletions rerun_py/docs/css/mkdocstrings.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,8 @@ div.doc-contents:not(.first) {
td code {
word-break: normal !important;
}

/* Add extra spacing between doc-objects. */
div.doc-object {
margin-bottom: 2rem;
}
123 changes: 123 additions & 0 deletions rerun_py/docs/templates/python/material/class.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
{# Very minimally patched from:
https://github.com/mkdocstrings/python/blob/master/src/mkdocstrings_handlers/python/templates/material/_base/class.html

See: CHANGE comments below
#}

{{ log.debug("Rendering " + class.path) }}

<div class="doc doc-object doc-class">
{% with html_id = class.path %}

{% if root %}
{% set show_full_path = config.show_root_full_path %}
{% set root_members = True %}
{% elif root_members %}
{% set show_full_path = config.show_root_members_full_path or config.show_object_full_path %}
{% set root_members = False %}
{% else %}
{% set show_full_path = config.show_object_full_path %}
{% endif %}

{% if not root or config.show_root_heading %}

{% filter heading(heading_level,
role="class",
id=html_id,
class="doc doc-heading",
toc_label=class.name) %}

{% if config.separate_signature %}
<span class="doc doc-object-name doc-class-name">{% if show_full_path %}{{ class.path }}{% else %}{{ class.name }}{% endif %}</span>
{% elif config.merge_init_into_class and "__init__" in class.members -%}
{%- with function = class.members["__init__"] -%}
{%- filter highlight(language="python", inline=True) -%}
{# CHANGE: Insert class before class for better highlighting #}
class {% if show_full_path %}{{ class.path }}{% else %}{{ class.name }}{% endif %}
{%- include "signature.html" with context -%}
{%- endfilter -%}
{%- endwith -%}
{% else %}
{# CHANGE: Insert class before class for better highlighting #}
{%- filter highlight(language="python", inline=True) -%}
class {% if show_full_path %}{{ class.path }}{% else %}{{ class.name }}{% endif %}
{%- endfilter -%}
{% endif %}

{% with labels = class.labels %}
{% include "labels.html" with context %}
{% endwith %}

{% endfilter %}

{% if config.separate_signature and config.merge_init_into_class %}
{% if "__init__" in class.members %}
{% with function = class.members["__init__"] %}
{% filter highlight(language="python", inline=False) %}
{% filter format_signature(config.line_length) %}
{% if show_full_path %}{{ class.path }}{% else %}{{ class.name }}{% endif %}
{% include "signature.html" with context %}
{% endfilter %}
{% endfilter %}
{% endwith %}
{% endif %}
{% endif %}

{% else %}
{% if config.show_root_toc_entry %}
{% filter heading(heading_level,
role="class",
id=html_id,
toc_label=class.path if config.show_root_full_path else class.name,
hidden=True) %}
{% endfilter %}
{% endif %}
{% set heading_level = heading_level - 1 %}
{% endif %}

<div class="doc doc-contents {% if root %}first{% endif %}">
{% if config.show_bases and class.bases %}
<p class="doc doc-class-bases">
Bases: {% for expression in class.bases -%}
<code>{% include "expression.html" with context %}</code>{% if not loop.last %}, {% endif %}
{% endfor -%}
</p>
{% endif %}

{% with docstring_sections = class.docstring.parsed %}
{% include "docstring.html" with context %}
{% endwith %}

{% if config.merge_init_into_class %}
{% if "__init__" in class.members and class.members["__init__"].has_docstring %}
{% with docstring_sections = class.members["__init__"].docstring.parsed %}
{% include "docstring.html" with context %}
{% endwith %}
{% endif %}
{% endif %}

{% if config.show_source %}
{% if config.merge_init_into_class %}
{% if "__init__" in class.members and class.members["__init__"].source %}
<details class="quote">
<summary>Source code in <code>{{ class.relative_filepath }}</code></summary>
{{ class.members["__init__"].source|highlight(language="python", linestart=class.members["__init__"].lineno, linenums=True) }}
</details>
{% endif %}
{% elif class.source %}
<details class="quote">
<summary>Source code in <code>{{ class.relative_filepath }}</code></summary>
{{ class.source|highlight(language="python", linestart=class.lineno, linenums=True) }}
</details>
{% endif %}
{% endif %}

{% with obj = class %}
{% set root = False %}
{% set heading_level = heading_level + 1 %}
{% include "children.html" with context %}
{% endwith %}
</div>

{% endwith %}
</div>
8 changes: 5 additions & 3 deletions rerun_py/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ repo_url: https://github.com/rerun-io/rerun/
theme:
name: "material"
features:
- navigation.tabs
- navigation.instant
- navigation.expand
- navigation.indexes
- navigation.instant
- navigation.tabs
- navigation.tabs.sticky
- navigation.tracking
- navigation.expand

plugins:
- search # https://squidfunk.github.io/mkdocs-material/setup/setting-up-site-search/
Expand All @@ -31,6 +32,7 @@ plugins:
members_order: source
heading_level: 3
show_root_heading: true
merge_init_into_class: true
- gen-files: # https://oprypin.github.io/mkdocs-gen-files
scripts:
- docs/gen_package_index.py
Expand Down
74 changes: 69 additions & 5 deletions rerun_py/rerun/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ def get_recording_id() -> str:
processes to log to the same Rerun instance (and be part of the same recording),
you will need to manually assign them all the same recording_id.
Any random UUIDv4 will work, or copy the recording id for the parent process.
Returns
-------
str
The recording ID that this process is logging to.
"""
return str(bindings.get_recording_id())

Expand All @@ -90,6 +96,12 @@ def set_recording_id(value: str) -> None:
processes to log to the same Rerun instance (and be part of the same recording),
you will need to manually assign them all the same recording_id.
Any random UUIDv4 will work, or copy the recording id for the parent process.
Parameters
----------
value : str
The recording ID to use for this process.
"""
bindings.set_recording_id(value)

Expand All @@ -107,7 +119,6 @@ def init(application_id: str, spawn_and_connect: bool = False) -> None:
For instance, if you have one application doing object detection
and another doing camera calibration, you could have
`rerun.init("object_detector")` and `rerun.init("calibrator")`.
spawn_and_connect : bool
Spawn a Rerun Viewer and stream logging data to it.
Short for calling `spawn_and_connect` separately.
Expand Down Expand Up @@ -143,7 +154,15 @@ def spawn_and_connect(port: int = 9876) -> None:
This is often the easiest and best way to use Rerun.
Just call this once at the start of your program.
See also: rerun.connect
Parameters
----------
port : int
The port to connect to
See Also
--------
* [rerun.connect][]
"""
spawn_viewer(port)
connect(f"127.0.0.1:{port}")
Expand All @@ -157,12 +176,26 @@ def connect(addr: Optional[str] = None) -> None:
Connect to a remote Rerun Viewer on the given ip:port.
Requires that you first start a Rerun Viewer, e.g. with 'python -m rerun'
Parameters
----------
addr : str
The ip:port to connect to
"""
bindings.connect(addr)


def spawn_viewer(port: int = 9876) -> None:
"""Spawn a Rerun Viewer, listening on the given port."""
"""
Spawn a Rerun Viewer, listening on the given port.
Parameters
----------
port : int
The port to listen on.
"""
import subprocess
import sys
from time import sleep
Expand Down Expand Up @@ -205,6 +238,7 @@ def show() -> None:
This will clear the logged data after showing it.
NOTE: There is a bug which causes this function to only work once on some platforms.
"""
bindings.show()

Expand All @@ -216,13 +250,19 @@ def save(path: str) -> None:
This only works if you have not called `connect`.
This will clear the logged data after saving.
Parameters
----------
path : str
The path to save the data to.
"""
bindings.save(path)


def set_time_sequence(timeline: str, sequence: Optional[int]) -> None:
"""
Set the current time for this thread.
Set the current time for this thread as an integer sequence.
Used for all subsequent logging on the same thread,
until the next call to `set_time_sequence`.
Expand All @@ -232,13 +272,21 @@ def set_time_sequence(timeline: str, sequence: Optional[int]) -> None:
You can remove a timeline again using `set_time_sequence("frame_nr", None)`.
There is no requirement of monoticity. You can move the time backwards if you like.
Parameters
----------
timeline : str
The name of the timeline to set the time for.
sequence : int
The current time on the timeline in integer units.
"""
bindings.set_time_sequence(timeline, sequence)


def set_time_seconds(timeline: str, seconds: Optional[float]) -> None:
"""
Set the current time for this thread.
Set the current time for this thread in seconds.
Used for all subsequent logging on the same thread,
until the next call to `set_time_seconds`.
Expand All @@ -254,6 +302,14 @@ def set_time_seconds(timeline: str, seconds: Optional[float]) -> None:
since unix epoch.
There is no requirement of monoticity. You can move the time backwards if you like.
Parameters
----------
timeline : str
The name of the timeline to set the time for.
seconds : float
The current time on the timeline in seconds.
"""
bindings.set_time_seconds(timeline, seconds)

Expand All @@ -276,5 +332,13 @@ def set_time_nanos(timeline: str, nanos: Optional[int]) -> None:
unix epoch.
There is no requirement of monoticity. You can move the time backwards if you like.
Parameters
----------
timeline : str
The name of the timeline to set the time for.
nanos : int
The current time on the timeline in nanoseconds.
"""
bindings.set_time_nanos(timeline, nanos)
Loading

1 comment on commit 1838b71

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rust Benchmark

Benchmark suite Current: 1838b71 Previous: 52c752a Ratio
datastore/insert/batch/rects/insert 576466 ns/iter (± 1687) 559409 ns/iter (± 7203) 1.03
datastore/latest_at/batch/rects/query 1789 ns/iter (± 5) 1744 ns/iter (± 18) 1.03
datastore/latest_at/missing_components/primary 305 ns/iter (± 7) 303 ns/iter (± 11) 1.01
datastore/latest_at/missing_components/secondaries 380 ns/iter (± 0) 362 ns/iter (± 4) 1.05
datastore/range/batch/rects/query 155625 ns/iter (± 232) 152112 ns/iter (± 2680) 1.02
mono_points_arrow/generate_message_bundles 47435847 ns/iter (± 821056) 43478086 ns/iter (± 1530536) 1.09
mono_points_arrow/generate_messages 126132452 ns/iter (± 1210529) 121762850 ns/iter (± 1478126) 1.04
mono_points_arrow/encode_log_msg 151815575 ns/iter (± 2491572) 149258659 ns/iter (± 2059181) 1.02
mono_points_arrow/encode_total 328116379 ns/iter (± 2494487) 317524430 ns/iter (± 4600271) 1.03
mono_points_arrow/decode_log_msg 175001643 ns/iter (± 1057898) 168648389 ns/iter (± 2272806) 1.04
mono_points_arrow/decode_message_bundles 64660158 ns/iter (± 744780) 61807097 ns/iter (± 1004534) 1.05
mono_points_arrow/decode_total 236472215 ns/iter (± 2105614) 230549080 ns/iter (± 2653979) 1.03
batch_points_arrow/generate_message_bundles 331138 ns/iter (± 468) 319180 ns/iter (± 5103) 1.04
batch_points_arrow/generate_messages 6271 ns/iter (± 19) 6042 ns/iter (± 102) 1.04
batch_points_arrow/encode_log_msg 362172 ns/iter (± 1106) 354499 ns/iter (± 3378) 1.02
batch_points_arrow/encode_total 721118 ns/iter (± 5048) 704017 ns/iter (± 7150) 1.02
batch_points_arrow/decode_log_msg 346874 ns/iter (± 733) 341247 ns/iter (± 2541) 1.02
batch_points_arrow/decode_message_bundles 2133 ns/iter (± 4) 2064 ns/iter (± 34) 1.03
batch_points_arrow/decode_total 354284 ns/iter (± 2166) 346697 ns/iter (± 3436) 1.02
arrow_mono_points/insert 5988440665 ns/iter (± 20666088) 6000823830 ns/iter (± 28763766) 1.00
arrow_mono_points/query 1689782 ns/iter (± 24024) 1674978 ns/iter (± 21422) 1.01
arrow_batch_points/insert 2643441 ns/iter (± 59990) 2570384 ns/iter (± 21795) 1.03
arrow_batch_points/query 17380 ns/iter (± 64) 16896 ns/iter (± 266) 1.03
tuid/Tuid::random 34 ns/iter (± 0) 34 ns/iter (± 0) 1

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.