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

Add example template #2392

Merged
merged 23 commits into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
80ca0df
add example templates
jprochazk Jun 12, 2023
5ae543d
update `python/template/main.py`
jprochazk Jun 12, 2023
dceb7d3
remove unused arg
jprochazk Jun 12, 2023
281c368
Merge branch 'main' into jan/example-template
jprochazk Jun 13, 2023
e7b4e82
Update examples/python/template/README.md
jprochazk Jun 13, 2023
3037bb3
Update examples/python/template/main.py
jprochazk Jun 13, 2023
226125c
Update examples/python/template/README.md
jprochazk Jun 13, 2023
da29309
Update examples/python/template/main.py
jprochazk Jun 13, 2023
58a4eeb
Update examples/python/template/main.py
jprochazk Jun 13, 2023
556f586
Update examples/python/template/main.py
jprochazk Jun 13, 2023
e8edfbe
Update examples/rust/template/src/main.rs
jprochazk Jun 13, 2023
e2e1bc5
Update examples/rust/template/README.md
jprochazk Jun 13, 2023
ec9cd7a
Update examples/python/template/main.py
jprochazk Jun 13, 2023
4081e04
add tags to example templates
jprochazk Jun 13, 2023
d4c7c3e
fix format
jprochazk Jun 13, 2023
faedbba
Update examples/python/template/main.py
jprochazk Jun 13, 2023
05bd8ca
Merge branch 'main' into jan/example-template
jprochazk Jun 13, 2023
327a1e5
remove log forwarding
jprochazk Jun 13, 2023
5870638
explain how to take screenshot
jprochazk Jun 13, 2023
68f2b58
Merge branch 'main' into jan/example-template
jprochazk Jun 16, 2023
29ac31d
update readmes
jprochazk Jun 16, 2023
43bebd5
hint to use `python` instead of running as executable
jprochazk Jun 16, 2023
139360d
Merge branch 'main' into jan/example-template
jprochazk Jun 16, 2023
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
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,8 @@ python: https://github.com/rerun-io/rerun/tree/latest/examples/python/tracking_h
The contents of this `README.md` file and its frontmatter are used to render the examples in [the documentation](https://rerun.io/examples). Individual examples are currently "stitched together" to form one large markdown file for every category of examples (`artificial-data`, `real-data`).

The `manifest.yml` file describes the structure of the examples contained in this repository. Only the examples which appear in the manifest are included in the [generated documentation](https://rerun.io/examples). The file contains a description of its own format.

## Adding a new example

You can base your example off of `python/template` or `rust/template`.
Once it's ready to be displayed in the docs, add it to the [manifest](./manifest.yml).
1 change: 1 addition & 0 deletions examples/python/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@
-r ros/requirements.txt
-r segment_anything/requirements.txt
-r stable_diffusion/requirements.txt
-r template/requirements.txt
-r text_logging/requirements.txt
-r tracking_hf_opencv/requirements.txt
15 changes: 15 additions & 0 deletions examples/python/template/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
title: Template
jprochazk marked this conversation as resolved.
Show resolved Hide resolved
tags: [kebab-case, comma, separated]
python: https://github.com/rerun-io/rerun/tree/latest/examples/python/template/main.py
rust: https://github.com/rerun-io/rerun/tree/latest/examples/rust/template/src/main.rs
---

<!-- Place a screenshot here -->
Copy link
Member

Choose a reason for hiding this comment

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

Link to how we upload screenshots?

Copy link
Member Author

Choose a reason for hiding this comment

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

We don't have this documented anywhere outside of an issue, so I included some instructions directly in there

Copy link
Member

Choose a reason for hiding this comment

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

It's a good point. I'll add this bit of information in just upload --help so we can refer to that.

Copy link
Member

Choose a reason for hiding this comment

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

You may review/merge #2454 at your convenience so you can update that part.

Copy link
Member Author

Choose a reason for hiding this comment

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

Update to point to just upload --help


This is an example example. It is not a real example. You can duplicate the directory and use it as a starting point for writing a real example.

```bash
pip install -r examples/python/template/requirements.txt
examples/python/template/main.py
```
44 changes: 44 additions & 0 deletions examples/python/template/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env python3
"""
Example template.

Run:
```sh
pip install -r examples/python/template/requirements.txt
./examples/python/template/main.py
jprochazk marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

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

In a context of examples and when the use of venv is mandated, I'd say it's more standard to call python explicitly:

python examples/python/template/main.py

I'd also remove the #! line altogether. It's weird outside of "script" context.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think keeping the shebang is fine, since it doesn't hurt anything, and some people may want to run the example directly as if it was an executable

```
"""
from __future__ import annotations

import argparse
import logging

import rerun as rr # pip install rerun-sdk


def setup_logging() -> None:
# Forward all text logs to Rerun by attaching a handler directly to the root logger,
# which will catch events from all loggers going forward (propagation is on by
# default).
#
# For more info: https://docs.python.org/3/howto/logging.html#handlers
logging.getLogger().addHandler(rr.log.text.LoggingHandler())
logging.getLogger().setLevel(-1)
Copy link
Member

Choose a reason for hiding this comment

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

I think we should either remove this or clarify that this is just an example of what you can do in the case where you want to get python logs into Rerun

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed it as its probably too specific for an example template



def main() -> None:
parser = argparse.ArgumentParser(description="Describe your example here!")
jprochazk marked this conversation as resolved.
Show resolved Hide resolved
rr.script_add_args(parser)
args = parser.parse_args()

rr.script_setup(args, "my_example_name")

setup_logging()

# ... example code

rr.script_teardown(args)


if __name__ == "__main__":
main()
1 change: 1 addition & 0 deletions examples/python/template/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rerun-sdk
10 changes: 10 additions & 0 deletions examples/rust/template/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "template"
version = "0.7.0-alpha.0"
edition = "2021"
rust-version = "1.69"
license = "MIT OR Apache-2.0"
publish = false

[dependencies]
rerun = { path = "../../../crates/rerun", features = ["native_viewer"] }
15 changes: 15 additions & 0 deletions examples/rust/template/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
title: Template
jprochazk marked this conversation as resolved.
Show resolved Hide resolved
tags: [kebab-case, comma, separated]
python: https://github.com/rerun-io/rerun/tree/latest/examples/python/template/main.py
rust: https://github.com/rerun-io/rerun/tree/latest/examples/rust/template/src/main.rs
---

<!-- Place a screenshot here -->

This is an example example. It is not a real example. You can duplicate the directory and use it as a starting point for writing a real example.

```bash
cargo run --release -p template
```

15 changes: 15 additions & 0 deletions examples/rust/template/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//! Example template.

use rerun::RecordingStreamBuilder;

fn main() -> Result<(), Box<dyn std::error::Error>> {
let (rec_stream, storage) = RecordingStreamBuilder::new("my_example_name").memory()?;

let _ = rec_stream;

// ... example code

rerun::native_viewer::show(storage.take())?;

Ok(())
}