This repository has been archived by the owner on Apr 8, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
setup.py
executable file
·295 lines (234 loc) · 8.54 KB
/
setup.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
#!/usr/bin/env python
#
# Copyright 2009 Peter Prohaska
#
# This file is part of tagfs.
#
# tagfs is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# tagfs is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with tagfs. If not, see <http://www.gnu.org/licenses/>.
#
from distutils.core import setup, Command
import sys
import os
from os.path import (
basename,
dirname,
abspath,
splitext,
join as pjoin
)
from glob import glob
from unittest import TestLoader, TextTestRunner
import re
import datetime
from subprocess import call
projectdir = dirname(abspath(__file__))
reportdir = pjoin(projectdir, 'reports')
srcdir = pjoin(projectdir, 'src')
bindir = pjoin(srcdir, 'bin')
moddir = pjoin(srcdir, 'modules')
testdir = pjoin(srcdir, 'test')
endToEndTestDir = pjoin(projectdir, 'test', 'e2e')
testdatadir = pjoin(projectdir, 'etc', 'test', 'events')
testmntdir = pjoin(projectdir, 'mnt')
assert os.path.isdir(srcdir)
assert os.path.isdir(bindir)
assert os.path.isdir(moddir)
assert os.path.isdir(testdir)
assert os.path.isdir(testdatadir)
class Report(object):
def __init__(self):
self.reportDateTime = datetime.datetime.utcnow()
self.reportDir = os.path.join(reportdir, self.reportDateTime.strftime('%Y-%m-%d_%H_%M_%S'))
# fails when dir already exists which is nice
os.makedirs(self.reportDir)
@property
def coverageReportFileName(self):
return os.path.join(self.reportDir, 'coverage.txt')
@property
def unitTestReportFileName(self):
return os.path.join(self.reportDir, 'tests.txt')
def sourceFiles():
yield os.path.join(bindir, 'tagfs')
sourceFilePattern = re.compile('^.*[.]py$')
for root, dirs, files in os.walk(moddir):
for f in files:
if(not sourceFilePattern.match(f)):
continue
if(f.startswith('.#')):
continue
yield os.path.join(root, f)
def fullSplit(p):
head, tail = os.path.split(p)
if(len(head) > 0):
for n in fullSplit(head):
yield n
yield tail
def testModules():
testFilePattern = re.compile('^(test.*)[.]py$', re.IGNORECASE)
for root, dirs, files in os.walk(testdir):
for f in files:
m = testFilePattern.match(f)
if(not m):
continue
relDir = os.path.relpath(root, testdir)
yield '.'.join([n for n in fullSplit(relDir)] + [m.group(1), ])
def printFile(fileName):
if(not os.path.exists(fileName)):
# TODO maybe we should not silently return?
return
with open(fileName, 'r') as f:
for line in f:
sys.stdout.write(line)
class TestFailException(Exception):
'''Indicates that at lease one of the unit tests has failed
'''
pass
class test(Command):
description = 'run tests'
user_options = []
def initialize_options(self):
self._cwd = os.getcwd()
self._verbosity = 2
def finalize_options(self): pass
def run(self):
report = Report()
tests = [m for m in testModules()]
print "..using:"
print " moddir:", moddir
print " testdir:", testdir
print " testdatadir:", testdatadir
print " testmntdir:", testmntdir
print " tests:", tests
print " sys.path:", sys.path
print
# insert project lookup paths at index 0 to make sure they are used
# over global libraries
sys.path.insert(0, moddir)
sys.path.insert(0, testdir)
# TODO try to import all test cases here. the TestLoader is throwing
# very confusing errors when imports can't be resolved.
# configure logging
# TODO not sure how to enable this... it's a bit complicate to enable
# logging only for 'make mt' and disable it then for
# 'python setup.py test'. 'python setup.py test' is such a gabber...
#if 'DEBUG' in os.environ:
# from tagfs import log_config
# log_config.setUpLogging()
if 'DEBUG' in os.environ:
import logging
logging.basicConfig(level = logging.DEBUG)
suite = TestLoader().loadTestsFromNames(tests)
try:
with open(report.unitTestReportFileName, 'w') as testResultsFile:
r = TextTestRunner(stream = testResultsFile, verbosity = self._verbosity)
def runTests():
result = r.run(suite)
if(not result.wasSuccessful()):
raise TestFailException()
try:
import coverage
c = coverage.coverage()
c.start()
runTests()
c.stop()
with open(report.coverageReportFileName, 'w') as reportFile:
c.report([f for f in sourceFiles()], file = reportFile)
except ImportError:
# TODO ImportErrors from runTests() may look like coverage is missing
print ''
print 'coverage module not found.'
print 'To view source coverage stats install http://nedbatchelder.com/code/coverage/'
print ''
runTests()
finally:
# TODO use two streams instead of printing files after writing
printFile(report.unitTestReportFileName)
printFile(report.coverageReportFileName)
class EndToEndTestFailure(Exception):
def __init__(self, testPath):
super(EndToEndTestFailure, self).__init__('end-to-end test failed: %s' % testPath)
class EndToEndTests(Command):
description = 'execute the end-to-end tests'
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def runTest(self, testPath):
if(not call(['bin/runEndToEndTest.sh', testPath]) is 0):
raise EndToEndTestFailure(testPath)
def run(self):
for endToEndDirName in os.listdir(endToEndTestDir):
testPath = os.path.join(endToEndTestDir, endToEndDirName)
if(not os.path.isdir(testPath)):
continue
self.runTest(testPath)
# Overrides default clean (which cleans from build runs)
# This clean should probably be hooked into that somehow.
class clean_pyc(Command):
description = 'remove *.pyc files from source directory'
user_options = []
def initialize_options(self):
self._delete = []
for cwd, dirs, files in os.walk(projectdir):
self._delete.extend(
pjoin(cwd, f) for f in files if f.endswith('.pyc')
)
def finalize_options(self):
pass
def run(self):
for f in self._delete:
try:
os.unlink(f)
except OSError, e:
print "Strange '%s': %s" % (f, e)
# Could be a directory.
# Can we detect file in use errors or are they OSErrors
# as well?
# Shall we catch all?
setup(
cmdclass = {
'test': test,
'clean_pyc': clean_pyc,
'e2e_test': EndToEndTests,
},
name = 'tagfs',
version = '0.1',
url = 'http://wiki.github.com/marook/tagfs',
description = '',
long_description = '',
author = 'Markus Pielmeier',
author_email = 'markus.pielmeier@gmail.com',
license = 'GPLv3',
download_url = 'http://github.com/marook/tagfs/downloads/tagfs_0.1-src.tar.bz2',
platforms = 'Linux',
requires = [],
classifiers = [
'Development Status :: 2 - Pre-Alpha',
'Environment :: Console',
'Intended Audience :: Developers',
'License :: OSI Approved :: GNU General Public License (GPL)',
'Natural Language :: English',
'Operating System :: POSIX :: Linux',
'Programming Language :: Python',
'Topic :: System :: Filesystems'
],
data_files = [
(pjoin('share', 'doc', 'tagfs'), ['AUTHORS', 'COPYING', 'README'])
],
# TODO maybe we should include src/bin/*?
scripts = [pjoin(bindir, 'tagfs')],
packages = ['tagfs'],
package_dir = {'': moddir},
)