-
Notifications
You must be signed in to change notification settings - Fork 0
/
to_release.py
executable file
·87 lines (55 loc) · 1.56 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
# -*- 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 = 'noseapp_workspace'
SUBPROCESS_OPTIONS = {
'shell': True,
'cwd': os.path.abspath(
os.path.join(
os.path.dirname(__file__),
),
),
}
def sudo(command):
if os.getlogin() != 'root':
return 'sudo {}'.format(command)
return command
def python(command):
return '{} {}'.format(PYTHON_BIN, command)
def git(command):
return '{} {}'.format(GIT_BIN, command)
def call(command):
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 to_delete_old_files():
command = sudo('rm -rf ./{}.egg-info ./dist/'.format(PACKAGE_NAME))
call(command)
def run_tests():
command = sudo(python('setup.py test'))
exit_code = call(command)
assert exit_code == 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 main():
check_git_branch()
to_delete_old_files()
run_tests()
upload_to_pip()
if __name__ == '__main__':
main()