Skip to content

Conversation

@mfinean
Copy link
Collaborator

@mfinean mfinean commented Dec 26, 2025

Fixes a few small code issues:

  • Input validation: Changed assert statements to raise TypeError/ValueError with descriptive messages. Assertions can be disabled with -O, so they shouldn't be used for input validation.

  • Dead code: Removed duplicate self.worker_class_instance = None assignment.

  • Magic number: Extracted the 100GB cache size to DEFAULT_CACHE_SIZE_BYTES constant.

  • Hardcoded version: The rerun viewer URL now uses the installed package version via importlib.metadata instead of a hardcoded string (resolves the TODO).

Summary by Sourcery

Improve input validation and configuration around benchmarking cache and rerun viewer integration.

Bug Fixes:

  • Replace assertion-based input validation with explicit TypeError/ValueError exceptions for benchmark names and input variable lists.
  • Remove duplicate worker_class_instance initialization in the benchmark setup.

Enhancements:

  • Introduce a DEFAULT_CACHE_SIZE_BYTES constant for the default 100GB benchmark result cache size.
  • Derive the rerun viewer URL version from the installed rerun package via importlib.metadata with a safe fallback.

@mfinean mfinean requested a review from blooop as a code owner December 26, 2025 11:30
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Dec 26, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Refactors input validation to use explicit exceptions instead of assertions, removes a redundant assignment, centralizes the default cache size in a constant, and makes the rerun viewer URL dynamically use the installed rerun package version with a safe fallback.

Sequence diagram for dynamic rerun viewer version resolution

sequenceDiagram
  participant Caller
  participant UtilsRerun
  participant ImportlibMetadata as ImportlibMetadata
  participant Panel

  Caller->>UtilsRerun: rrd_to_pane(url, width, height, version=None)
  UtilsRerun->>UtilsRerun: _get_rerun_version()
  UtilsRerun->>ImportlibMetadata: get_package_version(rerun-sdk)
  alt version lookup succeeds
    ImportlibMetadata-->>UtilsRerun: rerun_version
  else version lookup fails
    ImportlibMetadata-->>UtilsRerun: raises Exception
    UtilsRerun->>UtilsRerun: use fallback 0.20.1
  end
  UtilsRerun->>Panel: pn.pane.HTML(iframe_html)
  Panel-->>Caller: HTMLPane
Loading

Class diagram for updated Bencher initialization and rerun utilities

classDiagram

class BencherModule {
  + DEFAULT_CACHE_SIZE_BYTES int
}

class Bencher {
  - bench_name str
  - worker Any
  - worker_class_instance Any
  - worker_input_cfg Any
  - cache_size int
  - sample_cache Any
  - ds_dynamic dict
  + __init__(bench_name, worker, worker_input_cfg, run_cfg, report)
  + set_worker(worker, worker_input_cfg)
  + plot_sweep(input_vars_in, run_cfg)
}

class UtilsRerun {
  + _get_rerun_version() str
  + rrd_to_pane(url str, width int, height int, version str) HTMLPane
}

BencherModule --> Bencher : uses DEFAULT_CACHE_SIZE_BYTES
UtilsRerun --> Bencher : used in plotting workflows
Loading

File-Level Changes

Change Details Files
Replace assertion-based input validation with explicit TypeError/ValueError exceptions carrying descriptive messages.
  • Validate bench_name type using an isinstance check and raise TypeError with a clear message when invalid instead of using an assert.
  • Ensure list-type input variables in plot_sweep raise ValueError with a descriptive message when empty instead of asserting non-emptiness.
bencher/bencher.py
Clean up configuration defaults and remove dead code in the benchmark class.
  • Introduce DEFAULT_CACHE_SIZE_BYTES constant for the 100 GB default cache size.
  • Use the shared DEFAULT_CACHE_SIZE_BYTES constant when initializing self.cache_size instead of an inline literal.
  • Remove duplicate initialization of self.worker_class_instance to None in the constructor.
bencher/bencher.py
Resolve hardcoded rerun viewer version by deriving it from the installed package with a robust fallback.
  • Add a helper function _get_rerun_version that retrieves the rerun-sdk package version via importlib.metadata.version and falls back to a default string on failure.
  • Update rrd_to_pane to use _get_rerun_version when no version is provided instead of a hardcoded version literal.
bencher/utils_rerun.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue, and left some high level feedback:

  • In _get_rerun_version, catching a broad Exception will hide unexpected issues; consider catching importlib.metadata.PackageNotFoundError (and possibly logging a warning) before falling back to the hardcoded version.
  • Since DEFAULT_CACHE_SIZE_BYTES encodes the 100 GB default, you might want to express it as 100 * 1024**3 (and/or update the nearby comment to derive from the constant) to avoid ambiguity if the value changes later.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `_get_rerun_version`, catching a broad `Exception` will hide unexpected issues; consider catching `importlib.metadata.PackageNotFoundError` (and possibly logging a warning) before falling back to the hardcoded version.
- Since `DEFAULT_CACHE_SIZE_BYTES` encodes the 100 GB default, you might want to express it as `100 * 1024**3` (and/or update the nearby comment to derive from the constant) to avoid ambiguity if the value changes later.

## Individual Comments

### Comment 1
<location> `bencher/utils_rerun.py:11-13` </location>
<code_context>

+def _get_rerun_version() -> str:
+    """Get the installed rerun package version."""
+    try:
+        return get_package_version("rerun-sdk")
+    except Exception:
+        return "0.20.1"  # Fallback version
+
</code_context>

<issue_to_address>
**issue (bug_risk):** Narrow the exception type when resolving the rerun package version to avoid masking unrelated errors.

Catching `Exception` here can mask real problems (e.g., import errors or environment misconfiguration). Please catch `importlib.metadata.PackageNotFoundError` for the missing-package case instead, and let other exceptions propagate (optionally with a log warning before falling back to the hard-coded version).
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Owner

@blooop blooop left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@codecov
Copy link

codecov bot commented Dec 26, 2025

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

Thanks for integrating Codecov - We've got you covered ☂️

@blooop blooop merged commit 436ff62 into blooop:main Dec 26, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants