JetBrains-Research / snakecharm

Plugin for PyCharm / IntelliJ IDEA Platform IDEs which adds support for Snakemake language.
MIT License
61 stars 7 forks source link

[8.3.0] Inspeciton False Positive: Unresolved reference for: lookup, evaluate, branch, collect, exists #548

Closed iromeo closed 1 month ago

iromeo commented 1 month ago
def foo():
    if not exists("test.txt"):
        raise ValueError("File does not exist")

foo()

works in 8.20.6

iromeo commented 1 month ago

Also lookup, evaluate, branch, collect, exists

See snakemake/ioutils.py: registered with other via:


def register_in_globals(_globals):
    _globals.update(
        {
            "lookup": lookup,
            "evaluate": evaluate,
            "branch": branch,
            "collect": collect,
            "exists": exists,
        }
    )
iromeo commented 1 month ago
import pandas as pd

samples = pd.read_csv("samples.tsv", sep="\t")

configfile: "config.yaml"

assert lookup(dpath="does/not/exist", within=config, default=None) is None
assert lookup(dpath="does/not/exist", within=config, default=5) == 5

rule all:
    input:
        "results/switch~someswitch.column~sample.txt",

rule a:
    output:
        "a/{sample}.txt",
    shell:
        "echo a > {output}"

rule b:
    input:
        branch(evaluate("{sample} == '100'"), then="a/{sample}.txt"),
    output:
        "b/{sample}.txt",
    shell:
        "echo b > {output}"

rule c:
    input:
        branch(
            evaluate("{sample} == '1'"),
            then="a/{sample}.txt",
            otherwise="b/{sample}.txt",
        ),
    output:
        "c/{sample}.txt",
    shell:
        "cat {input} > {output}"

rule d:
    output:
        "test.txt",
    shell:
        "echo d > {output}"

rule e:
    input:
        collect("c/{item.sample}.txt", item=lookup(query="{col} <= 2", within=samples)),
        branch(lookup(dpath="switches/{switch}", within=config), then="test.txt"),
    output:
        "results/switch~{switch}.column~{col}.txt",
    shell:
        "cat {input} > {output}"
iromeo commented 1 month ago

exists added in 8.9.0 - https://github.com/snakemake/snakemake/commit/ee9639385cb2c9cec425800088faee4e4bf77c9a