Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect the RERUN_STRICT environment variable if not specified in rr.init #6341

Merged
merged 3 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions rerun_py/rerun_sdk/rerun/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def init(
spawn: bool = False,
init_logging: bool = True,
default_enabled: bool = True,
strict: bool = False,
strict: bool | None = None,
default_blueprint: BlueprintLike | None = None,
) -> None:
"""
Expand Down Expand Up @@ -233,8 +233,10 @@ def init(
init_logging
Should we initialize the logging for this application?
strict
If `True`, an exceptions is raised on use error (wrong parameter types, etc.).
If `True`, an exception is raised on use error (wrong parameter types, etc.).
If `False`, errors are logged as warnings instead.
If unset, this can alternatively be overridden using the RERUN_STRICT environment variable.
If not otherwise specified, the default behavior will be equivalent to `False`.
default_blueprint
Optionally set a default blueprint to use for this application. If the application
already has an active blueprint, the new blueprint won't become active until the user
Expand All @@ -248,7 +250,8 @@ def init(
random.seed(0)
np.random.seed(0)

set_strict_mode(strict)
if strict is not None:
set_strict_mode(strict)

# Always check whether we are a forked child when calling init. This should have happened
# via `_register_on_fork` but it's worth being conservative.
Expand Down
13 changes: 10 additions & 3 deletions rerun_py/tests/unit/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def expected_warnings(warnings: Any, mem: Any, starting_msgs: int, count: int, e
def test_stack_tracking() -> None:
# Force flushing so we can count the messages
os.environ["RERUN_FLUSH_NUM_ROWS"] = "0"
rr.init("rerun_example_strict_mode", spawn=False)
rr.init("rerun_example_strict_mode", strict=False, spawn=False)

mem = rr.memory_recording()
with pytest.warns(RerunWarning) as warnings:
Expand Down Expand Up @@ -117,17 +117,24 @@ def test_stack_tracking() -> None:


def test_strict_mode() -> None:
# We can disable strict on just this function
rr.set_strict_mode(False)

# Confirm strict mode is off
with pytest.warns(RerunWarning):
assert outer() == 42

# We can enable strict on just this function
with pytest.raises(ValueError):
outer(strict=True)

with pytest.raises(ValueError):
uses_context(strict=True)

# We can disable strict mode globally
# We can enable strict mode globally
rr.set_strict_mode(True)
with pytest.raises(ValueError):
outer()

# Clear the global strict mode again
rr.set_strict_mode(False)

Expand Down
Loading