pyiron / docker-stacks

Ready-to-run Docker images containing pyiron applications
https://hub.docker.com/u/pyiron
BSD 3-Clause "New" or "Revised" License
3 stars 1 forks source link

[Feature] Generate the environment file without installing #189

Open jan-janssen opened 9 months ago

jan-janssen commented 9 months ago

At the moment we install the conda environment in the Docker container to primarily get the environment file with all the resolved dependencies. This can also be achieve with a simple dry-run command:

def get_detailed_environment(environment_input_file, environment_output_file):
    output_start = subprocess.check_output(
        ["conda", "env", "create", "-n", "testenv", "-f", environment_input_file, "--dry-run", "--json"], 
        shell=False, 
        universal_newlines=True
    )
    output_start_dict = json.loads(output_start)
    output_dict = output_start_dict.copy()

    if output_dict["name"] is None:
        del output_dict["name"]
    output_dict["dependencies"] = list(sorted([
        dep.split("::")[-1].replace("==", "=") 
        for dep in output_dict["dependencies"]
    ]))
    with open(environment_output_file, "w") as f:
        f.writelines(yaml.dump(output_dict))

    output_extended = subprocess.check_output(
        ["conda", "env", "create", "-n", "testenv", "-f", environment_output_file, "--dry-run", "--json"], 
        shell=False, 
        universal_newlines=True
    )
    output_extended_dict = json.loads(output_extended)
    return output_extended_dict == output_start_dict

So maybe it is possible to first create the conda environment files and then install them in the docker containers.

jan-janssen commented 2 months ago

This technique is used in https://github.com/jan-janssen/shared-conda-environment