Catching python syntax errors at build time

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

 



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

-- 
fedora-devel-list mailing list
fedora-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/fedora-devel-list

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Fedora Announce]     [Fedora Kernel]     [Fedora Testing]     [Fedora Formulas]     [Fedora PHP Devel]     [Kernel Development]     [Fedora Legacy]     [Fedora Maintainers]     [Fedora Desktop]     [PAM]     [Red Hat Development]     [Gimp]     [Yosemite News]
  Powered by Linux