-
Notifications
You must be signed in to change notification settings - Fork 41
/
versioner.py
executable file
·92 lines (79 loc) · 3.22 KB
/
versioner.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
#!/usr/bin/env python
from __future__ import print_function
import re
import sys
import time
import fileinput
import subprocess
# Fetch version from git tags, and write to version.py.
# Also, when git is not available (PyPi package), use stored version.py.
initfile = "ipyrad/__init__.py"
version_git = sys.argv[1]
print("Setting new version to - {}".format(version_git))
# Make sure we you have the current changes in master w/o any
# merge conflicts
try:
subprocess.check_call(["git", "pull"])
except Exception as inst:
sys.exit("You have unmerged conflicts from master. Fix these then "
+ "rerun versioner.py\n{}".format(inst))
# Make sure to track previous release version
prev_version = ""
with open(initfile, 'r') as infile:
for line in infile:
if line.strip().startswith("__version__"):
prev_version = str(line.split("=")[1].strip().strip("\""))
print("last version - {}".format(prev_version))
# Update docs/releasenotes.rst to include commit history for this version
release_file = "newdocs/releasenotes.rst"
# Get all commits since last tag
# git log --pretty=oneline tagA..
cmd = "git log --pretty=oneline {}..".format(prev_version)
new_commits = subprocess.check_output(cmd.split())
# Split off just the first element, cuz we don't care about the
# commit tag
commit_lines = [x.split(b" ", 1) for x in new_commits.split(b"\n")]
checkfor = "Merge branch 'master' of https://github.com/dereneaton/ipyrad"
# Write updates to releasenotes.rst
for line in fileinput.input(release_file, inplace=1):
if line.strip().startswith("=========="):
line += "\n"
line += version_git + "\n"
line += "-" * len(version_git) + "\n"
line += "**" + time.strftime("%B %d, %Y") + "**\n\n"
for commit in commit_lines:
try:
## Convert binary result from git call to ascii
commit = commit[1].decode("ascii")
# Squash merge commits from the releasenotes cuz it annoying
# Also any cosmetic commits
if commit == checkfor:
continue
if "cosmetic" in commit:
continue
line += "- " + commit + "\n"
except:
pass
print(line.strip("\n"))
# Write version to ipyrad/__init__.py
for line in fileinput.input(initfile, inplace=1):
if line.strip().startswith("__version__"):
line = "__version__ = \""+version_git+"\""
print(line.strip("\n"))
try:
subprocess.call(["git", "add", release_file])
subprocess.call(["git", "add", initfile])
subprocess.call(["git", "commit", "-m \"Updating ipyrad/__init__.py to "+\
"version - {}".format(version_git)])
subprocess.call(["git", "push"])
subprocess.call(["git", "tag", "-a", version_git, "-m", "Updating ipyrad to "+\
"version - {}".format(version_git)])
subprocess.call(["git", "push", "origin", version_git])
except Exception as e:
print("Something broke - {}".format(e))
## Bioconda now handles the coda packaging
## print("Push new version of conda installer")
#try:
# subprocess.call(["conda", "build", "conda.recipe/ipyrad"])
#except Exception as e:
# print("something broke - {}".format(e))