Skip to content

fix: allowing trailing '+' in name patterns#3002

Merged
johanneskoester merged 3 commits intomainfrom
fix/issue3001
Aug 13, 2024
Merged

fix: allowing trailing '+' in name patterns#3002
johanneskoester merged 3 commits intomainfrom
fix/issue3001

Conversation

@cmeesters
Copy link
Copy Markdown
Member

@cmeesters cmeesters commented Aug 8, 2024

This PR should fix issue #3001:

A workflow might contain simple regexes within Python code, e.g. r"\s+". Prior to this PR the NAME_PATTERN of the linter considered this first part, the s as part of a string to be concatenated with a path.

QC

There is no additional test (yet. Not sure it needs one). Docs do not need updating as the intended behaviour does not change.

  • 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

    • Improved name validation logic by updating the regex pattern, ensuring that file names do not end with a '+' character, reducing the risk of unintended exclusions.
  • Documentation

    • Added comments to clarify the implications of the regex changes and to suggest alternatives for different separator needs.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Aug 8, 2024

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

@cmeesters
Copy link
Copy Markdown
Member Author

brrrr, I consider this failure unrelated to the PR:

=========================== short test summary info ============================
FAILED tests/tests.py::test_paramspace - AssertionError: wrong result produced for file 'results/sep/simulations/alpha_is_2/beta_is_0.0/gamma_is_3.9.tsv':
------found------
{'alpha': np.int64(2), 'beta': np.float64(0.0), 'gamma': np.float64(3.9)}
-----expected-----
{'alpha': 2, 'beta': 0.0, 'gamma': 3.9}
-----------------
!!!!!!!!!!!!!!!!!!!!!!!!!! stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!
========= 1 failed, 22 passed, 306 deselected, 111 warnings in 51.20s ==========

But, of course, the rest will not run.

@johanneskoester
Copy link
Copy Markdown
Contributor

Seems like the floats are not correctly converted into plain string representations. A fix would be greatly appreciated, I don't have any time in the next days.

@cmeesters
Copy link
Copy Markdown
Member Author

cmeesters commented Aug 8, 2024

Already thought, that a fix might be trivial, but whether I will find the time ... Let's see.

edit: Or perhaps not so trivial - doubt that the actual code needs adaption, because np.float is quit ok and panda-ish. I'll give changing the expected results a try ...

@cmeesters
Copy link
Copy Markdown
Member Author

Definitively not trivial. We could:

  • change the expected results to meet the code output.
  • change the test.
  • change the actual code. I found the spot, it's a tiny lambda function, which could be extended.

All three options sound like tinkering to me.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Aug 12, 2024

Walkthrough

The recent changes enhance the validation logic for naming patterns in the Snakemake linter. By modifying the regular expression for NAME_PATTERN, the update prevents strings from ending with a '+' character, addressing potential user intent while ensuring more accurate name validation. Additionally, the change suggests accommodating simpler regex expressions for varied separator needs, promoting flexibility in file naming conventions.

Changes

Files Change Summary
snakemake/linting/__init__.py Modified NAME_PATTERN regex to prevent trailing '+' characters; added comments on user intent and potential for simpler regex expressions.

Poem

🐇 In the land of code, where rabbits hop,
A regex change makes name checks pop!
No trailing '+' to cause a fright,
With patterns now clearer, everything's right!
Hopping through linting, we dance with glee,
Celebrating changes, just wait and see! 🎉


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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.

@sonarqubecloud
Copy link
Copy Markdown

Copy link
Copy Markdown
Contributor

@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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 715c572 and 12ad41d.

Files selected for processing (1)
  • snakemake/linting/init.py (1 hunks)
Additional comments not posted (1)
snakemake/linting/__init__.py (1)

8-13: Regex modification looks good. Verify its impact on the codebase.

The addition of the negative lookahead (?!\\+) in the NAME_PATTERN regex is well-implemented and aligns with the PR's objective to prevent trailing '+' characters. The comment provides a clear explanation of the change and potential risks.

To ensure the change does not introduce unintended side effects, verify that all relevant tests pass and that the regex behaves as expected in all scenarios.

@cmeesters
Copy link
Copy Markdown
Member Author

Thank you, @johanneskoester — this PR can now possibly be merged. The coderabit summarizes my intent perfectly. ;-) What do you think?

@johanneskoester johanneskoester merged commit 59150d3 into main Aug 13, 2024
@johanneskoester johanneskoester deleted the fix/issue3001 branch August 13, 2024 09:15
@johanneskoester
Copy link
Copy Markdown
Contributor

Thank you!

@cmeesters
Copy link
Copy Markdown
Member Author

Thank you for the swift review!

johanneskoester pushed a commit that referenced this pull request Aug 13, 2024
🤖 I have created a release *beep* *boop*
---


