Josh Loecker
Josh Loecker

Reputation: 386

Getting command line flags from snakemake

Is it possible to retrieve the flags used on the command line? For example, I want to force the use conda for my workflow, as I have set up environments for various rules. This allows me to control package versions, and users don't have to install packages manually. This is what I would like to do:

When on the command line, I use this command:
snakemake --cores 10

I can then detect the usage of these flags. For example:

if snakemake.flags.use_conda == False:
    print("You must use conda!")
    exit(1)

I know this isn't exactly perfect, but I hope my intentions are clear.

Thanks for any help!

Upvotes: 1

Views: 150

Answers (1)

dariober
dariober

Reputation: 9062

Maybe:

if not workflow.use_conda:
    sys.stderr.write("Use conda\n")
    sys.exit(1)

Note that sys.exit makes snakemake give an ugly error trace - I vaguely remember a hacky workaround which I cannot find now...

Upvotes: 1

Related Questions