forked from conda/menuinst
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cwp.py
44 lines (37 loc) · 1.64 KB
/
cwp.py
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
32
33
34
35
36
37
38
39
40
41
42
43
44
# 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
import argparse
from menuinst.knownfolders import FOLDERID, get_folder_path, PathNotFoundException
# call as: python cwp.py [--no-console] PREFIX ARGs...
parser = argparse.ArgumentParser()
parser.add_argument("--no-console", action="store_true",
help="Create subprocess with CREATE_NO_WINDOW flag.")
parser.add_argument("prefix",
help="Prefix to be 'activated' before calling `args`.")
parser.add_argument("args", nargs="*",
help="Command (and arguments) to be executed.")
parsed_args = parser.parse_args()
no_console = parsed_args.no_console
prefix = parsed_args.prefix
args = parsed_args.args
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
documents_folder, exception = get_folder_path(FOLDERID.Documents)
if exception:
documents_folder, exception = get_folder_path(FOLDERID.PublicDocuments)
if not exception:
os.chdir(documents_folder)
creationflags = {}
if no_console:
creationflags["creationflags"] = getattr(subprocess, "CREATE_NO_WINDOW", 0x08000000)
sys.exit(subprocess.call(args, env=env, **creationflags))