Despite what commenters have said in issue #2350, this phenomenon of Snakemake running the python code twice is a feature, not a bug, and it's not going to be "fixed". Even if the behaviour was changed for the simple -j1
case it will still manifest as soon as you allow parallel jobs or submit your jobs to a HPC cluster (this includes your fixed code, @antje-janosch!)
The actual bug in this code is on line 16. If you replace {tarfile}
with "{tarfile}"
(only on line 16, not line 12) in the original example you will find that it works, just by adding the two quotes.
The difference is this: {tarfile}
means "a python set containing the single fixed string from the variable tarfile", whereas "{tarfile}"
is a template string that will act as a placeholder for any filename. These are not the same!