-
Notifications
You must be signed in to change notification settings - Fork 283
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SDK
DataLoader
s 2: barebones Python support (#5328)
Exposes raw `DataLoader`s to the Python SDK through 2 new methods: `RecordingStream.log_file_from_path` & `RecordingStream.log_file_from_contents`. Everything streams asynchronously, as expected. There's no way to configure the behavior of the `DataLoader` at all, yet. That comes next. ```python rr.log_file_from_path(filepath) ``` ![image](https://github.com/rerun-io/rerun/assets/2910679/0fe2d39c-f069-44a6-b836-e31001b3adaa) --- Part of series of PR to expose configurable `DataLoader`s to our SDKs: - #5327 - #5328 - #5330 - #5337 - #5351 - #5355
- Loading branch information
Showing
8 changed files
with
189 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!--[metadata] | ||
title = "Log file example" | ||
--> | ||
|
||
Demonstrates how to log any file from the SDK using the [`DataLoader`](https://www.rerun.io/docs/howto/open-any-file) machinery. | ||
|
||
Usage: | ||
```bash | ||
python examples/python/log_file/main.py examples/assets | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/usr/bin/env python3 | ||
""" | ||
Demonstrates how to log any file from the SDK using the `DataLoader` machinery. | ||
See <https://www.rerun.io/docs/howto/open-any-file> for more information. | ||
Usage: | ||
``` | ||
python examples/python/log_file/main.py -- examples/assets | ||
``` | ||
""" | ||
from __future__ import annotations | ||
|
||
import argparse | ||
from pathlib import Path | ||
|
||
import rerun as rr # pip install rerun-sdk | ||
|
||
parser = argparse.ArgumentParser( | ||
description="Demonstrates how to log any file from the SDK using the `DataLoader` machinery." | ||
) | ||
rr.script_add_args(parser) | ||
parser.add_argument( | ||
"--from-contents", | ||
action="store_true", | ||
default=False, | ||
help="Log the contents of the file directly (files only -- not supported by external loaders).", | ||
) | ||
parser.add_argument("filepaths", nargs="+", type=Path, help="The filepaths to be loaded and logged.") | ||
args = parser.parse_args() | ||
|
||
rr.script_setup(args, "rerun_example_log_file") | ||
|
||
for filepath in args.filepaths: | ||
if not args.from_contents: | ||
# Either log the file using its path… | ||
rr.log_file_from_path(filepath) | ||
else: | ||
# …or using its contents if you already have them loaded for some reason. | ||
try: | ||
with open(filepath, "rb") as file: | ||
rr.log_file_from_contents(filepath, file.read()) | ||
except Exception: | ||
pass | ||
|
||
rr.script_teardown(args) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
rerun-sdk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters