forked from pjz/notehandler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.py
142 lines (112 loc) · 3.67 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
131
132
133
134
135
136
137
138
139
140
141
142
import os
import sys
import os.path
import fileinput
from optparse import make_option
from fabricate import main, run, shell, autoclean
from subprocess import check_output
# Core Executables
# ================
name = 'notehandler'
RUN_DEPS = [ 'cmdpy', 'evernote' ]
TEST_DEPS = [ 'coverage', 'pytest' ]
def _virt(cmd, envdir='env'):
return os.path.join(envdir, 'bin', cmd)
ENV_ARGS = [
'virtualenv',
'--distribute',
'--unzip-setuptools',
'--prompt=[%s] ' % name,
]
def dev():
if os.path.exists('env'): return
args = ENV_ARGS + [ 'env' ]
run(*args)
for dep in RUN_DEPS + TEST_DEPS:
run(_virt('pip'), 'install', dep)
run(_virt('python'), 'setup.py', 'develop')
def clean_dev():
shell('rm', '-rf', 'env')
def clean():
autoclean()
shell('find', '.', '-name', '*.pyc', '-delete')
clean_dev()
clean_test()
clean_build()
# Testing
# =======
def test():
dev()
run(_virt('py.test'), 'tests/', ignore_status=True, silent=False)
def analyse():
dev()
run(_virt('py.test'),
'--junitxml=testresults.xml',
'--cov-report', 'term',
'--cov-report', 'xml',
'--cov', name,
'tests/',
ignore_status=False)
print('done!')
def clean_test():
clean_dev()
shell('rm', '-f', '.coverage', 'coverage.xml', 'testresults.xml', 'pylint.out')
# Build
# =====
def build():
run(main.options.python, 'setup.py', 'bdist_egg', 'bdist_wheel')
def clean_build():
shell(main.options.python, 'setup.py', 'clean', '-a')
shell('rm', '-rf', 'dist')
def _require_y(prompt, failmsg=''):
yn = raw_input(prompt).lower()
if yn not in [ 'y', 'yes' ]:
print failmsg
sys.exit(1)
def _set_version(newversion):
needle = 'version ='
for line in fileinput.input(['setup.py'], inplace=True):
if needle in line:
i = line.find(needle)
line = line[:i] + needle + " " + repr(newversion) + "\n"
print line,
def release():
if main.options.release is None:
print("Must specify a version to release with --release <version>")
sys.exit(1)
rel = main.options.release
if rel in check_output(['git', 'tag', '-l'],universal_newlines=True).split('\n'):
print("Version %s is already git tagged." % rel)
sys.exit(1)
_require_y("Release version %s ?" % rel)
_set_version(rel)
run(main.options.python, 'setup.py', 'sdist', '--formats=zip,gztar,bztar', 'upload')
run(main.options.python, 'setup.py', 'bdist_wheel', 'upload')
shell('git', 'commit', 'setup.py', '-m', 'Release %s' % rel, silent=False)
shell('git', 'tag', rel, silent=False)
_set_version(rel + '-dev')
shell('git', 'commit', 'setup.py', '-m', 'Bump to %s-dev' % rel, silent=False)
shell('git', 'push', silent=False)
shell('git', 'push', '--tags', silent=False)
clean_build()
print("Released!")
def show_targets():
print("""Valid targets:
show_targets (default) - this
build - build an egg
dev - set up an environment able to run tests in env/
test - run the unit tests
pylint - run pylint on the source
analyse - run the unit tests with code coverage enabled
clean - remove all build artifacts
clean_{dev,test} - clean some build artifacts
release - requres --version and pypi upload rights
""")
sys.exit()
extra_options = [ make_option('--python', action="store", dest="python", default="python")
, make_option('--release', action="store", dest="release", default=None)
]
main( extra_options=extra_options
, default='show_targets'
, ignoreprefix="python"
)