Skip to content

Python 3.12 break f string inside Snakemake #2480

@DrYak

Description

@DrYak

Snakemake version
Tested with snakemake 7.34.2
(older version are affected, too. Tested down to 7.18.2)

Affected Python version: 3.12.0
(Last known good: Python 3.11.6)

Describe the bug

When snakemake is installed with python version 3.12.0, f-strings get unexpected extra space.

For example:

output: f'{PREFIX}.txt'

will produce...

Logs

...this output in the log (note the unexpected extra spaces):

Building DAG of jobs...
File path ' SID23454678 .txt ' starts with whitespace. This is likely unintended. It can also lead to inconsistent results of the file-matching approach used by Snakemake.
File path ' SID23454678 .txt ' ends with whitespace. This is likely unintended. It can also lead to inconsistent results of the file-matching approach used by Snakemake.

When run on python 3.12.0

Minimal example

UnitTest.smk:

#!/usr/bin/env python3
PREFIX = 'SID23454678'
rule unit1:
 input:
 output:
  f'{PREFIX}.txt'
 run:     
   "sleep 1"

Running with:

snakemake --dry-run -s UnitTest.smk --cores 1

In this environment... :

mamba create -n snake-test -c conda-forge -c bioconda snakemake-minimal=7.32.4 python=3.11

...everything work as expected:

[Thu Oct 12 15:55:02 2023]
rule unit1:
    output: SID23454678.txt
    jobid: 0
    reason: Missing output files: SID23454678.txt
    resources: tmpdir=/tmp

But in that environment...:

mamba create -n snake-test -c conda-forge -c bioconda snakemake-minimal=7.32.4 python=3.12

...the bug is triggered:

Building DAG of jobs...
File path ' SID23454678 .txt ' starts with whitespace. This is likely unintended. It can also lead to inconsistent results of the file-matching approach used by Snakemake.
File path ' SID23454678 .txt ' ends with whitespace. This is likely unintended. It can also lead to inconsistent results of the file-matching approach used by Snakemake.

Additional context

Apparently, the f-string have been completely overhauled as part of python 3.12. I suspect the new f-string parser somehow clashes with the parse of snakemake files.

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