Search code examples
pythoncondasnakemake

Snakemake: How to force the creation of all conda environments


I am aware that by adding the option --conda-create-envs-only you are able to create the conda environments for the workflow. However, would it be possible to force the creation of all conda environments under workflow/envs/ without knowing the workflow DAG in advance?

The reason is that I am planning to run snakemake on an HPC, and the compute nodes have no internet. As such I have to set up the environment in a build node with internet. The problem is that I can only access my input data in the compute nodes.


Solution

  • Maybe make the creation of the conda environments a target itself? Something like, not tested:

    localrules: all, make_envs
    
    rule all:
        input:
            # Maybe not needed:
            expand('{env}.done', env= ['env1', 'env2'])
    
    
    rule make_envs:
        conda:
            'workflow/envs/{env}.yaml',
        output:
            touch('{env}.done'),
    
    
    rule one:
        input:
            'env1.done',
        conda:
            'workflow/envs/env1.yaml',
        output: ...
        shell: ...
    

    Rule one will find the conda env created because it needs env1.done as input