-
Notifications
You must be signed in to change notification settings - Fork 2
/
test-base.cfg
472 lines (378 loc) · 13.4 KB
/
test-base.cfg
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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
# A buildout base configuration providing zope testrunner setup.
# The buildout basically provides two scripts, usable in test-setup as well
# as in development:
#
# bin/test : Runs the tests of the package (using collective.xmltestreport)
# bin/test-coverage : Runs the tests of the package, generates and opens
# a coverage report.
#
# Usage example:
# [buildout]
# extends =
# https://raw.githubusercontent.com/4teamwork/ftw-buildouts/master/test-base.cfg
# package-name = my.package
[buildout]
# =====================================================================
# Configuration variables:
package-name =
test-extras = tests
test-egg = ${buildout:package-name} [${buildout:test-extras}]
package-directory =
package-namespace = ${buildout:package-name}
# =====================================================================
# The "early-parts" option let late configs inject parts at the beginning.
early-parts =
tool-parts =
package-directory
dependencychecker
test-parts =
test
test-coverage
coverage
code-audit-parts =
pycodestyle-cfg
pycodestyle
pydocstyle-cfg
pydocstyle
isort-cfg
isort
pyflakes
zptlint
i18n-parts =
i18ndude
check-translations
parts =
${buildout:early-parts}
${buildout:tool-parts}
${buildout:test-parts}
${buildout:code-audit-parts}
${buildout:i18n-parts}
# We assume that the buildout directory is the package root (repository root)
# of the package we are testing.
develop = .
results-dir = ${buildout:directory}/parts/testresults
find-links = https://pypi.python.org/
index = https://pypi.python.org/simple/
versions = versions
# Show the picked version in the buildout log.
show-picked-versions = true
allow-hosts =
pypi.python.org
*.pypi.python.org
pypi.org
files.pythonhosted.org
*.4teamwork.ch
effbot.org
code.google.com
*.googlecode.com
*.github.com
*.githubusercontent.com
*.plone.org
# bin/test : A script running the tests of the configured package.
[test]
recipe = collective.xmltestreport
eggs =
${buildout:test-egg}
initialization =
import os
sys.argv[0] = os.path.abspath(sys.argv[0])
test_directory = '${buildout:directory}/parts/test'
try: os.makedirs(test_directory)
except OSError: pass
os.chdir(test_directory)
os.environ['zope_i18n_compile_mo_files'] = 'true'
chameleon_cache_dir = '${buildout:directory}/parts/test/chameleon-cache'
try: os.makedirs(chameleon_cache_dir)
except OSError: pass
if 'CHAMELEON_CACHE' not in os.environ: os.environ['CHAMELEON_CACHE'] = chameleon_cache_dir
scripts = test
defaults = ['-s', '${buildout:package-namespace}', '--exit-with-status', '--auto-color', '--auto-progress', '--xml', '--test-path', '${buildout:directory}']
# bin/coverage : A helper script generating a coverage report.
[coverage]
recipe = zc.recipe.egg
eggs = coverage
initialization =
import os
os.environ['COVERAGE_FILE'] = "${buildout:results-dir}/coverage.data"
# XXX HACK: let coverage exit with a propper exit code.
# See: https://bugs.launchpad.net/zc.buildout/+bug/164629
import coverage
if __name__ == '__main__': sys.exit(coverage.main())
# bin/test-coverage : A script for running the tests with coverage and
# opening the coverage report in the browser.
[test-coverage]
recipe = collective.recipe.template
input = inline:
#!/bin/sh
mkdir -p ${buildout:results-dir}
pkgdir=`${buildout:directory}/bin/package-directory`
bin/coverage erase
if [[ "$1" == "xml" ]]; then
shift
bin/coverage run --branch --source=$pkgdir bin/test $@
result=$?
bin/coverage xml -i --omit="*tests/*.py,*testing.py,*interfaces.py" -o ${buildout:results-dir}/coverage.xml
else
bin/coverage run --branch --source=$pkgdir bin/test $@
result=$?
bin/coverage html -i --omit="*tests/*.py,*testing.py,*interfaces.py" -d ${buildout:results-dir}/coverage/ && open ${buildout:results-dir}/coverage/index.html
fi
exit $result
output = ${buildout:directory}/bin/test-coverage
mode = 755
# bin/package-directory : A script returning the path to the source
# directory. It guesses the package namespace from the package name by
# replacing dots with slashes.
# For packages which use a different namespace as guessable by the package
# name, the path can be set using the ${buildout:package-directory}
# variable (path relative to buildout directory). Example::
# [buildout]
# package-name = MyPackage
# package-directory = scr/my/package/core
[package-directory]
recipe = collective.recipe.template
input = inline:
#!/bin/sh
pkgdir="${buildout:package-directory}"
pkgname="${buildout:package-namespace}"
namepath=`echo $pkgname | sed "s:\.:/:g"`
base="${buildout:directory}"
paths=$(echo "$pkgdir" "$namepath" "src/$namepath" "src/$pkgname/$namepath")
for path in $paths; do
if [ -d "$base/$path" ]; then
if [[ "$1" == "relative" ]]; then
echo "$path"
else
echo "$base/$path"
fi
exit 0
fi
done
exit 1
output = ${buildout:directory}/bin/package-directory
mode = 755
# Downloads the default pycodestyle.cfg.
[pycodestyle-cfg]
recipe = collective.recipe.cmd
on_install=true
on_update=true
cfgfile = ${buildout:directory}/parts/pycodestyle/pycodestyle.cfg
cfgurl = https://raw.githubusercontent.com/4teamwork/ftw-buildouts/master/pycodestyle.cfg
cmds =
mkdir -p `dirname ${pycodestyle-cfg:cfgfile}`
curl "${pycodestyle-cfg:cfgurl}" > "${pycodestyle-cfg:cfgfile}"
# bin/pycodestyle : pycodestyle validation of the packages source.
[pycodestyle]
recipe = zc.recipe.egg:scripts
eggs = pycodestyle
initialization =
from os import chdir
from subprocess import PIPE
from subprocess import Popen
chdir("${buildout:directory}")
sys.argv.append('--config=${pycodestyle-cfg:cfgfile}')
absolute_paths = False
if '--absolute' in sys.argv:
absolute_paths = True
sys.argv.remove('--absolute')
if len(sys.argv) < 3:
pkgdir = Popen(
'${buildout:directory}/bin/package-directory relative',
shell=True,
stdout=PIPE,
).stdout.read().strip()
if absolute_paths:
pkgdir = os.path.abspath(pkgdir)
sys.argv.append(pkgdir)
# Downloads the default pydocstyle.cfg.
[pydocstyle-cfg]
recipe = collective.recipe.cmd
on_install=true
on_update=true
cfgfile = ${buildout:directory}/parts/pydocstyle/pydocstyle.cfg
cfgurl = https://raw.githubusercontent.com/4teamwork/ftw-buildouts/master/pydocstyle.cfg
cmds =
mkdir -p `dirname ${pydocstyle-cfg:cfgfile}`
curl "${pydocstyle-cfg:cfgurl}" > "${pydocstyle-cfg:cfgfile}"
# bin/pydocstyle : pydocstyle validation of the packages source.
[pydocstyle]
recipe = zc.recipe.egg
eggs = pydocstyle
args = ['--config=${pydocstyle-cfg:cfgfile}']
initialization =
import os
import subprocess
os.chdir("${buildout:directory}")
pkgdir = subprocess.Popen(
'${buildout:directory}/bin/package-directory relative',
shell=True, stdout=subprocess.PIPE).stdout.read().strip()
if '--absolute' in sys.argv: pkgdir = os.path.abspath(pkgdir) ; sys.argv.remove('--absolute')
if len(sys.argv) < 2: sys.argv.extend([pkgdir])
sys.argv.extend(${pydocstyle:args})
# Downloads the default isort.cfg.
[isort-cfg]
recipe = collective.recipe.cmd
on_install=true
on_update=true
cfgfile = ${buildout:directory}/parts/isort/.isort.cfg
cfgurl = https://raw.githubusercontent.com/4teamwork/ftw-buildouts/master/.isort.cfg
cmds =
mkdir -p `dirname ${isort-cfg:cfgfile}`
curl "${isort-cfg:cfgurl}" > "${isort-cfg:cfgfile}"
# bin/isort : isort validation of the packages source.
[isort]
recipe = zc.recipe.egg
eggs =
isort
setuptools
args = [
'--recursive',
'--check-only',
'--diff',
]
initialization =
import os
import subprocess
os.chdir("${buildout:directory}")
config_path = os.path.dirname('${isort-cfg:cfgfile}')
sys.argv.append('--settings-path=%s' % (config_path))
if len(sys.argv) < 3:
pkgdir = subprocess.Popen(
'${buildout:directory}/bin/package-directory relative',
shell=True, stdout=subprocess.PIPE,
).stdout.read().strip()
sys.argv.extend([pkgdir])
sys.argv.extend(${isort:args})
# bin/pyflakes : Pyflakes validation of the packages source.
[pyflakes]
recipe = zc.recipe.egg
eggs = pyflakes
entry-points = pyflakes=pyflakes.scripts.pyflakes:main
initialization =
import os
import subprocess
os.chdir("${buildout:directory}")
if len(sys.argv) == 1:
# We're running this for a package
pkgdir = subprocess.Popen(
'${buildout:directory}/bin/package-directory relative',
shell=True,
stdout=subprocess.PIPE,
).stdout.read().decode('utf-8').strip()
# We filter by filetype, filename and add our ignores
files = subprocess.Popen(
(
"find {} "
"-type 'f' "
"-name '*.py' "
"! -name '__init__.py' "
"! -name 'bootstrap.py' "
"! -name 'pyxbgen.py' "
"! -path '*/bindings/*' "
"! -path '*/skins/*' "
).format(pkgdir),
shell=True,
stdout=subprocess.PIPE).stdout.read().decode('utf-8').splitlines()
sys.argv.extend(files)
# bin/ptlint : Zope page tempalte validation.
[zptlint]
recipe = zc.recipe.egg
eggs = zptlint
initialization =
import subprocess
pkgdir = subprocess.Popen(
'${buildout:directory}/bin/package-directory relative',
shell=True, stdout=subprocess.PIPE).stdout.read().decode('utf-8').strip()
ptfiles = subprocess.Popen(
'find %s -name "*.pt"' % pkgdir,
shell=True, stdout=subprocess.PIPE).stdout.read().decode('utf-8').strip()
sys.argv.extend(ptfiles and ptfiles.split('\n') or [])
if len(sys.argv) == 1: sys.exit(0)
# bin/i18ndude : Translation tools for ZPT and python scripts.
[i18ndude]
recipe = zc.recipe.egg
eggs = i18ndude
# bin/check-translations : Validates translatable strings and
# provides translation statistics.
[check-translations]
recipe = collective.recipe.template
input = inline:
#!/bin/sh
buildoutdir="${buildout:directory}"
pkgdir=`$buildoutdir/bin/package-directory`
pkgname="${buildout:package-namespace}"
echo ""
echo "===================================================="
echo " Not translatable strings in package templates"
echo "===================================================="
echo ""
$buildoutdir/bin/i18ndude find-untranslated $pkgdir | sed -e '/^Processing/ { N; s/\n//; D; }' -e '/^-*$/ {s/^.*$//;}' -e '/^===/d'
echo ""
echo ""
echo "===================================================="
echo " Translation statistics"
echo "===================================================="
echo ""
tmpdir=$buildoutdir/parts/test-i18n
mkdir -p $tmpdir
domains=`find $pkgdir -name '*.pot' | grep -v '\-manual\.pot' | sed -e 's/.*\/\(.*\).pot$/\1/'`
if [[ "$domains" == "" ]]; then
echo "There are no .pot files."
fi
for domain in $domains; do
rm -f $tmpdir/*
if [[ "$domain" == "$pkgname" ]]; then
echo "i18n domain: $domain (primary)"
# Rebuilding pot file from source since this seems to be the
# primary package domain.
buildargs="--pot $tmpdir/$domain.pot --create $domain"
manualfile=`find $pkgdir -name "$domain-manual.pot"`
if [[ "$manualfile" != "" ]]; then
buildargs="$buildargs --merge $manualfile"
fi
$buildoutdir/bin/i18ndude rebuild-pot $buildargs $pkgdir
else
echo "i18n domain: $domain"
find $pkgdir -name "$domain.pot" -exec cp {} $tmpdir/$domain.pot \;
manualfile=`find $pkgdir -name "$domain-manual.pot"`
if [[ "$manualfile" != "" ]]; then
$buildoutdir/bin/i18ndude merge --pot $tmpdir/$domain.pot --merge $manualfile &> /dev/null
fi
fi
language_pattern="\(en\)"
for pofile in $(find $pkgdir -name "$domain.po"); do
if [[ $pofile =~ /LC_MESSAGES/ ]]; then
lang=`echo $pofile | sed -e 's/.*\/\(.*\)\/LC_MESSAGES.*/\1/'`
tmppofile=$tmpdir/$domain-$lang.po
cp $pofile $tmppofile
language_pattern="$language_pattern|\($lang\)"
if [[ `grep -r '"Language-Code:' $tmppofile` == "" ]]; then
sed -i -e "1,/^$/ { s/^$/\"Language-Code: $lang\\\\n\"/; }" $tmppofile
fi
else
echo "Ignoring file $pofile since LC_MESSAGES could not be found."
fi
done
(cd $tmpdir && $buildoutdir/bin/i18ndude list --products $domain | egrep $language_pattern)
echo ""
done
output = ${buildout:directory}/bin/check-translations
mode = 755
# bin/dependencychecker : checks dependencies
[dependencychecker]
recipe = zc.recipe.egg
eggs =
z3c.dependencychecker
${test:eggs}
initialization =
import os
import subprocess
os.chdir("${buildout:directory}")
pkgdir = subprocess.Popen(
'${buildout:directory}/bin/package-directory relative',
shell=True, stdout=subprocess.PIPE).stdout.read().strip()
sys.argv.extend([pkgdir])
scripts = dependencychecker
[versions]
collective.recipe.cmd = 0.11
collective.xmltestreport = 2.0.2