JetBrains-Research / snakecharm

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

Inspection False Positive: Unresolved reference 'log' #549

Open iromeo opened 1 month ago

iromeo commented 1 month ago

Should not be shown, works in 8.20.6

log is pipeline log, string variable, not sure where is it added into workflow context

from snakemake.utils import min_version

from snakemake import __version__
print(__version__, file=sys.stderr)

shell.prefix("source ~/.bashrc; ")

#min_version("2.1")

TEST = "abc"

onstart:
    print("Workflow starting")
    print("Log:")
    print(log)

onsuccess:
    print("Workflow finished")
    print("Log:")
    print(log)

onerror:
    print("Workflow failed")
    print("Log:")
    print(log)

ruleorder: rule2 > rule4

def testin(wildcards):
    return "test.in"

def version():
    return "3.3"

rule rule1:
    # This rule creates an intermediate file.
    input: 
        'test.inter'
    output: 'dir/test.out'
    log:    a='log/logfile.log'
    threads: 3
    shell: 
        'if [ {threads} -ne 3 ]; then echo "This test has to be run with -j3 in order to succeed!"; exit 1; fi; ' \
        'echo {TEST}; cp {input[0]} {output[0]}; ' # append a comment
        'echo test > {log.a}'

rule rule2:
    input: testin
    output: 'test.inter'
    message: 'Copying {input[0]} to {output[0]}'
    shell: 
        '''
        cp {input[0]} {output[0]}
        '''

rule rule4:
    input: "test.in"
    output: "test.inter"
    shell: "cp {input} {output}"

# this should be ignored since test.in is present
rule rule3:
    input: "dir/{a}.out"
    output: "{a}.in"
    shell: "cp {input} {output}"
iromeo commented 1 month ago

should be available only in onstart/onerror/onsuccess handlers, not in rule body or toplevel, see https://snakemake.readthedocs.io/en/stable/snakefiles/rules.html#onstart-onsuccess-and-onerror-handlers