Reputation: 1708
I'm using Snakemake and it's been rather enjoyable, but I would love it if VSCode stopped complaining about Undefined variable: 'snakemake'
. The issue is that Snakemake runs jobs in such a way that it injects this global into your python scope, but IDEs have no idea that it really is defined. I am wondering if there is a way to get it to do two things:
Snakefile
(input, output, params, etc.) and its own APIs.The VSCode extension for Snakemake only relates to the Snakefile syntax. Elsewhere VSCode uses pylint.
Any ideas?
Upvotes: 4
Views: 674
Reputation: 11
Not sure if it would work for you since your warning seems to come from python itself and not pylint (which was the case for me), but I just found a solution that worked for me here.
I added to my pylint settings the following argument:
"--dummy-variables-rgx='(_+[a-zA-Z0-9]*?$)|dummy|snakemake'"
To do so, you can access your settings with ctr + ,, search for "pylint:Args" and click on Add Item
.
Basically, "(_+[a-zA-Z0-9]*?$)|dummy" is the default regex for the dummy variables (ignored by pylint) and by adding "snakemake" to it, this variable name doesn't produce pylint warnings anymore.
Upvotes: 1
Reputation: 92
This won't remove the error, but it will disable all error messages. Hit Ctrl-Shift-P and type disable error messages
in the top. Click that and they will completely disappear (it won't fix the errors though)
Upvotes: 0
Reputation: 616
Only slightly better than the other answer is to do:
smk = snakemake # type: ignore
mlp = load_python_obj(smk.input.mlp_model_filename)
This inlines the exclusion to that one line (where snakemake
is undefined), but allows the definition of smk
so that when when you refer to smk
there is no complaint. This allows other relevant cases of undefined variables to still be identified rather than excluding all of them.
Upvotes: 2
Reputation: 11
This is a terrible solution, but thus far the only one that I have managed to find. I hope that this non-solution can be quickly supplanted by a better one.
At the top of the script file you can add
# pyright: reportUndefinedVariable=false
This removes the warning (and all other undefined variable warnings). If you have flake8 as well, you will have to use # noqa: F821
on each line as well.
Upvotes: 1