snakemake icon indicating copy to clipboard operation
snakemake copied to clipboard

Linting interprets command string starting with / wrongly as path

Open seb-mueller opened this issue 3 years ago • 2 comments

Snakemake version

7.12.1 (latest stable)

Describe the bug

When linting the the rule below using snakemake --lint --cores 1, snakemake complains about "Absolute path" (see Logs below) even though the intended command has nothing to do with any paths. I believe it is interpreting the / at the beginning of the string and assumes it is a path, which of course it isn't. Could linting be made more smart to recognize and handle those cases correctly?

Logs

Lints for snakefile /home/seb/workspace/dolomite/code/scpipe/workflow/rules/star.smk:
    * Absolute path "/^[0-9]+[ ]+[0-9]+[ ]+[0-9]+/ {{print $0}}" in line 225:
      Do not define absolute paths inside of the workflow, since this renders your workflow irreproducible on other machines. Use path relative to the working directory instead, or make the path configurable via a config file.
      Also see:
      https://snakemake.readthedocs.io/en/latest/snakefiles/configuration.html#configuration

Minimal example

rule awk_convert:
   input:
      "in.txt"
   output:
      "out.txt"
    shell:
        """
        awk '/^[0-9]+[ ]+[0-9]+[ ]+[0-9]+/ {{print $0}}' {input} > {output}
        """

Additional context

`

seb-mueller avatar Aug 17 '22 12:08 seb-mueller

Similar thing happened to me. Line was roughly

link="https://.../filename"
filename=f"{link.split('/')[-1]"

chillenzer avatar Feb 05 '23 22:02 chillenzer

Version 8.20.6 (latest stable at this moment)

samples.loc[:, "sample_id"] = [
    line.split("/")[-2] for line in samples["path_to_sample"]
]

Gives false positive for this piece of code as well.

Strexas avatar Oct 08 '24 11:10 Strexas