Skip to content

Commit

Permalink
Add example template (#2392)
Browse files Browse the repository at this point in the history
<!--
Open the PR up as a draft until you feel it is ready for a proper
review.

Do not make PR:s from your own `main` branch, as that makes it difficult
for reviewers to add their own fixes.

Add any improvements to the branch as new commits to make it easier for
reviewers to follow the progress. All commits will be squashed to a
single commit once the PR is merged into `main`.

Make sure you mention any issues that this PR closes in the description,
as well as any other related issues.

To get an auto-generated PR description you can put "copilot:summary" or
"copilot:walkthrough" anywhere.
-->

### What

Closes #2313

### Checklist
* [ ] I have read and agree to [Contributor
Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and
the [Code of
Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md)
* [ ] I've included a screenshot or gif (if applicable)

<!-- This line will get updated when the PR build summary job finishes.
-->
PR Build Summary: https://build.rerun.io/pr/2392

<!-- pr-link-docs:start -->
Docs preview: https://rerun.io/preview/139360d/docs
Examples preview: https://rerun.io/preview/139360d/examples
<!-- pr-link-docs:end -->

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
  • Loading branch information
jprochazk and emilk authored Jun 16, 2023
1 parent e436820 commit ddb1f6c
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 1 deletion.
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 @@ -41,3 +41,8 @@ tags: [2D, huggingface, object-detection, object-tracking, opencv]
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).
3 changes: 2 additions & 1 deletion examples/python/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@
-r segment_anything_model/requirements.txt
-r signed_distance_fields/requirements.txt
-r structure_from_motion/requirements.txt
-r text_logging/requirements.txt
-r template/requirements.txt
-r text_logging/requirements.txt
18 changes: 18 additions & 0 deletions examples/python/template/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
title: Template
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 in place of this comment
Use `just upload --help` for instructions
-->

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
python examples/python/template/main.py
```
31 changes: 31 additions & 0 deletions examples/python/template/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env python3
"""
Example template.
Run:
```sh
pip install -r examples/python/template/requirements.txt
python examples/python/template/main.py
```
"""
from __future__ import annotations

import argparse

import rerun as rr # pip install rerun-sdk


def main() -> None:
parser = argparse.ArgumentParser(description="Example of using the Rerun visualizer")
rr.script_add_args(parser)
args = parser.parse_args()

rr.script_setup(args, "my_example_name")

# ... 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"] }
18 changes: 18 additions & 0 deletions examples/rust/template/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
title: Template
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 in place of this comment
Use `just upload --help` for instructions
-->

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(())
}

0 comments on commit ddb1f6c

Please sign in to comment.