From ce653855daeed9c625e68ea2e06c99887ffbc73b Mon Sep 17 00:00:00 2001 From: Jeremy Leibs Date: Mon, 14 Oct 2024 09:30:07 +0200 Subject: [PATCH] Make explicit recordings work without calling rr.init() (#7698) ### What Our recording functions would always check the global recording state even though they could validly operate just on a manually-created recording. With this change, this becomes valid: ``` import rerun as rr rec = rr.new_recording("rerun_example_cube_flat") rec.log("points", rr.Points3D([1, 2, 3])) rec.save("output.rrd") ``` --- rerun_py/rerun_sdk/rerun/sinks.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/rerun_py/rerun_sdk/rerun/sinks.py b/rerun_py/rerun_sdk/rerun/sinks.py index d86f35f28fef..c38cf6a3eddd 100644 --- a/rerun_py/rerun_sdk/rerun/sinks.py +++ b/rerun_py/rerun_sdk/rerun/sinks.py @@ -13,6 +13,12 @@ # --- Sinks --- +def is_recording_enabled(recording: RecordingStream | None) -> bool: + if recording is not None: + return bindings.is_enabled(recording.inner) # type: ignore[no-any-return] + return bindings.is_enabled() # type: ignore[no-any-return] + + def connect( addr: str | None = None, *, @@ -47,7 +53,7 @@ def connect( """ - if not bindings.is_enabled(): + if not is_recording_enabled(recording): logging.warning("Rerun is disabled - connect() call ignored") return @@ -102,7 +108,7 @@ def save( """ - if not bindings.is_enabled(): + if not is_recording_enabled(recording): logging.warning("Rerun is disabled - save() call ignored. You must call rerun.init before saving a recording.") return @@ -149,7 +155,7 @@ def stdout(default_blueprint: BlueprintLike | None = None, recording: RecordingS """ - if not bindings.is_enabled(): + if not is_recording_enabled(recording): logging.warning("Rerun is disabled - save() call ignored. You must call rerun.init before saving a recording.") return @@ -234,7 +240,7 @@ def serve( """ - if not bindings.is_enabled(): + if not is_recording_enabled(recording): logging.warning("Rerun is disabled - serve() call ignored") return @@ -346,7 +352,7 @@ def spawn( """ - if not bindings.is_enabled(): + if not is_recording_enabled(recording): logging.warning("Rerun is disabled - spawn() call ignored.") return