-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.py
executable file
·130 lines (95 loc) · 2.96 KB
/
build.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
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/python
import subprocess
import re
import os
import sys
from vulcan.builder import task, nsh
import sh
@task()
def apidoc():
"""
Generate API documentation using epydoc.
"""
nsh.epydoc('--config', 'epydoc.config')
@task()
def validate():
nsh.pycodestyle('vulcan', '--config=.pycodestyle')
@task(validate)
def build():
nsh.python3('setup.py', 'bdist_wheel')
nsh.pip3.install('.')
@task(build)
def test(*args):
"""
Run unit tests.
"""
pyTest = nsh.Command("py.test")
pyTest(args)
@task()
def check_uncommited():
result = nsh.git('status', '--porcelain')
if result:
raise Exception('There are uncommited files')
@task()
def generate_rst():
nsh.pandoc('-f', 'markdown', '-t', 'rst', '-o', 'README.rst', 'README.md')
nsh.pandoc('-f', 'markdown', '-t', 'rst', '-o', 'CHANGES.rst', 'CHANGES.md')
filenames_diff = nsh.git('--no-pager', 'diff', '--name-only')
if 'README.rst' in filenames_diff or 'CHANGES.rst' in filenames_diff:
nsh.git('commit', 'README.rst', 'CHANGES.rst', '-m', 'Autogenerated from markdown files')
@task()
def update_version(ver=None):
with open('vulcan/meta_aws.py', 'r') as f:
file_str = f.read()
if not ver:
regexp = re.compile(r'__version__\s*\=\s*\"([\d\w\.\-\_]+)\"\s*')
m = regexp.search(file_str)
if m:
ver = m.group(1)
minor_ver = int(ver[ver.rfind('.')+1:])
ver = '{}.{}'.format(ver[:ver.rfind('.')], minor_ver+1)
file_str = re.sub(
r'__version__\s*\=\s*\"([\d\w\.\-\_]+)\"\s*',
r'__version__ = "{}"\n'.format(ver),
file_str)
with open('vulcan/meta_aws.py', 'w') as f:
f.write(file_str)
nsh.git('commit', 'vulcan/meta_aws.py', '-m', 'Version updated to {}'.format(ver))
@task()
def create_tag():
with open('vulcan/meta_aws.py', 'r') as f:
file_str = f.read()
regexp = re.compile(r'__version__\s*\=\s*\"([\d\w\.\-\_]+)\"\s*')
m = regexp.search(file_str)
if m:
ver = m.group(1)
else:
raise "Can't find/parse current version in './vulcan/meta_aws.py'"
nsh.git('tag', '-a', '-m', 'Tagging version {}'.format(ver), ver)
@task()
def push():
nsh.git('push', '--verbose')
nsh.git('push', '--tags', '--verbose')
@task(validate)
def release(ver=None):
check_uncommited()
update_version(ver)
generate_rst()
create_tag()
push()
@task(test)
def pypi():
nsh.python('setup.py', 'sdist')
args = ['upload']
travis_pull_request = (os.environ.get('TRAVIS_PULL_REQUEST', 'false') == 'true')
travis_tag = os.environ.get('TRAVIS_TAG', False)
if not travis_pull_request and travis_tag:
args.append('--repository-url')
args.append('https://upload.pypi.org/legacy/')
else:
args.append('--skip-existing')
args.append('--repository-url')
args.append('https://test.pypi.org/legacy/')
args.append('dist/vulcan-aws-*')
nsh.twine(args)
__DEFAULT__ = test