开发者

How can I detect errors programatically when building an egg with setuptools?

If I have a script that builds eggs, basically by running

python setup.py bdist_egg --exclude-source-files

for a number of setup.py files that use setuptools to define how eggs are built, is there an easy way to determine if there were any errors in building the egg?

A situation I had recently, was that there was a syntax error in a module. Setuptools s开发者_StackOverflow社区pat out a message onto standard error, but continued to create the egg, omitting to broken module. Because this was part of a batch creating a number of eggs, the error was missed, and the result was useless.

Is there a way to detect errors when building an egg programatically, other than just capturing standard error and parsing that?


distutils use the py_compile.compile() function to compile source files. This function takes a doraise argument, that when set to True raises an exception on compilation errors (the default is to print the errors to stderr). distutils don't call py_compile.compile() with doraise=True, so compilation is not aborted on compilation errors.

To stop on errors and be able to check the setup.py return code (it will be nonzero on errors), you could patch the py_compile.compile() function. For example, in your setup.py:

from setuptools import setup
import py_compile

# Replace py_compile.compile with a function that calls it with doraise=True
orig_py_compile = py_compile.compile

def doraise_py_compile(file, cfile=None, dfile=None, doraise=False):
    orig_py_compile(file, cfile=cfile, dfile=dfile, doraise=True)

py_compile.compile = doraise_py_compile

# Usual setup...
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