Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: Undefined variable: 'snakemake', ignore warning, or ideally autocomplete for real

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:

  1. Stop complaining, at the least
  2. Do autocomplete--it should autocomplete based on the rules defined in the Snakefile (input, output, params, etc.) and its own APIs.

Undefined variable: 'snakemake'

The VSCode extension for Snakemake only relates to the Snakefile syntax. Elsewhere VSCode uses pylint.

Any ideas?

like image 236
wulftone Avatar asked Nov 15 '25 23:11

wulftone


1 Answers

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.

like image 91
alphabetasoup Avatar answered Nov 17 '25 21:11

alphabetasoup



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!