Skip to content

Commit

Permalink
update python bindings and examples
Browse files Browse the repository at this point in the history
  • Loading branch information
teh-cmc committed Mar 4, 2024
1 parent 93a31e2 commit 0811333
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 53 deletions.
2 changes: 1 addition & 1 deletion examples/python/external_data_loader/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def set_time_from_args() -> None:
timeline_name, time = parts
rr.set_time_seconds(timeline_name, float(time))

for time_str in args.time:
for time_str in args.sequence:
parts = time_str.split("=")
if len(parts) != 2:
continue
Expand Down
16 changes: 3 additions & 13 deletions rerun_py/rerun_sdk/rerun/_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,8 @@ def log_components(
def log_file_from_path(
file_path: str | Path,
*,
recording_id: str | None = None,
entity_path_prefix: str | None = None,
timeless: bool | None = None,
timeless: bool = False,
recording: RecordingStream | None = None,
) -> None:
r"""
Expand All @@ -308,14 +307,11 @@ def log_file_from_path(
file_path:
Path to the file to be logged.
recording_id:
The recommended `RecordingId` to log the data to.
entity_path_prefix:
What should the logged entity paths be prefixed with?
timeless:
Should the logged data be timeless?
Should the logged data be timeless? (default: False)
recording:
Specifies the [`rerun.RecordingStream`][] to use. If left unspecified,
Expand All @@ -326,7 +322,6 @@ def log_file_from_path(

bindings.log_file_from_path(
Path(file_path),
recording_id=recording_id,
entity_path_prefix=entity_path_prefix,
timeless=timeless,
recording=recording,
Expand All @@ -339,7 +334,6 @@ def log_file_from_contents(
file_path: str | Path,
file_contents: bytes,
*,
recording_id: str | None = None,
entity_path_prefix: str | None = None,
timeless: bool | None = None,
recording: RecordingStream | None = None,
Expand All @@ -362,14 +356,11 @@ def log_file_from_contents(
file_contents:
Contents to be logged.
recording_id:
The recommended `RecordingId` to log the data to.
entity_path_prefix:
What should the logged entity paths be prefixed with?
timeless:
Should the logged data be timeless?
Should the logged data be timeless? (default: False)
recording:
Specifies the [`rerun.RecordingStream`][] to use. If left unspecified,
Expand All @@ -381,7 +372,6 @@ def log_file_from_contents(
bindings.log_file_from_contents(
Path(file_path),
file_contents,
recording_id=recording_id,
entity_path_prefix=entity_path_prefix,
timeless=timeless,
recording=recording,
Expand Down
54 changes: 15 additions & 39 deletions rerun_py/src/python_bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -967,53 +967,40 @@ fn log_arrow_msg(
#[pyfunction]
#[pyo3(signature = (
file_path,
recording_id = None,
entity_path_prefix = None,
timeless = None,
recording=None,
timeless = false,
recording = None,
))]
fn log_file_from_path(
py: Python<'_>,
file_path: std::path::PathBuf,
recording_id: Option<String>,
entity_path_prefix: Option<String>,
timeless: Option<bool>,
timeless: bool,
recording: Option<&PyRecordingStream>,
) -> PyResult<()> {
log_file(
py,
file_path,
None,
recording_id,
entity_path_prefix,
timeless,
recording,
)
log_file(py, file_path, None, entity_path_prefix, timeless, recording)
}

#[pyfunction]
#[pyo3(signature = (
file_path,
file_contents,
recording_id = None,
entity_path_prefix = None,
timeless = None,
recording=None,
timeless = false,
recording = None,
))]
fn log_file_from_contents(
py: Python<'_>,
file_path: std::path::PathBuf,
file_contents: &[u8],
recording_id: Option<String>,
entity_path_prefix: Option<String>,
timeless: Option<bool>,
timeless: bool,
recording: Option<&PyRecordingStream>,
) -> PyResult<()> {
log_file(
py,
file_path,
Some(file_contents),
recording_id,
entity_path_prefix,
timeless,
recording,
Expand All @@ -1024,37 +1011,26 @@ fn log_file(
py: Python<'_>,
file_path: std::path::PathBuf,
file_contents: Option<&[u8]>,
recording_id: Option<String>,
entity_path_prefix: Option<String>,
timeless: Option<bool>,
timeless: bool,
recording: Option<&PyRecordingStream>,
) -> PyResult<()> {
let Some(recording) = get_data_recording(recording) else {
return Ok(());
};

let Some(recording_id) = recording
.store_info()
.map(|info| info.store_id.clone())
.or(recording_id.map(|id| StoreId::from_string(StoreKind::Recording, id)))
else {
return Ok(());
};

let settings = rerun::DataLoaderSettings {
store_id: recording_id,
opened_store_id: None,
entity_path_prefix: entity_path_prefix.map(Into::into),
timepoint: timeless.unwrap_or(false).then(TimePoint::timeless),
};

if let Some(contents) = file_contents {
recording
.log_file_from_contents(&settings, file_path, std::borrow::Cow::Borrowed(contents))
.log_file_from_contents(
file_path,
std::borrow::Cow::Borrowed(contents),
entity_path_prefix.map(Into::into),
timeless,
)
.map_err(|err| PyRuntimeError::new_err(err.to_string()))?;
} else {
recording
.log_file_from_path(&settings, file_path)
.log_file_from_path(file_path, entity_path_prefix.map(Into::into), timeless)
.map_err(|err| PyRuntimeError::new_err(err.to_string()))?;
}

Expand Down

0 comments on commit 0811333

Please sign in to comment.