Skip to content

fix: in the report, do not render toggle labels if there is more than one label eligible for a toggle#3502

Merged
johanneskoester merged 5 commits into
mainfrom
fix/report-toggle
Apr 1, 2025
Merged

fix: in the report, do not render toggle labels if there is more than one label eligible for a toggle#3502
johanneskoester merged 5 commits into
mainfrom
fix/report-toggle

Conversation

@johanneskoester

@johanneskoester johanneskoester commented Apr 1, 2025

Copy link
Copy Markdown
Contributor

QC

  • The PR contains a test case for the changes or the changes are already covered by an existing test case.
  • The documentation (docs/) is updated to reflect the changes or this is not necessary (e.g. if the change does neither modify the language nor the behavior or functionalities of Snakemake).

Summary by CodeRabbit

  • New Features
    • Report generation now leverages concurrent processing for a more responsive experience.
  • Bug Fixes
    • Improved results display by limiting toggle options to one, reducing potential confusion.
    • Enhanced error notifications for checkpoint issues by providing clearer contextual guidance.

@coderabbitai

coderabbitai Bot commented Apr 1, 2025

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

This pull request introduces asynchronous functionality to report generation by converting key functions in the report module to asynchronous methods that use an async TaskGroup for concurrent file retrieval and argument expansion. It also adds a conditional check in an HTML reporting component to ensure that only a single toggle label is used and enhances error messaging in the rules module by including additional context about input files and the affected checkpoint.

Changes

File(s) Change Summary
src/snakemake/report/__init__.py Converted expand_report_argument, expand_labels, and register_file to async functions. These modifications include using await and an async TaskGroup for concurrent processing of file retrieval and argument expansion.
src/snakemake/.../html_reporter/template/components/abstract_results.js Added a conditional check in the getData method to reset the toggleLabels map if its size exceeds one, ensuring only one toggle label is maintained.
src/snakemake/rules.py Updated the error message in handle_incomplete_checkpoint to include context about current inputs and the target checkpoint file, and associated the error with the current rule instance by adding rule=self.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant RegFile as register_file()
    participant ExpArg as expand_report_argument()
    participant ExpLabel as expand_labels()
    participant TaskGrp as TaskGroup
    participant Storage

    Caller->>RegFile: Call register_file()
    RegFile->>ExpArg: Await expand_report_argument()
    activate ExpArg
    ExpArg->>TaskGrp: Create async tasks for file retrieval
    TaskGrp->>Storage: Concurrently retrieve files
    Storage-->>TaskGrp: Return file data
    TaskGrp-->>ExpArg: Aggregate file data
    deactivate ExpArg
    RegFile->>ExpLabel: Await expand_labels() (if applicable)
    ExpLabel->>ExpArg: Await expand_report_argument() for label expansion
    Caller-->>RegFile: Async processing completes
Loading

Suggested labels

WIP, hackathon-2025


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3258a46 and 372b32e.

