JetBrains-Research / snakecharm

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

Unresolved reference 'snakemake' #511

Closed iquasere closed 1 month ago

iquasere commented 10 months ago

I never got, on my MacBook Pro M2, snakemake recognized. Is this working as designed? The pipeline runs fine.

image

SnakeCharm version: 2023.2.1

iromeo commented 7 months ago

Hi, as a workaround, you could add manually import snakemake line, it will not affect pipeline, but will help with static code analysis. Snakemake executes a snakemake file in a special environment, where some objects are inserted dynamically, so snakemake module will be available on runtime, but SnakeCharm codeInsight engine doesn't emulates this at the moment.

iromeo commented 6 months ago

@iquasere Is it .smk or Snakefile or just some .py file with wrapper impl?

iquasere commented 6 months ago

Thank you for the answer, @iromeo !

This is happening only for the .py scripts, although the .smk files have another problem, where it doesn't recognize stuff coming from the common.smk script.

image

Still, the most annoying is in the *.py files.

Hi, as a workaround, you could add manually import snakemake line

This turned all the errors into warnings, which is better. I guess it wouldn't make sense to have a params attribute in snakemake's __init__

image
iromeo commented 1 month ago

@iquasere

where it doesn't recognize stuff coming from the common.smk script.

Thx for mentioning that, it is known problem https://github.com/JetBrains-Research/snakecharm/issues/364. Snakemake files don't follow Python conventions on how code from different modules is imported. Instead snakemake framework assemble a context depending on the Snakefile content. So if you run you Snakefile that first includes common.smk, then some foo.smk, all content from common.smk will be available in foo.smk. But if you specify foo.smk as enty point, then common.smk will not be avaiable. Snakecharm plugin should definitely emulate such logic to avoid such false alerts.

*.py scripts,

The similar case for *.py scripts used inside snakemake. From python point such scripts doesn't work independently as valid python files. Again we need to somehow differentiate python files that could have such usage from other files where snakefile will be indeed unresolved.


You could always disable some false alerts using 'suppress' action for any inspection.

image image

as alternative, you could add identifiers (e.g. OUTPUT) for which unresolved reference will not be shown in 'Unresolved references' inspections settings:

image
iromeo commented 1 month ago

I added workaround, so unresolved snakemake runtime-injected variable will not be shown as error here, e.g.:

image image