Skip to content

fix: inherit flags of input functions#3483

Merged
johanneskoester merged 1 commit into
mainfrom
fix/inherit-flags
Mar 26, 2025
Merged

fix: inherit flags of input functions#3483
johanneskoester merged 1 commit into
mainfrom
fix/inherit-flags

Conversation

@johanneskoester

@johanneskoester johanneskoester commented Mar 26, 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

    • Introduced dynamic input filename generation based on dataset parameters, offering more flexible and intuitive file specification in workflows.
  • Refactor

    • Enhanced the underlying input processing logic to improve consistency and reliability when handling user-defined file patterns.

@coderabbitai

coderabbitai Bot commented Mar 26, 2025

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

This pull request refines the processing of wildcards by modifying the handling of callable items in the Snakemake rules. In the _apply_wildcards method, the assignment and condition checking for callable items have been adjusted, with an update to the concretize call. The expand_input method is similarly updated to pass along callable flags. Additionally, new functions have been introduced in the test Snakefile to dynamically generate input filenames for rules based on wildcards.

Changes

File(s) Change Summary
src/snakemake/rules.py Updated _apply_wildcards to assign olditem if callable and check for None instead of truthy; modified concretize to use from_callable; updated expand_input and associated function signature to inherit flags.
tests/test_access_patterns/Snakefile Added functions get_e_input and get_f_input for dynamically generating input filenames; modified input declarations for rules e and f to use these functions instead of hardcoded strings.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant Rule
    participant Concretize

    Caller->>Rule: call _apply_wildcards(newitems, olditems, wildcards)
    Note right of Rule: Check if item is callable
    alt Item is callable
        Rule->>Rule: Assign olditem to from_callable
    else Item is not callable
        Rule->>Rule: Set from_callable to None
    end
    Rule->>Rule: Check if from_callable is not None
    Rule->>Concretize: Call concretize(from_callable)
    Concretize-->>Rule: Return processed result
    Rule-->>Caller: Return updated wildcards
Loading
sequenceDiagram
    participant RuleE
    participant Snakefile
    participant GetE

    RuleE->>Snakefile: Request input for rule e
    Snakefile->>GetE: call get_e_input(wildcards)
    GetE-->>Snakefile: return input filename
    Snakefile-->>RuleE: Provide dynamic input filename
Loading
sequenceDiagram
    participant RuleF
    participant Snakefile
    participant GetF

    RuleF->>Snakefile: Request input for rule f
    Snakefile->>GetF: call get_f_input(wildcards)
    GetF-->>Snakefile: return input filename
    Snakefile-->>RuleF: Provide dynamic input filename
Loading

📜 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 5e151c2 and 9066230.

⛔ Files ignored due to path filters (1)
  • pyproject.toml is excluded by !pyproject.toml
📒 Files selected for processing (2)
  • src/snakemake/rules.py (3 hunks)
  • tests/test_access_patterns/Snakefile (2 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/rules.py
⏰ Context from checks skipped due to timeout of 90000ms (35)
  • 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, macos-latest, py312)
  • 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, macos-latest, py312)
  • 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, macos-latest, py312)
  • 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, macos-latest, py312)
  • 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, macos-latest, py312)
  • GitHub Check: tests (1, windows-latest, py312)
  • GitHub Check: tests (1, ubuntu-latest, py312)
  • GitHub Check: tests (1, ubuntu-latest, py311)
🔇 Additional comments (8)
tests/test_access_patterns/Snakefile (4)

50-52: Good implementation of the input function

The get_e_input function correctly formats an input filename string using the wildcard dataset parameter.


56-56: Appropriate use of the input function

Using the function name directly as an input (without calling it) allows Snakemake to pass the wildcard values automatically.


65-67: Good implementation of the input function

The get_f_input function correctly formats an input filename string using the wildcard dataset parameter.


71-71: Correct usage of access.multi flag with input function

Using access.multi(get_f_input) demonstrates the flags application pattern that the PR is addressing.

src/snakemake/rules.py (4)

805-807: Improved callable handling to support flag inheritance

This change preserves the actual callable object in from_callable instead of just a boolean flag, which is necessary for inheriting flags from the callable later in the processing pipeline.


826-830: More explicit condition for path modifier application

The condition now explicitly checks for from_callable is not None instead of relying on its truthiness, which makes the code more robust and consistent with the changes to preserve the callable object.


835-835: Passing the callable object to concretize

Correctly updates the concretize function call to pass the actual callable object rather than just a boolean flag.


850-864: Core implementation of flag inheritance from input functions

This is the key change that implements the feature to inherit flags from input functions. The function now:

  1. Takes the actual callable object instead of just a boolean flag
  2. Correctly checks if the callable has a flags attribute
  3. Transfers flags from the callable to the IOFile but only if they don't already exist

The implementation is clean and aligns perfectly with the PR's purpose of fixing flag inheritance from input functions.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 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.

@johanneskoester johanneskoester merged commit 6bd981e into main Mar 26, 2025
@johanneskoester johanneskoester deleted the fix/inherit-flags branch March 26, 2025 12:24
johanneskoester pushed a commit that referenced this pull request Mar 26, 2025
🤖 I have created a release *beep* *boop*
---


##
[9.1.2](v9.1.1...v9.1.2)
(2025-03-26)


### Bug Fixes

* inherit flags of input functions
([#3483](#3483))
([6bd981e](6bd981e))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
@coderabbitai coderabbitai Bot mentioned this pull request Apr 1, 2025
2 tasks
kjohnsen pushed a commit to kjohnsen/snakemake that referenced this pull request Dec 15, 2025
### 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**
- Introduced dynamic input filename generation based on dataset
parameters, offering more flexible and intuitive file specification in
workflows.

- **Refactor**
- Enhanced the underlying input processing logic to improve consistency
and reliability when handling user-defined file patterns.

<!-- 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.2](snakemake/snakemake@v9.1.1...v9.1.2)
(2025-03-26)


### Bug Fixes

* inherit flags of input functions
([snakemake#3483](snakemake#3483))
([6bd981e](snakemake@6bd981e))

---
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