forked from mytarget-test-team/seismograph
-
Notifications
You must be signed in to change notification settings - Fork 11
/
to_release.py
executable file
·119 lines (81 loc) · 2.41 KB
/
to_release.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
# -*- coding: utf-8 -*-
"""
To release library.
Usage:
python to_release.py
"""
import os
import subprocess
GIT_BIN = 'git'
PYTHON_BIN = 'python'
FROM_BRANCH = 'master'
PACKAGE_NAME = 'seismograph'
SELF_PATH = os.path.abspath(
os.path.join(
os.path.dirname(__file__),
),
)
SUBPROCESS_OPTIONS = {
'shell': True,
'cwd': SELF_PATH,
}
def sudo(command):
if os.getlogin() != 'root':
return 'sudo {}'.format(command)
return command
def python(command, env=None, version='2.7'):
if env:
env = ' '.join(
'{}={}'.format(k, v) for k, v in env.items()
) + ' '
else:
env = ''
return '{}{}{} {}'.format(env, PYTHON_BIN, version, command)
def git(command):
return '{} {}'.format(GIT_BIN, command)
def call(command, **params):
subprocess_options = SUBPROCESS_OPTIONS.copy()
subprocess_options.update(params)
return subprocess.call(command, **subprocess_options)
def check_output(command):
return subprocess.check_output(command, **SUBPROCESS_OPTIONS)
def check_git_branch():
command = git('branch')
output = check_output(command)
assert '* {}'.format(FROM_BRANCH) in output.split('\n'),\
'Please check current git branch. Branch for build "{}"'.format(FROM_BRANCH)
def delete_old_files():
command = sudo('rm -rf ./{}.egg-info ./dist/'.format(PACKAGE_NAME))
call(command)
def run_example(pyv='2.7'):
command = 'PYTHONPATH={} SEISMOGRAPH_CONF={} python{} -m seismograph {} -v'
assert call(
command.format(
SELF_PATH, 'example.etc.base', pyv, os.path.join(SELF_PATH, 'example'),
),
) == 0, 'Example tests was worked with errors'
def run_tests(pyv='2.7'):
command = sudo(python('setup.py test', version=pyv))
assert call(command) == 0, 'Tests was worked with errors'
def upload_to_pip():
command = sudo(python('setup.py register sdist upload'))
exit_code = call(command)
assert exit_code == 0, 'Upload to pip error'
def rebuild_docs():
exit_code = subprocess.call(
'make html',
shell=True,
cwd=os.path.join(SELF_PATH, 'docs'),
)
assert exit_code == 0, 'Rebuild docs error'
def main():
check_git_branch()
delete_old_files()
run_tests(pyv='2.7')
run_tests(pyv='3.4')
run_example(pyv='2.7')
run_example(pyv='3.4')
rebuild_docs()
upload_to_pip()
if __name__ == '__main__':
main()