Skip to content

Misformatting of lambda functions in threads: (causing "Unexpected keyword wildcards in rule definition") #208

@karel-brinda

Description

@karel-brinda

Problem description

This is an issues that we encountered when working on MOF-Search.

Snakefmt seems to be unable to parse correctly lambda functions used in the threads: section of rule definitions, due to which it then introduces line breaks in a way that invalidates the original Snakefile.

Example

Original Snakefile

rule decompress_and_run_cobs:
    output: "test"
    threads: lambda wildcards, input: get_number_of_COBS_threads(wildcards, input, predefined_cobs_threads, streaming)
    shell:
        """
        touch {output}
        """

Reformated Snakefile

If I run snakefmt Snakefile, I end up with the following Snakefile:

rule decompress_and_run_cobs:
    output:
        "test",
    threads: lambda wildcards, input: get_number_of_COBS_threads(
    wildcards, input, predefined_cobs_threads, streaming
)
    shell:
        """
        touch {output}
        """

Parsing errors

After which Snakemake fails with the following error:

$ snakemake -j1
SyntaxError in file /private/tmp/~20231128150941/Snakefile, line 5:
Unexpected keyword wildcards in rule definition (Snakefile, line 5)

And Snakefmt cannot be rerun either.

$ snakefmt  Snakefile 
snakefmt.exceptions.InvalidParameterSyntax: 4lambda wildcards , input: get_number_of_COBS_threads(

Version

$ snakefmt --version
snakefmt, version 0.8.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions