-
Notifications
You must be signed in to change notification settings - Fork 37
/
install_metrics_from_branches.py
executable file
·145 lines (122 loc) · 3.95 KB
/
install_metrics_from_branches.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/usr/bin/env python
import argparse
import time
import subprocess
import os
import sys
import shlex
loc = time.localtime()
today = "%s.%s.%s" % (loc.tm_year, loc.tm_mon, loc.tm_mday)
P = argparse.ArgumentParser(
description='Merge many branches into a conda env',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
c = P.add_argument_group('CONDA')
c.add_argument("-e", "--env", default=today, help="conda env to install into")
c.add_argument("-x", "--extra", default="", help="extra packages and channels you need")
c.add_argument(
"-M",
"--no-mesa",
default=False,
action="store_true",
help="turn on/off mesa")
c.add_argument(
"-n",
"--no-nightly",
default=False,
action="store_true",
help="turn on/off mesa")
b = P.add_argument_group('Repositories')
b.add_argument(
"-m",
"--metrics",
default=["master"],
nargs="*",
help="metrics branches to merge in")
b.add_argument("-r", "--repo", default="PCMDI/pcmdi_metrics",
help="metrics repo to use")
b.add_argument(
"-v",
"--vcs",
default=["master"],
nargs="*",
help="vcs branches to merge")
b.add_argument(
"-c",
"--cdms",
default=["master"],
nargs="*",
help="cdms branches to merge")
loc = P.add_argument_group('Local Setup')
loc.add_argument("-g", "--git", default=os.path.expanduser("~/git"),
help="top directory where you will clone your git repos")
args = P.parse_args(sys.argv[1:])
sp = args.repo.split("/")
metrics_repo = sp[0]
metrics_name = "/".join(sp[1:])
def execute_cmd(cmd, path=os.getcwd()):
print("Executing: %s in: %s" % (cmd, path))
p = subprocess.Popen(shlex.split(cmd), cwd=path)
o, e = p.communicate()
return o, e
def merge_branches(repo_pth, branches):
execute_cmd("git checkout master", path=repo_pth)
execute_cmd("git reset --hard origin/master", path=repo_pth)
execute_cmd("git pull", path=repo_pth)
for b in branches:
execute_cmd("git merge --no-commit origin/%s" % b, path=repo_pth)
# Make sure we yank conda
execute_cmd("conda clean --lock")
execute_cmd("conda remove -n %s -y --all" % args.env)
if args.no_mesa:
pname = ""
else:
pname = "-nox"
if args.no_nightly:
nightly = ""
else:
nightly = "-c uvcdat/label/nightly"
# Create conda env
execute_cmd(
"conda create -y -n %s %s -c uvcdat %s ipython output_viewer eztemplate vcsaddons%s cdms2 vcs%s hdf5=1.8.16 " %
(args.env, nightly, args.extra, pname, pname))
# Setup GIT
if not os.path.exists(args.git):
os.makedirs(args.git)
# Loop through vcs branches
execute_cmd("git clone git:https://github.com/UV-CDAT/vcs", path=args.git)
vcs_pth = os.path.join(args.git, "vcs")
merge_branches(vcs_pth, args.vcs)
# Loop through cdms branches
execute_cmd("git clone git:https://github.com/UV-CDAT/cdms", path=args.git)
cdms_pth = os.path.join(args.git, "cdms")
merge_branches(cdms_pth, args.cdms)
# Loop through metrics branches
execute_cmd("git clone git:https://github.com/%s" % metrics_repo, path=args.git)
metrics_pth = os.path.join(args.git, metrics_name)
merge_branches(metrics_pth, args.metrics)
f = open("install_in_env.bash", "w")
print >> f, "#!/usr/bin/env bash"
print >>f, "source activate %s" % args.env
print >>f, "conda uninstall -y openblas"
if args.vcs != ["master"]:
print >>f, "cd %s" % vcs_pth
print >>f, "rm -rf build"
print >>f, "python setup.py install --old-and-unmanageable"
if args.cdms != ["master"]:
print >>f, "cd %s" % cdms_pth
print >>f, "rm -rf build"
print >>f, "python setup.py install"
print >>f, "cd %s" % metrics_pth
print >>f, "rm -rf build"
print >>f, "python setup.py install"
f.close()
execute_cmd("bash install_in_env.bash")
print(
"You should be good to go, we merged vcs branches:" +
"'%s' cdms branches: '%s' and metrics branches '%s' into conda env: '%s'" %
(" ".join(
args.vcs), " ".join(
args.cdms), " ".join(
args.metrics), args.env))
print("now run")
print("source activate %s" % args.env)