Skip to content

Instantly share code, notes, and snippets.

@bdforbes
Created October 18, 2017 05:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bdforbes/9ef59cd01c22acefc20c5c92bd9550ae to your computer and use it in GitHub Desktop.
Save bdforbes/9ef59cd01c22acefc20c5c92bd9550ae to your computer and use it in GitHub Desktop.
# this script is used on windows to wrap shortcuts so that they are executed within an environment
# It only sets the appropriate prefix PATH entries - it does not actually activate environments
import os
import sys
import subprocess
from os.path import join, pathsep
from menuinst.knownfolders import FOLDERID, get_folder_path, PathNotFoundException
# call as: python cwp.py PREFIX ARGs...
prefix = sys.argv[1]
cwd = sys.argv[2]
args = sys.argv[3:]
new_paths = pathsep.join([prefix,
join(prefix, "Library", "mingw-w64", "bin"),
join(prefix, "Library", "usr", "bin"),
join(prefix, "Library", "bin"),
join(prefix, "Scripts")])
env = os.environ.copy()
env['PATH'] = new_paths + pathsep + env['PATH']
env['CONDA_PREFIX'] = prefix
os.chdir(cwd)
sys.exit(subprocess.call(args, env=env))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment