-
Notifications
You must be signed in to change notification settings - Fork 1
/
update-conda-yaml.py
executable file
·59 lines (46 loc) · 1.57 KB
/
update-conda-yaml.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
#!/usr/bin/env python
import os
import sys
import traceback
import subprocess as sp
def read_file(fname):
content = []
with open(fname) as f:
for line in f:
content.append(line)
# you may also want to remove whitespace characters like `\n` at the end of each line
content = [x.strip("\n") for x in content]
return content
def main(new_git_rev):
meta_file = os.path.join("recipe", "meta.yaml")
content = read_file(meta_file)
fm = open(meta_file, "w")
old_git_rev = ""
for itr in content:
lstrip = itr.strip().strip("-").strip("\t")
entries = lstrip.split()
if len(entries) > 1:
if entries[0] == "git_rev:":
old_git_rev = entries[1]
itr = itr.replace(old_git_rev, new_git_rev)
fm.write("{}\n".format(itr))
print("{}".format(itr))
fm.close()
print("\nOld git revision: {}".format(old_git_rev))
print("\nNew git revision: {}\n".format(new_git_rev))
if __name__ == "__main__":
try:
git_rev = ""
if len(sys.argv) < 2:
process = sp.Popen(["git", "rev-parse", "HEAD"], stdout=sp.PIPE)
out, err = process.communicate()
git_rev = "{}".format(out.decode("utf-8").strip())
else:
git_rev = sys.argv[1]
main(git_rev)
except Exception as e:
print("Error running pyctest - {}".format(e))
exc_type, exc_value, exc_trback = sys.exc_info()
traceback.print_exception(exc_type, exc_value, exc_trback, limit=10)
sys.exit(1)
sys.exit(0)