Skip to content

fixes for #209 #129 #193 #267#270

Merged
mbhall88 merged 3 commits intosnakemake:masterfrom
mbhall88:master
Feb 9, 2026
Merged

fixes for #209 #129 #193 #267#270
mbhall88 merged 3 commits intosnakemake:masterfrom
mbhall88:master

Conversation

@mbhall88
Copy link
Member

@mbhall88 mbhall88 commented Jan 25, 2026

closes #209

We had implicitly resolved this issue when we updated our snakemake supported dev version

I didn't do these tests the same way as we always necessarily do them (i.e. with the expected formatted code) because we are just testing this syntax doesn't raise an issue.

also closes #129 and closes #193 and closes #267

Summary by CodeRabbit

  • Bug Fixes

    • Improved error handling for parameter formatting with fallback fallback mechanism
    • Enhanced comment whitespace preservation in indented code blocks
    • Refined inline comment handling during parameter parsing
  • Tests

    • Added comprehensive test suite for Snakemake v8/v9 features including resource directives and module support
    • Expanded test coverage for shell blocks, string types, and comment formatting

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Jan 25, 2026

📝 Walkthrough

Walkthrough

Updates to parsing and formatting to support Snakemake v8/v9 features: resource_scopes grammar changed to a parameter-list form, formatter adds a Black-parsing fallback, comment/whitespace handling adjusted in parser/syntax, and new tests covering v8/v9 directives and run-block formatting added.

Changes

