fix: in the report, do not render toggle labels if there is more than one label eligible for a toggle#3502
Conversation
…ible for a toggle
📝 WalkthroughWalkthroughThis 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
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
Suggested labels
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🧰 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...
🧬 Code Definitions (1)src/snakemake/report/__init__.py (1)
🪛 Ruff (0.8.2)src/snakemake/report/__init__.py555-555: Function definition does not bind loop variable (B023) 560-560: Function definition does not bind loop variable (B023) 566-566: Function definition does not bind loop variable (B023) 566-566: Function definition does not bind loop variable (B023) 570-570: Function definition does not bind loop variable (B023) 570-570: Function definition does not bind loop variable (B023) 573-573: Function definition does not bind loop variable (B023) 573-573: Function definition does not bind loop variable (B023) ⏰ Context from checks skipped due to timeout of 90000ms (30)
🔇 Additional comments (4)
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
|
Please format your code with black: |
There was a problem hiding this comment.
Actionable comments posted: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 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 theselfargument of methods.
Do not suggest type annotation of theclsargument of classmethods.
Do not suggest return type annotation if a function or method does not contain areturnstatement.
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 (
jobandreport_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 (
jobandreport_obj) by assigning them as default parameters in bothregister_fileand its nested functionexpand_cat_nameseem 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_fileto includejob=job, report_obj=report_objin its parameters.- Modified the nested async function
expand_cat_nameto capturewildcardsandjobas 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_namePlease 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)
🤖 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).
… 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 -->
🤖 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).
QC
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