Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save jerowe/dde6bd2fd58be54e43ccff6d8fd9975f to your computer and use it in GitHub Desktop.

Select an option

Save jerowe/dde6bd2fd58be54e43ccff6d8fd9975f to your computer and use it in GitHub Desktop.
#!/usr/bin/env python2
import argparse
import subprocess
import os
parser = argparse.ArgumentParser(description='Install things')
parser.add_argument('--instdir', help='you must supply an installdir')
parser.add_argument('--requirements', nargs='?', help='optionally supply a list of packages to install', required=False)
parser.add_argument('--channels', nargs='+', help='optionally supply a list of channels to search', required=False)
args = parser.parse_args()
if args.instdir:
subprocess.call("conda config --add create_default_packages setuptools", shell=True)
subprocess.call("conda env remove -y -p {}".format(args.instdir), shell=True)
subprocess.call("conda create -y --no-deps -p {}".format(args.instdir), shell=True)
if args.channels:
channels = ""
for n in args.channels:
channels += "-c {} ".format(n)
if args.requirements:
myEnv = os.environ.copy()
myEnv["PATH"] = "{}/bin".format(args.instdir) + ":" + myEnv["PATH"]
myEnv["CONDA_ENV"] = args.instdir
myEnv["CONDA_DEFAULT_ENV"] = args.instdir
if args.channels:
cmd = "conda install -y --file {} {}".format(args.requirements, channels)
else:
cmd = "conda install -y --file {} ".format(args.requirements)
subprocess.call(cmd, shell=True, env = myEnv)
print('Running conda install ', cmd)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment