forked from gdanezis/petlib
/
pavement.py
162 lines (130 loc) · 4.63 KB
/
pavement.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import os.path
import os
import re
import fnmatch
def match_files(directory="petlib", pattern="*.py"):
files = []
for file in os.listdir(directory):
if fnmatch.fnmatch(file, pattern):
files += [os.path.join(directory, file)]
return files
from paver.tasks import task, cmdopts
from paver.easy import sh, needs, pushd
from paver.virtual import *
def tell(x):
print
print "-"*10, x, "-"*10
print
@task
def unit_tests():
""" Run all the unit tests in a Python 2.7 py.test context, and produce coverage report. """
tell("Unit tests")
files = " ".join(match_files())
# sh('py.test-2.7 -v --doctest-modules --cov-report html --cov petlib ' + files)
sh('py.test-2.7 -v --doctest-modules ' + files)
@task
def test3():
""" Run all the unit tests in a Python 3.4 py.test context, and produce coverage report. """
tell("Unit tests for python 3")
files = " ".join(match_files())
# sh('py.test-3.4 -v --doctest-modules --cov-report html --cov petlib ' + files)
sh('py.test-3.4 -v --doctest-modules ' + files)
@task
@cmdopts([
('file=', 'f', 'File to test.')
])
def testf(options):
"""Test a specific file for Python 2/3 with all flags turned on."""
tell("Unit tests for specific file")
print(options)
sh('py.test-3.4 -vs --doctest-modules --cov %s %s' % (options.file, options.file))
sh('py.test-2.7 -vs --doctest-modules --cov %s %s' % (options.file, options.file))
@task
def build(quiet=True):
""" Builds the petlib distribution, ready to be uploaded to pypi. """
tell("Build dist")
sh('python setup.py sdist', capture=quiet)
@task
def win(quiet=True):
""" Builds the petlib binary distribution for windows. """
tell("Build windows distribution")
sh('python setup.py build bdist_wininst', capture=quiet)
@task
def upload(quiet=False):
""" Uploads the latest distribution to pypi. """
tell("upload dist")
sh('python setup.py sdist upload', capture=quiet)
@task
def lintlib(quiet=False):
""" Run the python linter on petlib with project specific options (see pylintrc petlib). """
tell("Run pylint on the library")
sh('pylint --rcfile=pylintrc petlib', capture=quiet)
@needs("make_env")
@task
@virtualenv(dir=r"test_env/pltest")
def lintexamples(quiet=True):
""" Run the python linter on the petlib examples. """
tell("Run Lint on example code")
sh("pip install %s --upgrade" % get_latest_dist(), capture=quiet)
files = " ".join(match_files("examples", "*.py"))
sh('export PYTHONPATH=$PYHTONPATH:./utils; pylint --rcfile=pylintrc --load-plugins ignoretest ' + files, capture=quiet)
@needs("lintlib", "lintexamples")
@task
def lint():
""" Lint all petlib library code and examples. """
pass
@task
def make_docs(quiet=True):
""" Build the petlib documentation. """
tell("Making Docs")
with pushd('docs') as old_dir:
sh('make html', capture=quiet)
@task
def wc(quiet=False):
""" Count the petlib library and example code lines. """
tell("Counting code lines")
print("\nLibrary code:")
sh('wc -l petlib/*.py', capture=quiet)
print("\nExample code:")
sh('wc -l examples/*.py', capture=quiet)
print("\nAdministration code:")
sh('wc -l pavement.py setup.py docs/conf.py utils/ignoretest.py', capture=quiet)
def get_latest_dist():
lib = file(os.path.join("petlib", "__init__.py")).read()
v = re.findall("VERSION.*=.*['\"](.*)['\"]", lib)[0]
return os.path.join("dist","petlib-%s.tar.gz" % v)
@needs('build')
@task
def make_env(quiet=True):
""" Build a virtual environment with petlib installed. """
tell("Make a virtualenv")
if os.path.exists("test_env"):
return
os.mkdir("test_env")
with pushd('test_env') as old_dir:
sh("virtualenv pltest", capture=quiet)
@needs("make_env")
@task
@virtualenv(dir=os.path.join(r"test_env",r"pltest"))
def big_tests(quiet=True):
""" Run all example unit_tests in a fresh python 2.7 context. """
tell("Run acceptance tests (big examples)")
sh("pip install %s --upgrade" % get_latest_dist(), capture=quiet)
files = " ".join(match_files("examples", "*.py"))
sh("py.test-2.7 -v " + files)
@task
def local_big_tests(quiet=True):
""" Run example tests using local install. """
tell("Run acceptance tests (big examples) using local install.")
files = " ".join(match_files("examples", "*.py"))
sh("py.test-2.7 -v " + files)
@needs('unit_tests', 'big_tests')
@task
def test():
""" Run all tests. """
pass
@needs('unit_tests', 'test3', 'build', 'make_docs', 'make_env', 'big_tests')
@task
def default():
""" Run all default tasks to test, and build lib and docs. """
pass