def conda_func(wildcards, params):
    env_name = f"{params.name_prefix}-test-env-{wildcards.version}"
    shell(
        f"conda create -y -n {env_name} -c conda-forge --override-channels ripgrep=={wildcards.version}"
    )
    return env_name


onsuccess:
    shell("conda env remove -y -n foo-test-env-12.1.1")
    shell("conda env remove -y -n foo-test-env-13.0.0")


onerror:
    shell("conda env remove -y -n foo-test-env-12.1.1")
    shell("conda env remove -y -n foo-test-env-13.0.0")


rule all:
    input:
        "test_13.0.0_v.out",
        "test_12.1.1_v.out",


rule a:
    output:
        "test_{version}_v.out",
    log:
        err="test_{version}.log",
    params:
        name_prefix="foo",
    conda:
        conda_func
    shell:
        r"(rg --version | grep -o 'ripgrep [0-9]*\.[0-9]*\.[0-9]*' > {output}) 2> {log.err}"