📒 Files selected for processing (1)
  • src/snakemake/report/__init__.py (10 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.py`: Do not try to improve formatting. Do not suggest type annotations for functions that are defined inside of functions or methods. Do not suggest type annotation of the `s...

**/*.py: Do not try to improve formatting.
Do not suggest type annotations for functions that are defined inside of functions or methods.
Do not suggest type annotation of the self argument of methods.
Do not suggest type annotation of the cls argument of classmethods.
Do not suggest return type annotation if a function or method does not contain a return statement.

  • src/snakemake/report/__init__.py
🧬 Code Definitions (1)
src/snakemake/report/__init__.py (1)
src/snakemake/rules.py (8)
  • params (581-582)
  • params (1390-1391)
  • input (267-268)
  • input (1370-1387)
  • output (301-302)
  • output (1366-1367)
  • name (129-130)
  • name (133-134)
🪛 Ruff (0.8.2)
src/snakemake/report/__init__.py

555-555: Function definition does not bind loop variable job

(B023)


560-560: Function definition does not bind loop variable job

(B023)


566-566: Function definition does not bind loop variable report_obj

(B023)


566-566: Function definition does not bind loop variable job

(B023)


570-570: Function definition does not bind loop variable report_obj

(B023)


570-570: Function definition does not bind loop variable job

(B023)


573-573: Function definition does not bind loop variable report_obj

(B023)


573-573: Function definition does not bind loop variable job

(B023)

⏰ Context from checks skipped due to timeout of 90000ms (30)
  • GitHub Check: tests (10, windows-latest, py312)
  • GitHub Check: tests (10, ubuntu-latest, py312)
  • GitHub Check: tests (10, ubuntu-latest, py311)
  • GitHub Check: tests (9, windows-latest, py312)
  • GitHub Check: tests (9, ubuntu-latest, py312)
  • GitHub Check: tests (9, ubuntu-latest, py311)
  • GitHub Check: tests (8, windows-latest, py312)
  • GitHub Check: tests (8, ubuntu-latest, py312)
  • GitHub Check: tests (8, ubuntu-latest, py311)
  • GitHub Check: tests (7, windows-latest, py312)
  • GitHub Check: tests (7, ubuntu-latest, py312)
  • GitHub Check: tests (7, ubuntu-latest, py311)
  • GitHub Check: tests (6, windows-latest, py312)
  • GitHub Check: tests (6, ubuntu-latest, py312)
  • GitHub Check: tests (6, ubuntu-latest, py311)
  • GitHub Check: tests (5, windows-latest, py312)
  • GitHub Check: tests (5, ubuntu-latest, py312)
  • GitHub Check: tests (5, ubuntu-latest, py311)
  • GitHub Check: tests (4, windows-latest, py312)
  • GitHub Check: tests (4, ubuntu-latest, py312)
  • GitHub Check: tests (4, ubuntu-latest, py311)
  • GitHub Check: tests (3, windows-latest, py312)
  • GitHub Check: tests (3, ubuntu-latest, py312)
  • GitHub Check: tests (3, ubuntu-latest, py311)
  • GitHub Check: tests (2, windows-latest, py312)
  • GitHub Check: tests (2, ubuntu-latest, py312)
  • GitHub Check: tests (2, ubuntu-latest, py311)
  • GitHub Check: tests (1, windows-latest, py312)
  • GitHub Check: tests (1, ubuntu-latest, py312)
  • GitHub Check: tests (1, ubuntu-latest, py311)
🔇 Additional comments (4)
src/snakemake/report/__init__.py (4)

6-6: Good addition of TaskGroup for concurrency.

The addition of TaskGroup from asyncio is appropriate for the async changes being implemented throughout the file. This will allow concurrent execution of file retrieval tasks, improving performance.


114-114: LGTM: Minor initialization change.

The change to initialize definitions with an empty array [] is a small adjustment that doesn't impact functionality.


188-215: Good async implementation for file retrieval concurrency.

Converting expand_report_argument to an async function with TaskGroup for concurrent file retrieval is a good performance improvement. The implementation correctly handles IO items that might need retrieval from storage before evaluating the function.

🧰 Tools
🪛 Ruff (0.8.2)

206-206: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling

(B904)


211-211: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling

(B904)


454-478: Properly converted function to async with await calls.

The expand_labels function has been correctly converted to async, with appropriate await calls for the expanded arguments.

🧰 Tools
🪛 Ruff (0.8.2)

463-463: Multiple isinstance calls for col, merge into a single call

Merge isinstance calls for col

(SIM101)

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions

github-actions Bot commented Apr 1, 2025

Copy link
Copy Markdown
Contributor

Please format your code with black: black snakemake tests/*.py.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 378ec2d and 3258a46.

📒 Files selected for processing (1)
  • src/snakemake/report/__init__.py (9 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.py`: Do not try to improve formatting. Do not suggest type annotations for functions that are defined inside of functions or methods. Do not suggest type annotation of the `s...

**/*.py: Do not try to improve formatting.
Do not suggest type annotations for functions that are defined inside of functions or methods.
Do not suggest type annotation of the self argument of methods.
Do not suggest type annotation of the cls argument of classmethods.
Do not suggest return type annotation if a function or method does not contain a return statement.

  • src/snakemake/report/__init__.py
🪛 Ruff (0.8.2)
src/snakemake/report/__init__.py

557-557: Function definition does not bind loop variable job

(B023)


562-562: Function definition does not bind loop variable job

(B023)


568-568: Function definition does not bind loop variable report_obj

(B023)


570-570: Function definition does not bind loop variable job

(B023)


573-573: Function definition does not bind loop variable report_obj

(B023)


575-575: Function definition does not bind loop variable job

(B023)


577-577: Function definition does not bind loop variable report_obj

(B023)


577-577: Function definition does not bind loop variable job

(B023)

🔇 Additional comments (6)
src/snakemake/report/__init__.py (6)

6-6: Adding support for async operations.

Adding TaskGroup from asyncio enables concurrent execution of tasks, which will improve performance when retrieving multiple files from storage.


114-114: Initialization change for report definitions.

Changed the initialization of the definitions variable to start with an empty JSON array.


188-202: Converted function to async with concurrent file retrieval.

The function is now asynchronous and uses TaskGroup to concurrently retrieve files from storage, which is a significant performance optimization for workflows that handle multiple storage-based files.


456-460: Properly modified expand_labels for async operation.

The function has been converted to async and properly awaits the result of expand_report_argument when processing labels, maintaining consistency with the overall async pattern.

Also applies to: 478-479


599-599: Properly awaiting async register_file calls.

All calls to the now-async register_file function are correctly awaited, maintaining the async flow through the code.

Also applies to: 620-621, 643-644


550-566:

Details

❓ Verification inconclusive

Potential issue with nested async function scope.

The nested async functions access outer scope variables (job and report_obj) without capturing them as parameters, which could lead to unexpected behavior if these variables change before the async functions are executed.

async def register_file(
    f,
    parent_path=None,
    wildcards_overwrite=None,
    aux_files=None,
    name_overwrite=None,
+   job=job,
+   report_obj=report_obj,
):
    wildcards = wildcards_overwrite or job.wildcards

    async def expand_cat_name(cat_name, wildcards=wildcards, job=job):
        if cat_name is not None:
            return await expand_report_argument(
                cat_name, wildcards, job
            )
        else:
            return cat_name

🏁 Script executed:

#!/bin/bash
# Verify if this is a known pattern in the codebase
rg -A 3 "async def \w+\([^)]*\):" --type py | rg -B 1 -A 2 "^\s+async def"

Length of output: 76


Action: Verify Closure Capture in Nested Async Functions

The modifications to capture outer scope variables (job and report_obj) by assigning them as default parameters in both register_file and its nested function expand_cat_name seem to address the potential issues raised. However, since our automated search for similar patterns returned no results, please verify manually that these changes reliably preserve the intended values in asynchronous contexts.

  • File: src/snakemake/report/__init__.py (Lines: 550-566)
    • Updated register_file to include job=job, report_obj=report_obj in its parameters.
    • Modified the nested async function expand_cat_name to capture wildcards and job as default parameters.

Diff snippet:

async def register_file(
    f,
    parent_path=None,
    wildcards_overwrite=None,
    aux_files=None,
    name_overwrite=None,
+   job=job,
+   report_obj=report_obj,
):
    wildcards = wildcards_overwrite or job.wildcards

    async def expand_cat_name(cat_name, wildcards=wildcards, job=job):
        if cat_name is not None:
            return await expand_report_argument(
                cat_name, wildcards, job
            )
        else:
            return cat_name

Please confirm manually that these changes correctly capture the outer variables at the time of function definition, ensuring there are no unexpected side effects during asynchronous execution.

🧰 Tools
🪛 Ruff (0.8.2)

557-557: Function definition does not bind loop variable job

(B023)


562-562: Function definition does not bind loop variable job

(B023)

Comment thread src/snakemake/report/__init__.py Outdated
Comment thread src/snakemake/report/__init__.py
@johanneskoester johanneskoester merged commit 3be8ca9 into main Apr 1, 2025
@johanneskoester johanneskoester deleted the fix/report-toggle branch April 1, 2025 14:01
johanneskoester pushed a commit that referenced this pull request Apr 1, 2025
🤖 I have created a release *beep* *boop*
---


##
[9.1.4](v9.1.3...v9.1.4)
(2025-04-01)


### Bug Fixes

* Fix map call in report creation
([#3503](#3503))
([44754cc](44754cc))
* in the report, do not render toggle labels if there is more than one
label eligible for a toggle
([#3502](#3502))
([3be8ca9](3be8ca9))
* only inform about storage cleanup in case of --verbose mode
([#3494](#3494))
([62bbbf5](62bbbf5))
* provide causing rule to workflow error during checkpoint handling
([#3499](#3499))
([b4cbe5d](b4cbe5d))
* rerun-trigger regression
([#3492](#3492))
([811742d](811742d))


### Documentation

* note about parameter inheritance when using the "use rule with"
pattern ([#3500](#3500))
([8f6a8eb](8f6a8eb))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
kjohnsen pushed a commit to kjohnsen/snakemake that referenced this pull request Dec 15, 2025
… one label eligible for a toggle (snakemake#3502)

<!--Add a description of your PR here-->

### QC
<!-- Make sure that you can tick the boxes below. -->

* [x] The PR contains a test case for the changes or the changes are
already covered by an existing test case.
* [x] The documentation (`docs/`) is updated to reflect the changes or
this is not necessary (e.g. if the change does neither modify the
language nor the behavior or functionalities of Snakemake).


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Report generation now leverages concurrent processing for a more
responsive experience.
- **Bug Fixes**
- Improved results display by limiting toggle options to one, reducing
potential confusion.
- Enhanced error notifications for checkpoint issues by providing
clearer contextual guidance.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
kjohnsen pushed a commit to kjohnsen/snakemake that referenced this pull request Dec 15, 2025
🤖 I have created a release *beep* *boop*
---


##
[9.1.4](snakemake/snakemake@v9.1.3...v9.1.4)
(2025-04-01)


### Bug Fixes

* Fix map call in report creation
([snakemake#3503](snakemake#3503))
([44754cc](snakemake@44754cc))
* in the report, do not render toggle labels if there is more than one
label eligible for a toggle
([snakemake#3502](snakemake#3502))
([3be8ca9](snakemake@3be8ca9))
* only inform about storage cleanup in case of --verbose mode
([snakemake#3494](snakemake#3494))
([62bbbf5](snakemake@62bbbf5))
* provide causing rule to workflow error during checkpoint handling
([snakemake#3499](snakemake#3499))
([b4cbe5d](snakemake@b4cbe5d))
* rerun-trigger regression
([snakemake#3492](snakemake#3492))
([811742d](snakemake@811742d))


### Documentation

* note about parameter inheritance when using the "use rule with"
pattern ([snakemake#3500](snakemake#3500))
([8f6a8eb](snakemake@8f6a8eb))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
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.

1 participant