|
Packit |
6bd9ab |
#!/bin/sh
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
# test_pycompile.sh - see if all Python files compile
|
|
Packit |
6bd9ab |
#
|
|
Packit |
6bd9ab |
# Copyright (C) 2013 Arthur de Jong
|
|
Packit |
6bd9ab |
#
|
|
Packit |
6bd9ab |
# This library is free software; you can redistribute it and/or
|
|
Packit |
6bd9ab |
# modify it under the terms of the GNU Lesser General Public
|
|
Packit |
6bd9ab |
# License as published by the Free Software Foundation; either
|
|
Packit |
6bd9ab |
# version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
6bd9ab |
#
|
|
Packit |
6bd9ab |
# This library is distributed in the hope that it will be useful,
|
|
Packit |
6bd9ab |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
6bd9ab |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
6bd9ab |
# Lesser General Public License for more details.
|
|
Packit |
6bd9ab |
#
|
|
Packit |
6bd9ab |
# You should have received a copy of the GNU Lesser General Public
|
|
Packit |
6bd9ab |
# License along with this library; if not, write to the Free Software
|
|
Packit |
6bd9ab |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
Packit |
6bd9ab |
# 02110-1301 USA
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
set -e
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
# find source directory
|
|
Packit |
6bd9ab |
srcdir="${srcdir-`dirname "$0"`}"
|
|
Packit |
6bd9ab |
top_srcdir="${top_srcdir-${srcdir}/..}"
|
|
Packit |
6bd9ab |
python="${PYTHON-python}"
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
# if Python is missing, ignore
|
|
Packit |
6bd9ab |
if ! ${python} --version > /dev/null 2> /dev/null
|
|
Packit |
6bd9ab |
then
|
|
Packit |
6bd9ab |
echo "Python (${python}) not found"
|
|
Packit |
6bd9ab |
exit 77
|
|
Packit |
6bd9ab |
fi
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
# compile all Python files (without writing pyc files)
|
|
Packit |
6bd9ab |
${python} -c "
|
|
Packit |
6bd9ab |
import os
|
|
Packit |
6bd9ab |
import py_compile
|
|
Packit |
6bd9ab |
import sys
|
|
Packit |
6bd9ab |
import traceback
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
top_srcdir = '$top_srcdir'
|
|
Packit |
6bd9ab |
errors_found = 0
|
|
Packit |
6bd9ab |
tmpfile = 'tmpfile.pyc'
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
for root, dirs, files in os.walk(top_srcdir):
|
|
Packit |
6bd9ab |
for f in files:
|
|
Packit |
6bd9ab |
if f.endswith('.py'):
|
|
Packit |
6bd9ab |
filename = os.path.join(root, f)
|
|
Packit |
6bd9ab |
try:
|
|
Packit |
6bd9ab |
py_compile.compile(filename, tmpfile, doraise=True)
|
|
Packit |
6bd9ab |
except py_compile.PyCompileError, e:
|
|
Packit |
6bd9ab |
print 'Compiling %s ...' % os.path.abspath(filename)
|
|
Packit |
6bd9ab |
print e
|
|
Packit |
6bd9ab |
errors_found += 1
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
os.unlink(tmpfile)
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
if errors_found:
|
|
Packit |
6bd9ab |
print '%d errors found' % errors_found
|
|
Packit |
6bd9ab |
sys.exit(1)
|
|
Packit |
6bd9ab |
"
|