-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdev.py
69 lines (56 loc) · 2.22 KB
/
dev.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
import argparse
import re
import os
import sys
def update_package_version(version):
with open('./pymaps/__version__.py', 'w') as f:
f.write('__version__ = "{}"'.format(str(version)))
if __name__ == '__main__':
PYTHON = 'python'
parser = argparse.ArgumentParser()
parser.add_argument("--version", help="number of the new package version")
parser.add_argument("--gitpush", help="message for commit and push to Github")
parser.add_argument("--pypi", action='store_true', help="Release a new version of the package on Pypi")
args = parser.parse_args()
if args.version:
msg = '-' * 80 + '\nUPDATING PACKAGE VERSION TO {}\n' + '-' * 80
print(msg.format(args.version))
version_pattern = '[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}'
version_is_valid = re.match(version_pattern, args.version) is not None
if version_is_valid:
update_package_version(args.version)
print('Sucess!')
else:
raise ValueError('Invalid Version {}'.format(args.version))
THIS_DIR = os.getcwd()
tests = 'setup.py test'
docs = 'docs.py'
install = 'setup.py install'
pypi = 'setup.py sdist upload'
print('-' * 80 + '\nRUNNING TESTS\n' + '-' * 80)
r = os.system(' '.join([PYTHON, tests]))
if r != 0:
raise SystemError('Error while testing.')
print('-' * 80 + '\nBUILDING DOCS\n' + '-' * 80)
os.chdir('./docs')
r= os.system(' '.join([PYTHON, docs]))
if r != 0:
raise SystemError('Error while building docs.')
os.chdir(THIS_DIR)
print('-' * 80 + '\nINSTALLING PACKAGE\n' + '-' * 80)
r= os.system(' '.join([PYTHON, install]))
if r != 0:
raise SystemError('Error while installing the package.')
if args.gitpush:
print('-' * 80 + '\nPUSHING TO REPOSITORY\n' + '-' * 80)
print('Git add')
os.system('git add .')
print('Git commit')
os.system('git commit -m "{}"'.format(args.gitpush))
print('Git push')
os.system('git push')
print('-' * 80 + '\nUPLOAD TO PYPI\n' + '-' * 80)
if args.pypi:
os.system(' '.join([PYTHON, pypi]))
os.system('git tag {}'.format(args.version))
os.system('git push origin --tags')