##
[8.17.0](v8.16.0...v8.17.0)
(2024-08-13)


### Features

* fix job rate limiting with --max-jobs-per-second and introduce the
more flexible --max-jobs-per-timespan
([#3010](#3010))
([9c31257](9c31257))


### Bug Fixes

* Allow hyphens in config keys given on the command line.
([#2998](#2998))
([b70c0db](b70c0db))
* allowing trailing '+' in name patterns
([#3002](#3002))
([59150d3](59150d3))
* print message if not yet enough resources for executing further jobs
([b8df036](b8df036))
* unawaited coroutine sanitize_local_storage_copies
([#2972](#2972))
([715c572](715c572))


### Documentation

* Change sha256 checksum in docs to more realistic example
([#2987](#2987))
([16a5cf2](16a5cf2))
* Make it more clear that the cluster commands now require a plugin
([#2976](#2976))
([74134cf](74134cf))
* Update installation.rst to recommend Miniforge instead of Mambaforge
([#2975](#2975))
([0fc7619](0fc7619))
* use plain monospace font instead of theme default that changes &gt;=
into ≥
([cc17fc1](cc17fc1))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@zhangxiaoxing
Copy link
Copy Markdown

I'm a bit confused here, as a long-running snakefile now produces a new warning:
"/path/to/snakefile:666: SyntaxWarning: invalid escape sequence '\d'"
The line number could not be easily matched back in the snakefile, but somewhere I do have such a line:

output:
    "output/outputfile_{index,\d+}.out"

This is to limit the wildcard matching to only digits. Should I ignore the warning? Should I update the rules? Should I provide more detail?

Thanks!

@cmeesters
Copy link
Copy Markdown
Member Author

Thanks for reporting this!!!

You may ignore the warning. I will not. Can you please indicate the entire rule? Is there, perhaps, more detail to the warning message?

Actually, this PR only affected the linter, not the Snakemake core. So, this might be totally unrelated. But we should sort this out, before perhaps opening a full issue.

@zhangxiaoxing
Copy link
Copy Markdown

zhangxiaoxing commented Aug 15, 2024

Thanks for reporting this!!!

You may ignore the warning. I will not. Can you please indicate the entire rule? Is there, perhaps, more detail to the warning message?

Actually, this PR only affected the linter, not the Snakemake core. So, this might be totally unrelated. But we should sort this out, before perhaps opening a full issue.

It's quite reproducible on my side:

FILE: snaketest

rule plus:                              
    output:                             
        "test{num,\d+}.txt"             
    shell:                              
        '''                             
        touch test{wildcards.num}.txt   
        '''                             

CONSOLE

$ snakemake -s snaketest -n -p --verbose test000.txt
snaketest:4: SyntaxWarning: invalid escape sequence '\d'
  shell:
Building DAG of jobs...
shared_storage_local_copies: True
remote_exec: False
Job stats:
job      count
-----  -------
plus         1
total        1

[Thu Aug 15 20:16:51 2024]
rule plus:
    output: test000.txt
    jobid: 0
    reason: Missing output files: test000.txt
    wildcards: num=000
    resources: tmpdir=<TBD>


        touch test000.txt

... ...

$ conda list | grep snake
# packages in environment at /home/conda/snakemake_py312:
snakemake-executor-plugin-cluster-generic 1.0.9              pyhdfd78af_0    bioconda
snakemake-interface-common 1.17.2             pyhdfd78af_0    bioconda
snakemake-interface-executor-plugins 9.2.0              pyhdfd78af_0    bioconda
snakemake-interface-report-plugins 1.0.0              pyhdfd78af_0    bioconda
snakemake-interface-storage-plugins 3.2.3              pyhdfd78af_0    bioconda
snakemake-minimal         8.18.0             pyhdfd78af_0    bioconda

The execution judging by the shell command is not affected.

Same file and command with Snakemake 8.16.0 does not show this warning.

Snakemake is a very helpful package for me. Thanks a lot !

@cmeesters
Copy link
Copy Markdown
Member Author

Ah, yes, this alone is a faulty syntax expression. Try

output:
     r"test{num,\d+}.txt"

@zhangxiaoxing
Copy link
Copy Markdown

Ah, yes, this alone is a faulty syntax expression. Try

output:
     r"test{num,\d+}.txt"

That indeed fixed the warning. Thanks.

@zhangxiaoxing
Copy link
Copy Markdown

zhangxiaoxing commented Aug 15, 2024

Ah, yes, this alone is a faulty syntax expression. Try

output:
     r"test{num,\d+}.txt"

Still I suggest the documentation to be refined. Currently it's still showing this misleading/faulty syntax...

image

@cmeesters
Copy link
Copy Markdown
Member Author

ah, thanks. It's a Python thing. Will fix the docs.

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.

3 participants