forked from partizand/gnucashreport
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpublic.py
111 lines (76 loc) · 2.17 KB
/
public.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
"""
Script for public package on PyPi
"""
import unittest
import subprocess
import re
# Public to test pypi
test_public = True
suf_test = ['-r', 'pypitest']
# sdist command
cmd_sdist = ['python', 'setup.py', 'sdist', 'bdist_wheel', '--universal']
def find_version(filename):
with open(filename, 'r') as f:
version_file = f.read()
version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]",
version_file, re.M)
if version_match:
return version_match.group(1)
raise RuntimeError("Unable to find version string.")
ver = find_version('src/gnucashreport/__init__.py')
reg_name = 'gnucashreport-{}-py2.py3-none-any.whl'.format(ver)
# public command
cmd_public = ['twine', 'upload', 'dist/{}'.format(reg_name)]
cmd_public_test = cmd_public + suf_test
# register command
cmd_register = ['twine.exe', 'register', 'dist/{}'.format(reg_name)]
cmd_register_test = cmd_register + suf_test
def run_all_test():
print('Run all tests...')
test_suite = unittest.defaultTestLoader.discover('src/test')
test_runner = unittest.TextTestRunner(resultclass=unittest.TextTestResult)
result = test_runner.run(test_suite)
if not result.wasSuccessful():
print('Tests fails! Exit')
exit(2)
return result
def build():
# build
print('Build dist')
ret = subprocess.run(cmd_sdist)
if ret.returncode != 0:
print('setup.py sdist error! Exit.')
exit(3)
return ret
def register():
# register
print('Register')
if test_public:
ret = subprocess.run(cmd_register_test)
else:
ret = subprocess.run(cmd_register)
if ret.returncode != 0:
print('setup.py sdist error! Exit.')
exit(3)
return ret
def public():
# Public
print('Public')
if test_public:
ret = subprocess.run(cmd_public_test)
else:
ret = subprocess.run(cmd_public)
if ret.returncode == 0:
print('Public is successful')
else:
print('Error public')
return ret
print('Publishing version {}'.format(ver))
# Run all tests
# run_all_test()
# build
build()
# register
# register()
# public
public()