Cohort / File(s) Summary
Grammar change
snakefmt/parser/grammar.py
Changed SnakeGlobal.spec.resource_scopes from Context(None, KeywordSyntax) to Context(None, ParamList), switching parsing expectation for resource_scopes to a param-list form.
Formatter fallback
snakefmt/formatter.py
Wraps run_black_format_str in try/except for InvalidPython; on failure wraps value in parentheses and retries with no_nesting=True as a fallback formatting path.
Parser comment/whitespace handling
snakefmt/parser/parser.py, snakefmt/parser/syntax.py
Adjusts comment-leading whitespace calculation to subtract block indent when buffering COMMENT after newline; changes how COMMENT tokens are attached to parameters — only adds as param comment when inline or already processed, otherwise incorporates comment into parameter value.
v8/v9 feature tests
tests/test_v8_v9_features.py
New test module adding TestSnakemakeV8V9Features with tests for global conda, module, use rule blocks, storage, resource_scopes, new rule properties, input/output flags, and pathvars.
Formatter tests (run blocks & shell cases)
tests/test_formatter.py
Adds tests for mixed string types in shell blocks, inline/interspersed comments in shell blocks, and a regression test for comment indentation inside run blocks.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 3 | ❌ 2
❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 29.41% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title references issue numbers (#209 #129 #193 #267) but does not clearly describe the main change: adding support for Snakemake v8/v9 syntax with grammar updates and new tests. Consider revising the title to be more descriptive, such as 'Add support for Snakemake v8/v9 syntax features' or 'Update grammar and add tests for v8/v9 features'. Bare issue references lack context for someone scanning commit history.
✅ Passed checks (3 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The PR successfully addresses issue #209 by implementing grammar changes (resource_scopes Context update), error handling (InvalidPython fallback), and comprehensive test coverage for v8/v9 features.
Out of Scope Changes check ✅ Passed All changes align with the PR objective: grammar updates for v8/v9 syntax, parser fixes for comment handling and indentation, formatter error handling, and test coverage for new features.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@mbhall88 mbhall88 requested a review from bricoletc January 25, 2026 10:55
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@tests/test_formatter.py`:
- Around line 955-968: In the test_shell_interspersed_comments test, remove the
unnecessary inline noqa directive on the comment line that currently reads "#
Merge overlapping coordinates into individual expanded records  # noqa: E501"
(inside the snakecode string); update the string in
test_shell_interspersed_comments so the long comment no longer contains " #
noqa: E501" and ensure the test still asserts formatter.get_formatted() ==
snakecode.

Comment on lines +955 to +968
def test_shell_interspersed_comments(self):
"""https://github.com/snakemake/snakefmt/issues/193"""
snakecode = (
"rule:\n"
f"{TAB * 1}shell:\n"
f"{TAB * 2}# Concatenate all the files together\n"
f'{TAB * 2}"cat {{input:q}} 2> {{log.cat:q}} | "\n'
f"{TAB * 2}# Coordinate sort everything\n"
f'{TAB * 2}+"sortBed 2> {{log.sort:q}} | "\n'
f"{TAB * 2}# Merge overlapping coordinates into individual expanded records\n" # noqa: E501
f'{TAB * 2}+"mergeBed 2> {{log.merge:q}} 1> {{output:q}}"\n'
)
formatter = setup_formatter(snakecode)
assert formatter.get_formatted() == snakecode
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Remove unused noqa directive on line 964.

Static analysis indicates the # noqa: E501 comment is unnecessary since the line doesn't actually trigger an E501 violation.

Suggested fix
-            f"{TAB * 2}# Merge overlapping coordinates into individual expanded records\n"  # noqa: E501
+            f"{TAB * 2}# Merge overlapping coordinates into individual expanded records\n"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
def test_shell_interspersed_comments(self):
"""https://github.com/snakemake/snakefmt/issues/193"""
snakecode = (
"rule:\n"
f"{TAB * 1}shell:\n"
f"{TAB * 2}# Concatenate all the files together\n"
f'{TAB * 2}"cat {{input:q}} 2> {{log.cat:q}} | "\n'
f"{TAB * 2}# Coordinate sort everything\n"
f'{TAB * 2}+"sortBed 2> {{log.sort:q}} | "\n'
f"{TAB * 2}# Merge overlapping coordinates into individual expanded records\n" # noqa: E501
f'{TAB * 2}+"mergeBed 2> {{log.merge:q}} 1> {{output:q}}"\n'
)
formatter = setup_formatter(snakecode)
assert formatter.get_formatted() == snakecode
def test_shell_interspersed_comments(self):
"""https://github.com/snakemake/snakefmt/issues/193"""
snakecode = (
"rule:\n"
f"{TAB * 1}shell:\n"
f"{TAB * 2}# Concatenate all the files together\n"
f'{TAB * 2}"cat {{input:q}} 2> {{log.cat:q}} | "\n'
f"{TAB * 2}# Coordinate sort everything\n"
f'{TAB * 2}+"sortBed 2> {{log.sort:q}} | "\n'
f"{TAB * 2}# Merge overlapping coordinates into individual expanded records\n"
f'{TAB * 2}+"mergeBed 2> {{log.merge:q}} 1> {{output:q}}"\n'
)
formatter = setup_formatter(snakecode)
assert formatter.get_formatted() == snakecode
🧰 Tools
🪛 Ruff (0.14.14)

[warning] 964-964: Unused noqa directive (non-enabled: E501)

Remove unused noqa directive

(RUF100)

🤖 Prompt for AI Agents
In `@tests/test_formatter.py` around lines 955 - 968, In the
test_shell_interspersed_comments test, remove the unnecessary inline noqa
directive on the comment line that currently reads "# Merge overlapping
coordinates into individual expanded records  # noqa: E501" (inside the
snakecode string); update the string in test_shell_interspersed_comments so the
long comment no longer contains " # noqa: E501" and ensure the test still
asserts formatter.get_formatted() == snakecode.

@mbhall88 mbhall88 changed the title test: v8 and v9 support [#209] fixes for #209 #129 #193 #267 Feb 1, 2026
@mbhall88
Copy link
Member Author

mbhall88 commented Feb 1, 2026

PR title check is failing but that doesn't matter as I will do a rebase merge of the PR, so the title won't end up as a commit.

@mbhall88 mbhall88 merged commit 5fc754d into snakemake:master Feb 9, 2026
9 of 11 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

1 participant