Skip to content

Commit

Permalink
fix all instances of broken upcasts
Browse files Browse the repository at this point in the history
  • Loading branch information
teh-cmc committed Nov 19, 2024
1 parent ff46476 commit e78d528
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 62 deletions.
8 changes: 4 additions & 4 deletions rerun_py/rerun_sdk/rerun/_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def log(
components=components,
num_instances=num_instances,
static=static,
recording=recording,
recording=recording, # NOLINT
)


Expand Down Expand Up @@ -294,7 +294,7 @@ def log_components(
entity_path,
components=instanced,
static_=static,
recording=recording,
recording=RecordingStream.to_native(recording),
)


Expand Down Expand Up @@ -358,7 +358,7 @@ def log_file_from_path(
Path(file_path),
entity_path_prefix=entity_path_prefix,
static_=static,
recording=recording,
recording=RecordingStream.to_native(recording),
)


Expand Down Expand Up @@ -419,7 +419,7 @@ def log_file_from_contents(
file_contents,
entity_path_prefix=entity_path_prefix,
static_=static,
recording=recording,
recording=RecordingStream.to_native(recording),
)


Expand Down
2 changes: 1 addition & 1 deletion rerun_py/rerun_sdk/rerun/_send_columns.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,5 +252,5 @@ def send_columns(
entity_path,
timelines={t.timeline_name(): t.as_arrow_array() for t in times},
components=components_args,
recording=recording,
recording=RecordingStream.to_native(recording),
)
2 changes: 1 addition & 1 deletion rerun_py/rerun_sdk/rerun/error_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def _send_warning_or_raise(
# TODO(jleibs): Context/stack should be its own component.
context_descriptor = _build_warning_context_string(skip_first=depth_to_user_code + 1)

log("rerun", TextLog(text=f"{message}\n{context_descriptor}", level="WARN"), recording=recording)
log("rerun", TextLog(text=f"{message}\n{context_descriptor}", level="WARN"), recording=recording) # NOLINT
_rerun_exception_ctx.sending_warning = False
else:
warnings.warn(
Expand Down
9 changes: 7 additions & 2 deletions rerun_py/rerun_sdk/rerun/legacy_notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def as_html(
if blueprint is not None:
output_stream.send_blueprint(blueprint, make_active=True) # type: ignore[attr-defined]

data_memory = memory_recording(recording=recording)
data_memory = memory_recording(recording=recording) # NOLINT
output_memory = output_stream.memory_recording() # type: ignore[attr-defined]

base64_data = base64.b64encode(output_memory.storage.concat_as_bytes(data_memory.storage)).decode("utf-8")
Expand Down Expand Up @@ -165,7 +165,12 @@ def legacy_notebook_show(
"""
html = as_html(
width=width, height=height, app_url=app_url, timeout_ms=timeout_ms, blueprint=blueprint, recording=recording
width=width,
height=height,
app_url=app_url,
timeout_ms=timeout_ms,
blueprint=blueprint,
recording=recording, # NOLINT
)
try:
from IPython.core.display import HTML
Expand Down
3 changes: 1 addition & 2 deletions rerun_py/rerun_sdk/rerun/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ def memory_recording(recording: RecordingStream | None = None) -> MemoryRecordin
"""

recording = RecordingStream.to_native(recording)
return MemoryRecording(bindings.memory_recording(recording=recording))
return MemoryRecording(bindings.memory_recording(recording=RecordingStream.to_native(recording)))


class MemoryRecording:
Expand Down
2 changes: 1 addition & 1 deletion rerun_py/rerun_sdk/rerun/notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,6 @@ def notebook_show(
width=width,
height=height,
blueprint=blueprint,
recording=recording,
recording=recording, # NOLINT
)
viewer.display()
8 changes: 3 additions & 5 deletions rerun_py/rerun_sdk/rerun/recording_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def new_recording(
if spawn:
from rerun.sinks import spawn as _spawn

_spawn(recording=recording)
_spawn(recording=recording) # NOLINT

return recording

Expand Down Expand Up @@ -271,7 +271,7 @@ def __del__(self): # type: ignore[no-untyped-def]
#
# See: https://github.com/rerun-io/rerun/issues/6223 for context on why this is necessary.
if recording is not None and not recording.is_forked_child():
bindings.flush(blocking=False, recording=recording)
bindings.flush(blocking=False, recording=recording) # NOLINT


def binary_stream(recording: RecordingStream | None = None) -> BinaryStream:
Expand Down Expand Up @@ -307,9 +307,7 @@ def binary_stream(recording: RecordingStream | None = None) -> BinaryStream:
An object that can be used to flush or read the data.
"""

recording = RecordingStream.to_native(recording)
return BinaryStream(bindings.binary_stream(recording=recording))
return BinaryStream(bindings.binary_stream(recording=RecordingStream.to_native(recording)))


class BinaryStream:
Expand Down
49 changes: 26 additions & 23 deletions rerun_py/rerun_sdk/rerun/sinks.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ def connect(
)

return connect_tcp(
addr, flush_timeout_sec=flush_timeout_sec, default_blueprint=default_blueprint, recording=recording
addr,
flush_timeout_sec=flush_timeout_sec,
default_blueprint=default_blueprint,
recording=recording, # NOLINT
)


Expand Down Expand Up @@ -111,7 +114,7 @@ def connect_tcp(
logging.warning("Rerun is disabled - connect() call ignored")
return

application_id = get_application_id(recording=recording)
application_id = get_application_id(recording=recording) # NOLINT
if application_id is None:
raise ValueError(
"No application id found. You must call rerun.init before connecting to a viewer, or provide a recording."
Expand All @@ -124,10 +127,11 @@ def connect_tcp(
application_id=application_id, blueprint=default_blueprint
).storage

recording = RecordingStream.to_native(recording)

bindings.connect_tcp(
addr=addr, flush_timeout_sec=flush_timeout_sec, default_blueprint=blueprint_storage, recording=recording
addr=addr,
flush_timeout_sec=flush_timeout_sec,
default_blueprint=blueprint_storage,
recording=RecordingStream.to_native(recording),
)


Expand Down Expand Up @@ -163,7 +167,7 @@ def save(
logging.warning("Rerun is disabled - save() call ignored. You must call rerun.init before saving a recording.")
return

application_id = get_application_id(recording=recording)
application_id = get_application_id(recording=recording) # NOLINT
if application_id is None:
raise ValueError(
"No application id found. You must call rerun.init before connecting to a viewer, or provide a recording."
Expand All @@ -176,9 +180,7 @@ def save(
application_id=application_id, blueprint=default_blueprint
).storage

recording = RecordingStream.to_native(recording)

bindings.save(path=str(path), default_blueprint=blueprint_storage, recording=recording)
bindings.save(path=str(path), default_blueprint=blueprint_storage, recording=RecordingStream.to_native(recording))


def stdout(default_blueprint: BlueprintLike | None = None, recording: RecordingStream | None = None) -> None:
Expand Down Expand Up @@ -210,7 +212,7 @@ def stdout(default_blueprint: BlueprintLike | None = None, recording: RecordingS
logging.warning("Rerun is disabled - save() call ignored. You must call rerun.init before saving a recording.")
return

application_id = get_application_id(recording=recording)
application_id = get_application_id(recording=recording) # NOLINT
if application_id is None:
raise ValueError(
"No application id found. You must call rerun.init before connecting to a viewer, or provide a recording."
Expand All @@ -223,8 +225,7 @@ def stdout(default_blueprint: BlueprintLike | None = None, recording: RecordingS
application_id=application_id, blueprint=default_blueprint
).storage

recording = RecordingStream.to_native(recording)
bindings.stdout(default_blueprint=blueprint_storage, recording=recording)
bindings.stdout(default_blueprint=blueprint_storage, recording=RecordingStream.to_native(recording))


def disconnect(recording: RecordingStream | None = None) -> None:
Expand All @@ -243,8 +244,7 @@ def disconnect(recording: RecordingStream | None = None) -> None:
"""

recording = RecordingStream.to_native(recording)
bindings.disconnect(recording=recording)
bindings.disconnect(recording=RecordingStream.to_native(recording))


@deprecated(
Expand Down Expand Up @@ -309,7 +309,7 @@ def serve(
web_port=web_port,
ws_port=ws_port,
default_blueprint=default_blueprint,
recording=recording,
recording=recording, # NOLINT
server_memory_limit=server_memory_limit,
)

Expand Down Expand Up @@ -362,7 +362,7 @@ def serve_web(
logging.warning("Rerun is disabled - serve() call ignored")
return

application_id = get_application_id(recording=recording)
application_id = get_application_id(recording=recording) # NOLINT
if application_id is None:
raise ValueError(
"No application id found. You must call rerun.init before connecting to a viewer, or provide a recording."
Expand All @@ -375,15 +375,14 @@ def serve_web(
application_id=application_id, blueprint=default_blueprint
).storage

recording = RecordingStream.to_native(recording)
# TODO(#5531): keep static data around.
bindings.serve_web(
open_browser,
web_port,
ws_port,
server_memory_limit=server_memory_limit,
default_blueprint=blueprint_storage,
recording=recording,
recording=RecordingStream.to_native(recording),
)


Expand Down Expand Up @@ -417,16 +416,16 @@ def send_blueprint(
See also: [`rerun.init`][], [`rerun.set_global_data_recording`][].
"""
application_id = get_application_id(recording=recording)
application_id = get_application_id(recording=recording) # NOLINT

if application_id is None:
raise ValueError("No application id found. You must call rerun.init before sending a blueprint.")

recording = RecordingStream.to_native(recording)

blueprint_storage = create_in_memory_blueprint(application_id=application_id, blueprint=blueprint).storage

bindings.send_blueprint(blueprint_storage, make_active, make_default, recording=recording)
bindings.send_blueprint(
blueprint_storage, make_active, make_default, recording=RecordingStream.to_native(recording)
)


def spawn(
Expand Down Expand Up @@ -477,4 +476,8 @@ def spawn(
_spawn_viewer(port=port, memory_limit=memory_limit, hide_welcome_screen=hide_welcome_screen)

if connect:
connect_tcp(f"127.0.0.1:{port}", recording=recording, default_blueprint=default_blueprint)
connect_tcp(
f"127.0.0.1:{port}",
recording=recording, # NOLINT
default_blueprint=default_blueprint,
)
18 changes: 5 additions & 13 deletions rerun_py/rerun_sdk/rerun/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ def set_time_sequence(timeline: str, sequence: int, recording: RecordingStream |
See also: [`rerun.init`][], [`rerun.set_global_data_recording`][].
"""
recording = RecordingStream.to_native(recording)
bindings.set_time_sequence(timeline, sequence, recording=recording)
bindings.set_time_sequence(timeline, sequence, recording=RecordingStream.to_native(recording))


def set_time_seconds(timeline: str, seconds: float, recording: RecordingStream | None = None) -> None:
Expand Down Expand Up @@ -69,8 +68,7 @@ def set_time_seconds(timeline: str, seconds: float, recording: RecordingStream |
"""

recording = RecordingStream.to_native(recording)
bindings.set_time_seconds(timeline, seconds, recording=recording)
bindings.set_time_seconds(timeline, seconds, recording=RecordingStream.to_native(recording))


def set_time_nanos(timeline: str, nanos: int, recording: RecordingStream | None = None) -> None:
Expand Down Expand Up @@ -106,9 +104,7 @@ def set_time_nanos(timeline: str, nanos: int, recording: RecordingStream | None
"""

recording = RecordingStream.to_native(recording)

bindings.set_time_nanos(timeline, nanos, recording=recording)
bindings.set_time_nanos(timeline, nanos, recording=RecordingStream.to_native(recording))


def disable_timeline(timeline: str, recording: RecordingStream | None = None) -> None:
Expand All @@ -126,9 +122,7 @@ def disable_timeline(timeline: str, recording: RecordingStream | None = None) ->
"""

recording = RecordingStream.to_native(recording)

bindings.disable_timeline(timeline, recording=recording)
bindings.disable_timeline(timeline, recording=RecordingStream.to_native(recording))


def reset_time(recording: RecordingStream | None = None) -> None:
Expand All @@ -149,6 +143,4 @@ def reset_time(recording: RecordingStream | None = None) -> None:
"""

recording = RecordingStream.to_native(recording)

bindings.reset_time(recording=recording)
bindings.reset_time(recording=RecordingStream.to_native(recording))
20 changes: 10 additions & 10 deletions tests/python/gil_stress/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,38 @@
rec = rr.new_recording(application_id="test")

rec = rr.new_recording(application_id="test")
rr.log("test", rr.Points3D([1, 2, 3]), recording=rec.inner)
rr.log("test", rr.Points3D([1, 2, 3]), recording=rec)

rec = rr.new_recording(application_id="test", make_default=True)
rr.log("test", rr.Points3D([1, 2, 3]), recording=rec.inner)
rr.log("test", rr.Points3D([1, 2, 3]), recording=rec)

rec = rr.new_recording(application_id="test", make_thread_default=True)
rr.log("test", rr.Points3D([1, 2, 3]), recording=rec.inner)
rr.log("test", rr.Points3D([1, 2, 3]), recording=rec)

rec = rr.new_recording(application_id="test") # this works
rr.set_global_data_recording(rec)
rr.log("test", rr.Points3D([1, 2, 3]), recording=rec.inner)
rr.log("test", rr.Points3D([1, 2, 3]), recording=rec)

rec = rr.new_recording(application_id="test") # this works
rr.set_thread_local_data_recording(rec)
rr.log("test", rr.Points3D([1, 2, 3]), recording=rec.inner)
rr.log("test", rr.Points3D([1, 2, 3]), recording=rec)

rec = rr.new_recording(application_id="test", spawn=True)
rr.log("test", rr.Points3D([1, 2, 3]), recording=rec.inner)
rr.log("test", rr.Points3D([1, 2, 3]), recording=rec)

rec = rr.new_recording(application_id="test")
rr.connect_tcp(recording=rec)
rr.log("test", rr.Points3D([1, 2, 3]), recording=rec.inner)
rr.log("test", rr.Points3D([1, 2, 3]), recording=rec)

rec = rr.new_recording(application_id="test")
rr.memory_recording(recording=rec)
rr.log("test", rr.Points3D([1, 2, 3]), recording=rec.inner)
rr.log("test", rr.Points3D([1, 2, 3]), recording=rec)

for _ in range(3):
rec = rr.new_recording(application_id="test", make_default=False, make_thread_default=False)
mem = rec.memory_recording()
rr.log("test", rr.Points3D([1, 2, 3]), recording=rec.inner)
rr.log("test", rr.Points3D([1, 2, 3]), recording=rec)

for _ in range(3):
rec = rr.new_recording(application_id="test", make_default=False, make_thread_default=False)
rr.log("test", rr.Points3D([1, 2, 3]), recording=rec.inner)
rr.log("test", rr.Points3D([1, 2, 3]), recording=rec)

0 comments on commit e78d528

Please sign in to comment.