Error from `min_version` should be prioritized
Is your feature request related to a problem? Please describe.
Ideally, the snakemake.utils.min_version function checks for a minimum version and raises a WorkflowError when that is not satisfied. However, in practice it often fails to provide value. For example, the use of min_version("6.0") to ensure support for module declarations never yields a WorkflowError when using versions below v6.0, but instead ends with SyntaxError. This undermines using it.
I have not dug into the code, but the behavior would suggest that a first pass of parsing occurred (at least in pre-6.0 versions) prior to any code evaluation.
Describe the solution you'd like
Ensure that a min_version call appearing anywhere in a Snakefile is evaluated with priority so that version issues propagate to the user rather than syntax errors. Perhaps if the regular parsing fails, it could be caught before propagating and a rudimentary check for min_version calls could be made and reported.
Describe alternatives you've considered
I declare in documentation minimum Snakemake versions.
Possibly it should be documented that min_version, even at the top of a Snakefile, does not guarantee a WorkflowError.
Additional context I realize the criticism here is about behavior of older versions and I don't expect any retroactive patching. However, I couldn't find previous threads that raised this particular point so that it could be addressed in versions moving forward.
Minimal example
Snakefile
from snakemake.utils import min_version
min_version("6.0")
rule all:
input: "b.txt"
module a_factory:
snakefile: "a_factory.smk"
use rule * from a_factory
rule b_from_a:
input: "a.txt"
output: "b.txt"
shell: "echo 'found {input}' > {output}"
a_factory.smk
rule make_a:
output: "a.txt"
shell: "echo 'Made in A Factory' > {output}"
Result in Snakemake v5.29
$ snakemake -np
SyntaxError in line 7 of /Users/mfansler/scratch/smk-version-fail/Snakefile:
invalid syntax
But it seems this behavior doesn't happen in the latest releases
But it seems this behavior doesn't happen in the latest releases
Do you have an example? That is, a Snakefile that uses a syntactic feature requiring a minimum, and running a Snakemake below that minimum leads to the minimum violation being detected instead of a syntax error.
But it seems this behavior doesn't happen in the latest releases
Do you have an example? That is, a Snakefile that uses a syntactic feature requiring a minimum, and running a Snakemake below that minimum leads to the minimum violation being detected instead of a syntax error.
I did a quick test in snakemake version 8.4.3 with the same minimal example you provided and I only changed min_version("6.0") to min_version("9.0")
and I got the following result
$ snakemake -np
WorkflowError:
Expecting Snakemake version 9.0 or higher (you are currently using 8.4.3).
@MarwanMabrouk that test does not satisfy the specifications. Perhaps I should clarify that when I said "that uses a syntactic feature requiring a minimum" I intended it as requiring the specific minimum. A relevant test should be using some new syntax that was introduced in the minimum version (i.e., v9.0 in this case).