[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Catching python syntax errors at build time



It occurred to me that, since we are already byte-compiling Python code at build time, it is no extra effort to verify that it can be parsed and fail if not.

See attached patch.

Can anyone think of any reason not to do this?

Tim.
*/
--- /usr/lib/rpm/brp-python-bytecompile~	2008-12-12 19:08:20.000000000 +0000
+++ /usr/lib/rpm/brp-python-bytecompile	2009-02-20 17:03:55.000000000 +0000
@@ -20,7 +20,12 @@
 fi
 
 # Generate normal (.pyc) byte-compiled files.
-$python    -c 'import compileall; compileall.compile_dir("'"$RPM_BUILD_ROOT"'", '"$depth"', "/", 1)' > /dev/null
+$python    -c 'import compileall, sys; sys.exit (not compileall.compile_dir("'"$RPM_BUILD_ROOT"'", '"$depth"', "/", 1, quiet=1))'
+if [ $? != 0 ]; then
+  # One or more of the files has a syntax error.
+  exit 1
+fi
+
 
 # Generate optimized (.pyo) byte-compiled files.
 $python -O -c 'import compileall; compileall.compile_dir("'"$RPM_BUILD_ROOT"'", '"$depth"', "/", 1)' > /dev/null

Attachment: signature.asc
Description: OpenPGP digital signature


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]