File: conda_env.py

package info (click to toggle)
qcengine 0.30.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,524 kB
  • sloc: python: 36,452; makefile: 54; sh: 35
file content (31 lines) | stat: -rw-r--r-- 1,118 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import argparse
import os
import shutil
import subprocess as sp

# Args
parser = argparse.ArgumentParser(description='Creates a conda environment from file for a given Python version.')
parser.add_argument('-n', '--name', type=str, nargs=1, help='The name of the created Python environment')
parser.add_argument('-p', '--python', type=str, nargs=1, help='The version of the created Python environment')
parser.add_argument('conda_file', nargs='*', help='The file for the created Python environment')

args = parser.parse_args()

with open(args.conda_file[0], "r") as handle:
    script = handle.read()

tmp_file = "tmp_env.yaml"
script = script.replace("- python", "- python {}*".format(args.python[0]))

with open(tmp_file, "w") as handle:
    handle.write(script)

conda_path = shutil.which("conda")

print("CONDA ENV NAME  {}".format(args.name[0]))
print("PYTHON VERSION  {}".format(args.python[0]))
print("CONDA FILE NAME {}".format(args.conda_file[0]))
print("CONDA path      {}".format(conda_path))

sp.call("{} env create -n {} -f {}".format(conda_path, args.name[0], tmp_file), shell=True)
os.unlink(tmp_file)